diff options
author | Alkalus <draknyte1@hotmail.com> | 2017-09-28 12:52:31 +1000 |
---|---|---|
committer | Alkalus <draknyte1@hotmail.com> | 2017-09-28 12:52:31 +1000 |
commit | 19749c79884682301e292b52d0ddb15e6d35a580 (patch) | |
tree | d34cc6f5ffe3aebb2354761ca9a9e2a53b853b38 /src/Java/gtPlusPlus/core | |
parent | 4ab32e96512efaccb63fc2024e44dbc675afc5f0 (diff) | |
download | GT5-Unofficial-19749c79884682301e292b52d0ddb15e6d35a580.tar.gz GT5-Unofficial-19749c79884682301e292b52d0ddb15e6d35a580.tar.bz2 GT5-Unofficial-19749c79884682301e292b52d0ddb15e6d35a580.zip |
+ Added Base Tile Entity Class.
% Changed Trade Table to inherit from the base class.
+ Added functionality to the base TE to store the owners name and UUID.
+ Added Base NBT Block Class.
$ Fixed ItemBlockNBT handling of NBT.
Diffstat (limited to 'src/Java/gtPlusPlus/core')
8 files changed, 234 insertions, 117 deletions
diff --git a/src/Java/gtPlusPlus/core/block/base/BlockBaseNBT.java b/src/Java/gtPlusPlus/core/block/base/BlockBaseNBT.java new file mode 100644 index 0000000000..3ecb556e09 --- /dev/null +++ b/src/Java/gtPlusPlus/core/block/base/BlockBaseNBT.java @@ -0,0 +1,73 @@ +package gtPlusPlus.core.block.base; + +import cpw.mods.fml.common.registry.GameRegistry; +import cpw.mods.fml.common.registry.LanguageRegistry; +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.item.base.itemblock.ItemBlockNBT; +import net.minecraft.block.Block; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.Explosion; +import net.minecraft.world.World; + +public abstract class BlockBaseNBT extends BlockContainer +{ + @SideOnly(Side.CLIENT) + private IIcon textureTop; + @SideOnly(Side.CLIENT) + private IIcon textureBottom; + @SideOnly(Side.CLIENT) + private IIcon textureFront; + + @SuppressWarnings("deprecation") + public BlockBaseNBT(Material material, String unlocalName, String displayName){ + super(material); + this.setBlockName(unlocalName); + this.setCreativeTab(AddToCreativeTab.tabMachines); + GameRegistry.registerBlock(this, ItemBlockNBT.class, unlocalName); + LanguageRegistry.addName(this, displayName); + } + + /** + * Gets the block's texture. Args: side, meta + */ + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(final int p_149691_1_, final int p_149691_2_){ + return p_149691_1_ == 1 ? this.textureTop : (p_149691_1_ == 0 ? this.textureBottom : ((p_149691_1_ != 2) && (p_149691_1_ != 4) ? this.blockIcon : this.textureFront)); + } + + @Override + public abstract TileEntity createNewTileEntity(final World world, final int p_149915_2_); + + @Override + public void breakBlock(World world, int x, int y, int z, Block block, int meta) { + super.breakBlock(world, x, y, z, block, meta); + } + + @Override + public void onBlockDestroyedByPlayer(World world, int x, int y, int z, int meta) { + super.onBlockDestroyedByPlayer(world, x, y, z, meta); + } + + @Override + public void onBlockDestroyedByExplosion(World world, int x, int y, int z, Explosion explosion) { + super.onBlockDestroyedByExplosion(world, x, y, z, explosion); + } + + @Override + public void onBlockHarvested(World world, int x, int y, int z, int meta, EntityPlayer player) { + super.onBlockHarvested(world, x, y, z, meta, player); + } + + @Override + public void onBlockExploded(World world, int x, int y, int z, Explosion explosion) { + super.onBlockExploded(world, x, y, z, explosion); + } + +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/block/machine/Machine_TradeTable.java b/src/Java/gtPlusPlus/core/block/machine/Machine_TradeTable.java index a5ba90013d..540ba61837 100644 --- a/src/Java/gtPlusPlus/core/block/machine/Machine_TradeTable.java +++ b/src/Java/gtPlusPlus/core/block/machine/Machine_TradeTable.java @@ -5,6 +5,7 @@ import cpw.mods.fml.common.registry.LanguageRegistry; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; import gtPlusPlus.GTplusplus; +import gtPlusPlus.core.block.base.BlockBaseNBT; import gtPlusPlus.core.creative.AddToCreativeTab; import gtPlusPlus.core.item.base.itemblock.ItemBlockNBT; import gtPlusPlus.core.lib.CORE; @@ -18,7 +19,7 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.IIcon; import net.minecraft.world.World; -public class Machine_TradeTable extends BlockContainer +public class Machine_TradeTable extends BlockBaseNBT { @SideOnly(Side.CLIENT) private IIcon textureTop; @@ -27,31 +28,13 @@ public class Machine_TradeTable extends BlockContainer @SideOnly(Side.CLIENT) private IIcon textureFront; - @SuppressWarnings("deprecation") - public Machine_TradeTable() - { - super(Material.leaves); - this.setBlockName("blockTradeBench"); - this.setCreativeTab(AddToCreativeTab.tabMachines); - GameRegistry.registerBlock(this, ItemBlockNBT.class, "blockTradeBench"); - LanguageRegistry.addName(this, "Trade-o-Mat"); - - } - - /** - * Gets the block's texture. Args: side, meta - */ - @Override - @SideOnly(Side.CLIENT) - public IIcon getIcon(final int p_149691_1_, final int p_149691_2_) - { - return p_149691_1_ == 1 ? this.textureTop : (p_149691_1_ == 0 ? this.textureBottom : ((p_149691_1_ != 2) && (p_149691_1_ != 4) ? this.blockIcon : this.textureFront)); + public Machine_TradeTable(){ + super(Material.leaves, "blockTradeBench", "Trade-o-Mat"); } @Override @SideOnly(Side.CLIENT) - public void registerBlockIcons(final IIconRegister p_149651_1_) - { + public void registerBlockIcons(final IIconRegister p_149651_1_){ this.blockIcon = p_149651_1_.registerIcon(CORE.MODID + ":" + "SwirlYellow"); this.textureTop = p_149651_1_.registerIcon(CORE.MODID + ":" + "workbench_top"); this.textureBottom = p_149651_1_.registerIcon(CORE.MODID + ":" + "SwirlYellow"); @@ -63,7 +46,6 @@ public class Machine_TradeTable extends BlockContainer */ @Override public boolean onBlockActivated(final World world, final int x, final int y, final int z, final EntityPlayer player, final int side, final float lx, final float ly, final float lz){ - if (world.isRemote) { return true; } diff --git a/src/Java/gtPlusPlus/core/container/Container_TradeTable.java b/src/Java/gtPlusPlus/core/container/Container_TradeTable.java index 3e89c1ddaf..e79a51f242 100644 --- a/src/Java/gtPlusPlus/core/container/Container_TradeTable.java +++ b/src/Java/gtPlusPlus/core/container/Container_TradeTable.java @@ -28,10 +28,14 @@ public class Container_TradeTable extends Container { public Container_TradeTable(final InventoryPlayer inventory, final TileEntityTradeTable te){ + this.tile_entity = te; this.inventoryChest = te.inventoryGrid; this.inventoryOutputs = te.inventoryOutputs; this.tile_entity.setContainer(this); + + if (te.isServerSide()) + Utils.LOG_INFO("Container - "+te.mOwnerName); int var6; int var7; diff --git a/src/Java/gtPlusPlus/core/gui/machine/GUI_TradeTable.java b/src/Java/gtPlusPlus/core/gui/machine/GUI_TradeTable.java index 70bfed3be3..93444a7a23 100644 --- a/src/Java/gtPlusPlus/core/gui/machine/GUI_TradeTable.java +++ b/src/Java/gtPlusPlus/core/gui/machine/GUI_TradeTable.java @@ -4,29 +4,45 @@ import org.lwjgl.opengl.GL11; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; -import gtPlusPlus.core.container.Container_ProjectTable; import gtPlusPlus.core.container.Container_TradeTable; -import gtPlusPlus.core.container.Container_Workbench; import gtPlusPlus.core.lib.CORE; -import gtPlusPlus.core.tileentities.machines.TileEntityProjectTable; import gtPlusPlus.core.tileentities.machines.TileEntityTradeTable; -import gtPlusPlus.core.tileentities.machines.TileEntityWorkbench; import gtPlusPlus.core.util.Utils; -import net.minecraft.client.gui.GuiButton; import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.InventoryPlayer; import net.minecraft.util.ResourceLocation; @SideOnly(Side.CLIENT) public class GUI_TradeTable extends GuiContainer { + + TileEntityTradeTable mThisTable; + final String mOwnerName; private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation(CORE.MODID, "textures/gui/ProjectTable.png"); - public GUI_TradeTable(final InventoryPlayer player_inventory, final TileEntityTradeTable te){ + public GUI_TradeTable(final InventoryPlayer player_inventory, final TileEntityTradeTable te, final String mOwnerName){ super(new Container_TradeTable(player_inventory, te)); + + if (te == null){ + this.mThisTable = null; + this.mOwnerName = mOwnerName; + Utils.LOG_INFO("Set invalid TE in GUI"); + } + else { + mThisTable = te; + this.mOwnerName = mOwnerName; + Utils.LOG_INFO("Set valid TE in GUI"); + } } @Override + protected void drawGuiContainerForegroundLayer(final int i, final int j){ + this.fontRendererObj.drawString(I18n.format("Owner: "+this.mOwnerName, new Object[0]), 28, 6, 4210752); + //this.fontRendererObj.drawString(I18n.format("container.inventory", new Object[0]), 8, this.ySize - 96 + 2, 4210752); + } + + @Override protected void drawGuiContainerBackgroundLayer(final float f, final int i, final int j){ GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); this.mc.renderEngine.bindTexture(craftingTableGuiTextures); diff --git a/src/Java/gtPlusPlus/core/handler/GuiHandler.java b/src/Java/gtPlusPlus/core/handler/GuiHandler.java index 55235e614e..a35795a906 100644 --- a/src/Java/gtPlusPlus/core/handler/GuiHandler.java +++ b/src/Java/gtPlusPlus/core/handler/GuiHandler.java @@ -11,6 +11,7 @@ import gtPlusPlus.core.gui.machine.*; import gtPlusPlus.core.interfaces.IGuiManager; import gtPlusPlus.core.inventories.BaseInventoryBackpack; import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.tileentities.base.TileEntityBase; import gtPlusPlus.core.tileentities.general.TileEntityFishTrap; import gtPlusPlus.core.tileentities.general.TileEntityHeliumGenerator; import gtPlusPlus.core.tileentities.machines.TileEntityProjectTable; @@ -124,7 +125,7 @@ public class GuiHandler implements IGuiHandler { return new GUI_FishTrap(player.inventory, (TileEntityFishTrap)te); } else if (ID == GUI7){ - return new GUI_TradeTable(player.inventory, (TileEntityTradeTable)te); + return new GUI_TradeTable(player.inventory, (TileEntityTradeTable)te, ((TileEntityBase) te).getOwner()); } } diff --git a/src/Java/gtPlusPlus/core/item/base/itemblock/ItemBlockNBT.java b/src/Java/gtPlusPlus/core/item/base/itemblock/ItemBlockNBT.java index 5b55bbd84f..69d01988f2 100644 --- a/src/Java/gtPlusPlus/core/item/base/itemblock/ItemBlockNBT.java +++ b/src/Java/gtPlusPlus/core/item/base/itemblock/ItemBlockNBT.java @@ -1,6 +1,11 @@ package gtPlusPlus.core.item.base.itemblock; +import gregtech.api.interfaces.tileentity.IGregTechTileEntity; import gregtech.api.util.GT_Utility; +import gregtech.common.blocks.GT_Block_Ores_Abstract; +import gregtech.common.blocks.GT_TileEntity_Ores; +import gtPlusPlus.core.tileentities.base.TileEntityBase; +import gtPlusPlus.core.util.Utils; import gtPlusPlus.core.util.player.PlayerUtils; import net.minecraft.block.Block; import net.minecraft.entity.Entity; @@ -9,6 +14,7 @@ import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; import net.minecraft.world.World; public class ItemBlockNBT extends ItemBlock { @@ -27,7 +33,7 @@ public class ItemBlockNBT extends ItemBlock { public void onUpdate(ItemStack item, World world, Entity entity, int p_77663_4_, boolean p_77663_5_) { if (entity instanceof EntityPlayerMP) { EntityPlayerMP mPlayer = (EntityPlayerMP) entity; - + NBTTagCompound rNBT = item.getTagCompound(); rNBT = ((rNBT == null) ? new NBTTagCompound() : rNBT); if (!rNBT.hasKey("mOwner")){ @@ -52,6 +58,32 @@ public class ItemBlockNBT extends ItemBlock { rNBT.setBoolean("mOP", false); } GT_Utility.ItemNBT.setNBT(item, rNBT); - } + } + + @Override + public boolean placeBlockAt(ItemStack aStack, EntityPlayer aPlayer, World aWorld, int aX, int aY, int aZ, int side, + float hitX, float hitY, float hitZ, int aMeta) { + + + + if (!(aWorld.setBlock(aX, aY, aZ, this.field_150939_a, 0, 3))) { + return false; + } + if (aWorld.getBlock(aX, aY, aZ) == this.field_150939_a) { + this.field_150939_a.onBlockPlacedBy(aWorld, aX, aY, aZ, aPlayer, aStack); + this.field_150939_a.onPostBlockPlaced(aWorld, aX, aY, aZ, aMeta); + } + + TileEntityBase tTileEntity = (TileEntityBase) aWorld.getTileEntity(aX, aY, aZ); + if (tTileEntity != null && aPlayer != null) { + if (tTileEntity.isServerSide()){ + Utils.LOG_INFO("Setting Tile Entity information"); + NBTTagCompound aNBT = GT_Utility.ItemNBT.getNBT(aStack); + tTileEntity.setOwnerInformation(aNBT.getString("mOwner"), aNBT.getString("mUUID"), aNBT.getBoolean("mOP")); + } + } + + return true; + } }
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/tileentities/base/TileEntityBase.java b/src/Java/gtPlusPlus/core/tileentities/base/TileEntityBase.java new file mode 100644 index 0000000000..9b0e8dee64 --- /dev/null +++ b/src/Java/gtPlusPlus/core/tileentities/base/TileEntityBase.java @@ -0,0 +1,89 @@ +package gtPlusPlus.core.tileentities.base; + +import java.util.UUID; + +import gtPlusPlus.core.util.Utils; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.tileentity.TileEntity; + +public class TileEntityBase extends TileEntity { + + public String mOwnerName = "null"; + public String mOwnerUUID = "null"; + private boolean mIsOwnerOP = false; + + @SuppressWarnings("static-method") + public NBTTagCompound getTag(final NBTTagCompound nbt, final String tag){ + if(!nbt.hasKey(tag)) + { + nbt.setTag(tag, new NBTTagCompound()); + } + return nbt.getCompoundTag(tag); + } + + @Override + public void writeToNBT(final NBTTagCompound nbt){ + super.writeToNBT(nbt); + nbt.setBoolean("mIsOwnerOP", this.mIsOwnerOP); + nbt.setString("mOwnerName", this.mOwnerName); + nbt.setString("mOwnerUUID", this.mOwnerUUID); + } + + @Override + public void readFromNBT(final NBTTagCompound nbt){ + this.mIsOwnerOP = nbt.getBoolean("mIsOwnerOP"); + this.mOwnerName = nbt.getString("mOwnerName"); + this.mOwnerUUID = nbt.getString("mOwnerUUID"); + super.readFromNBT(nbt); + } + + @Override + public void updateEntity() { + super.updateEntity(); + } + + @Override + public boolean canUpdate() { + return true; + } + + public String getOwner(){ + if (this.mOwnerName == null){ + return "null"; + } + return this.mOwnerName; + } + + public UUID getOwnerUUID(){ + return UUID.fromString(this.mOwnerUUID); + } + + public boolean isOwnerOP() { + return mIsOwnerOP; + } + + public void setOwnerInformation(String mName, String mUUID, boolean mOP){ + if (isServerSide()){ + if (this.mOwnerName.equals("null") || this.mOwnerUUID.equals("null") + || this.mOwnerName == null || this.mOwnerUUID == null){ + this.mOwnerName = mName; + this.mOwnerUUID = mUUID; + this.mIsOwnerOP = mOP; + Utils.LOG_INFO("Finished setting TE information. owner: "+this.mOwnerName+" | UUID: "+this.mOwnerUUID+" | OP: "+this.mIsOwnerOP); + } + } + } + + public boolean isServerSide(){ + if (this.hasWorldObj()){ + if (this.getWorldObj().isRemote){ + return false; + } + else { + return true; + } + } + return false; + } + +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityTradeTable.java b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityTradeTable.java index 8d65ad8926..6690e1e2c1 100644 --- a/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityTradeTable.java +++ b/src/Java/gtPlusPlus/core/tileentities/machines/TileEntityTradeTable.java @@ -1,26 +1,18 @@ package gtPlusPlus.core.tileentities.machines; -import java.util.List; -import java.util.Vector; - import gtPlusPlus.core.container.Container_TradeTable; import gtPlusPlus.core.inventories.tradetable.InventoryTradeMain; import gtPlusPlus.core.inventories.tradetable.InventoryTradeOutput; -import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.tileentities.base.TileEntityBase; import gtPlusPlus.core.util.nbt.NBTUtils; -import ic2.api.network.INetworkDataProvider; -import ic2.api.network.INetworkUpdateListener; -import ic2.api.tile.IWrenchable; -import ic2.core.IC2; -import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; -import net.minecraft.tileentity.TileEntity; -public class TileEntityTradeTable extends TileEntity implements INetworkDataProvider, INetworkUpdateListener, IWrenchable{ +public class TileEntityTradeTable extends TileEntityBase { public InventoryTradeMain inventoryGrid; public InventoryTradeOutput inventoryOutputs; + private Container_TradeTable container; public TileEntityTradeTable(){ @@ -32,19 +24,9 @@ public class TileEntityTradeTable extends TileEntity implements INetworkDataProv this.container = container_TradeTable; } - @SuppressWarnings("static-method") - public NBTTagCompound getTag(final NBTTagCompound nbt, final String tag){ - if(!nbt.hasKey(tag)) - { - nbt.setTag(tag, new NBTTagCompound()); - } - return nbt.getCompoundTag(tag); - } - @Override public void writeToNBT(final NBTTagCompound nbt){ super.writeToNBT(nbt); - nbt.setShort("facing", this.facing); this.inventoryGrid.writeToNBT(this.getTag(nbt, "ContentsGrid")); this.inventoryOutputs.writeToNBT(this.getTag(nbt, "ContentsOutput")); @@ -52,62 +34,9 @@ public class TileEntityTradeTable extends TileEntity implements INetworkDataProv @Override public void readFromNBT(final NBTTagCompound nbt){ + this.inventoryGrid.readFromNBT(nbt); + this.inventoryOutputs.readFromNBT(nbt); super.readFromNBT(nbt); - this.prevFacing = (this.facing = nbt.getShort("facing")); - this.inventoryGrid.readFromNBT(nbt.getCompoundTag("ContentsGrid")); - this.inventoryOutputs.readFromNBT(nbt.getCompoundTag("ContentsOutput")); - } - - @Override - public List<String> getNetworkedFields(){ - final List<String> ret = new Vector<String>(2); - ret.add("facing"); - return ret; - } - - - @Override - public boolean wrenchCanSetFacing(final EntityPlayer entityPlayer, final int side){ - return false; - } - - private short facing = 0; - public short prevFacing = 0; - - @Override - public void setFacing(final short facing1){ - this.facing = facing1; - if (this.prevFacing != facing1) { - IC2.network.get().updateTileEntityField(this, "facing"); - } - this.prevFacing = facing1; - } - - @Override - public short getFacing(){ - return this.facing; - } - - - @Override - public boolean wrenchCanRemove(final EntityPlayer entityPlayer){ - return true; - } - - @Override - public float getWrenchDropRate(){ - return 1.0F; - } - - @Override - public ItemStack getWrenchDrop(final EntityPlayer entityPlayer){ - return new ItemStack(this.worldObj.getBlock(this.xCoord, this.yCoord, this.zCoord), 1, this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord)); - } - - @Override - public void onNetworkUpdate(final String field) { - this.prevFacing = this.facing; - } @Override @@ -133,13 +62,4 @@ public class TileEntityTradeTable extends TileEntity implements INetworkDataProv super.updateEntity(); } - @Override - public boolean canUpdate() { - return true; - } - - - - - }
\ No newline at end of file |