diff options
author | draknyte1 <draknyte1@hotmail.com> | 2017-02-15 20:09:32 +1000 |
---|---|---|
committer | draknyte1 <draknyte1@hotmail.com> | 2017-02-15 20:09:32 +1000 |
commit | f03b1c8457aa428f0aacbe5062676248f8133bb7 (patch) | |
tree | bf3477164b3ddd07455c187219b92d62ad55f6da /src/Java/gtPlusPlus/core | |
parent | 3022f3f4f96d8892b6d8c073eea7f852dcf1d71c (diff) | |
download | GT5-Unofficial-f03b1c8457aa428f0aacbe5062676248f8133bb7.tar.gz GT5-Unofficial-f03b1c8457aa428f0aacbe5062676248f8133bb7.tar.bz2 GT5-Unofficial-f03b1c8457aa428f0aacbe5062676248f8133bb7.zip |
+ Finished off the fishtrap, the basis of it works, it just needs loot.
Diffstat (limited to 'src/Java/gtPlusPlus/core')
7 files changed, 398 insertions, 26 deletions
diff --git a/src/Java/gtPlusPlus/core/block/ModBlocks.java b/src/Java/gtPlusPlus/core/block/ModBlocks.java index 892044627f..1f8ca23b30 100644 --- a/src/Java/gtPlusPlus/core/block/ModBlocks.java +++ b/src/Java/gtPlusPlus/core/block/ModBlocks.java @@ -4,8 +4,7 @@ import gtPlusPlus.core.block.base.BasicBlock.BlockTypes; import gtPlusPlus.core.block.base.BlockBaseOre; import gtPlusPlus.core.block.general.FirePit; import gtPlusPlus.core.block.general.LightGlass; -import gtPlusPlus.core.block.machine.Machine_Workbench; -import gtPlusPlus.core.block.machine.Machine_WorkbenchAdvanced; +import gtPlusPlus.core.block.machine.*; import gtPlusPlus.core.fluids.FluidRegistryHandler; import gtPlusPlus.core.lib.CORE; import gtPlusPlus.core.util.Utils; @@ -16,6 +15,7 @@ import cpw.mods.fml.common.registry.GameRegistry; public final class ModBlocks { + public static Block blockFishTrap; public static Block blockWorkbench; public static Block blockWorkbenchAdvanced; //Blocks @@ -60,6 +60,7 @@ public final class ModBlocks { blockWorkbench = new Machine_Workbench().setHardness(1.5F); blockWorkbenchAdvanced = new Machine_WorkbenchAdvanced().setHardness(2.5F); blockFirePit = new FirePit(); + blockFishTrap = new FishTrap(); blockOreFluorite = new BlockBaseOre("oreFluorite", "Fluorite", Material.rock, BlockTypes.ORE, Utils.rgbtoHexValue(120, 120, 30), 3); diff --git a/src/Java/gtPlusPlus/core/block/machine/FishTrap.java b/src/Java/gtPlusPlus/core/block/machine/FishTrap.java new file mode 100644 index 0000000000..089e63597b --- /dev/null +++ b/src/Java/gtPlusPlus/core/block/machine/FishTrap.java @@ -0,0 +1,91 @@ +package gtPlusPlus.core.block.machine; + +import gtPlusPlus.GTplusplus; +import gtPlusPlus.core.creative.AddToCreativeTab; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.tileentities.general.TileEntityFishTrap; +import net.minecraft.block.BlockContainer; +import net.minecraft.block.material.Material; +import net.minecraft.client.renderer.texture.IIconRegister; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.tileentity.TileEntity; +import net.minecraft.util.IIcon; +import net.minecraft.world.World; +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; + +public class FishTrap extends BlockContainer +{ + @SideOnly(Side.CLIENT) + private IIcon textureTop; + @SideOnly(Side.CLIENT) + private IIcon textureBottom; + @SideOnly(Side.CLIENT) + private IIcon textureFront; + + + @SuppressWarnings("deprecation") + public FishTrap() + { + super(Material.wood); + this.setBlockName("blockFishTrap"); + this.setCreativeTab(AddToCreativeTab.tabMachines); + GameRegistry.registerBlock(this, "blockFishTrap"); + LanguageRegistry.addName(this, "Fish Catcher"); + + } + + /** + * Gets the block's texture. Args: side, meta + */ + @Override + @SideOnly(Side.CLIENT) + public IIcon getIcon(int p_149691_1_, 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 + @SideOnly(Side.CLIENT) + public void registerBlockIcons(IIconRegister p_149651_1_) + { + this.blockIcon = p_149651_1_.registerIcon(CORE.MODID + ":" + "TileEntities/" + "fishtrap"); + this.textureTop = p_149651_1_.registerIcon(CORE.MODID + ":" + "TileEntities/" + "fishtrap"); + this.textureBottom = p_149651_1_.registerIcon(CORE.MODID + ":" + "TileEntities/" + "fishtrap"); + this.textureFront = p_149651_1_.registerIcon(CORE.MODID + ":" + "TileEntities/" + "fishtrap"); + } + + /** + * Called upon block activation (right click on the block.) + */ + @Override + public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float lx, float ly, float lz) + { + if (world.isRemote) return true; + + TileEntity te = world.getTileEntity(x, y, z); + if (te != null && te instanceof TileEntityFishTrap){ + player.openGui(GTplusplus.instance, 5, world, x, y, z); + return true; + } + return false; + } + + @Override + public int getRenderBlockPass() { + return 1; + } + + @Override + public boolean isOpaqueCube() { + return false; + } + + @Override + public TileEntity createNewTileEntity(World world, int p_149915_2_) { + return new TileEntityFishTrap(); + } + +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/container/Container_FishTrap.java b/src/Java/gtPlusPlus/core/container/Container_FishTrap.java new file mode 100644 index 0000000000..c99a76ed39 --- /dev/null +++ b/src/Java/gtPlusPlus/core/container/Container_FishTrap.java @@ -0,0 +1,170 @@ +package gtPlusPlus.core.container; + +import gtPlusPlus.core.block.ModBlocks; +import gtPlusPlus.core.inventories.*; +import gtPlusPlus.core.tileentities.general.TileEntityFishTrap; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.inventory.*; +import net.minecraft.item.ItemStack; +import net.minecraft.world.World; + +public class Container_FishTrap extends Container { + + protected TileEntityFishTrap tile_entity; + public final InventoryFishTrap inventoryChest; + + private World worldObj; + private int posX; + private int posY; + private int posZ; + + + public static int StorageSlotNumber = 16; //Number of slots in storage area + public static int InventorySlotNumber = 36; //Inventory Slots (Inventory and Hotbar) + public static int FullSlotNumber = InventorySlotNumber + StorageSlotNumber; //All slots + + private int[] slotStorage = new int[16]; + + public Container_FishTrap(InventoryPlayer inventory, TileEntityFishTrap te){ + this.tile_entity = te; + this.inventoryChest = te.getInventory(); + + int var6; + int var7; + worldObj = te.getWorldObj(); + posX = te.xCoord; + posY = te.yCoord; + posZ = te.zCoord; + + int o=0; + + //Storage Side + for (var6 = 0; var6 < 4; ++var6) + { + for (var7 = 0; var7 < 4; ++var7) + { + //Utils.LOG_WARNING("Adding slots at var:"+(var7 + var6 * 4)+" x:"+(8 + var7 * 18)+" y:"+(7 + var6 * 18)); + this.addSlotToContainer(new Slot(inventoryChest, var7 + var6 * 4, 8 + var7 * 18, 7 + var6 * 18)); + slotStorage[o] = o; + o++; + } + } + + o=0; + + //Player Inventory + for (var6 = 0; var6 < 3; ++var6) + { + for (var7 = 0; var7 < 9; ++var7) + { + this.addSlotToContainer(new Slot(inventory, var7 + var6 * 9 + 9, 8 + var7 * 18, 84 + var6 * 18)); + } + } + + //Player Hotbar + for (var6 = 0; var6 < 9; ++var6) + { + this.addSlotToContainer(new Slot(inventory, var6, 8 + var6 * 18, 142)); + } + + } + + @Override + public ItemStack slotClick(int aSlotIndex, int aMouseclick, int aShifthold, EntityPlayer aPlayer){ + + if (!aPlayer.worldObj.isRemote){ + if (aSlotIndex == 999 || aSlotIndex == -999){ + //Utils.LOG_WARNING("??? - "+aSlotIndex); + } + } + return super.slotClick(aSlotIndex, aMouseclick, aShifthold, aPlayer); + } + + + + + + @Override + public void onContainerClosed(EntityPlayer par1EntityPlayer){ + super.onContainerClosed(par1EntityPlayer); + } + + + @Override + public boolean canInteractWith(EntityPlayer par1EntityPlayer){ + if (worldObj.getBlock(posX, posY, posZ) != ModBlocks.blockFishTrap){ + return false; + } + + return par1EntityPlayer.getDistanceSq((double)posX + 0.5D, (double)posY + 0.5D, (double)posZ + 0.5D) <= 64D; + } + + + @Override + public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) + { + ItemStack var3 = null; + Slot var4 = (Slot)this.inventorySlots.get(par2); + + if (var4 != null && var4.getHasStack()) + { + ItemStack var5 = var4.getStack(); + var3 = var5.copy(); + + /*if (par2 == 0) + { + if (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, true)) + { + return null; + } + + var4.onSlotChange(var5, var3); + } + else if (par2 >= InOutputSlotNumber && par2 < InventoryOutSlotNumber) + { + if (!this.mergeItemStack(var5, InventoryOutSlotNumber, FullSlotNumber, false)) + { + return null; + } + } + else if (par2 >= InventoryOutSlotNumber && par2 < FullSlotNumber) + { + if (!this.mergeItemStack(var5, InOutputSlotNumber, InventoryOutSlotNumber, false)) + { + return null; + } + } + else if (!this.mergeItemStack(var5, InOutputSlotNumber, FullSlotNumber, false)) + { + return null; + }*/ + + if (var5.stackSize == 0) + { + var4.putStack((ItemStack)null); + } + else + { + var4.onSlotChanged(); + } + + if (var5.stackSize == var3.stackSize) + { + return null; + } + + var4.onPickupFromSlot(par1EntityPlayer, var5); + } + + return var3; + } + + //Can merge Slot + @Override + public boolean func_94530_a(ItemStack p_94530_1_, Slot p_94530_2_) { + return super.func_94530_a(p_94530_1_, p_94530_2_); + } + + +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/gui/machine/GUI_FishTrap.java b/src/Java/gtPlusPlus/core/gui/machine/GUI_FishTrap.java new file mode 100644 index 0000000000..7c0be39146 --- /dev/null +++ b/src/Java/gtPlusPlus/core/gui/machine/GUI_FishTrap.java @@ -0,0 +1,58 @@ +package gtPlusPlus.core.gui.machine; + +import gtPlusPlus.core.container.Container_FishTrap; +import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.tileentities.general.TileEntityFishTrap; +import net.minecraft.client.gui.inventory.GuiContainer; +import net.minecraft.entity.player.InventoryPlayer; +import net.minecraft.util.ResourceLocation; + +import org.lwjgl.opengl.GL11; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; + +@SideOnly(Side.CLIENT) +public class GUI_FishTrap extends GuiContainer { + + private static final ResourceLocation craftingTableGuiTextures = new ResourceLocation(CORE.MODID, "textures/gui/BronzeCraftingTable.png"); + + public GUI_FishTrap(InventoryPlayer player_inventory, TileEntityFishTrap te){ + super(new Container_FishTrap(player_inventory, te)); + } + + + @Override + protected void drawGuiContainerForegroundLayer(int i, int j){ + //this.fontRendererObj.drawString(I18n.format("Workbench", 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(float f, int i, int j){ + GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f); + this.mc.renderEngine.bindTexture(craftingTableGuiTextures); + int x = (width - xSize) / 2; + int y = (height - ySize) / 2; + this.drawTexturedModalRect(x, y, 0, 0, xSize, ySize); + } + + + //This method is called when the Gui is first called! + @Override + public void initGui() + { + //You have to add this line for the Gui to function properly! + super.initGui(); + + //The parameters of GuiButton are(id, x, y, width, height, text); + //this.buttonList.add(new GuiButton( 1, 367, 132, 18, 18, "X")); + //this.buttonList.add(new GuiButton( 2, 385, 132, 18, 18, "Y")); + //NOTE: the id always has to be different or else it might get called twice or never! + + //Add any other buttons here too! + } + +}
\ No newline at end of file diff --git a/src/Java/gtPlusPlus/core/handler/GuiHandler.java b/src/Java/gtPlusPlus/core/handler/GuiHandler.java index 69a40acaa7..5f2416413b 100644 --- a/src/Java/gtPlusPlus/core/handler/GuiHandler.java +++ b/src/Java/gtPlusPlus/core/handler/GuiHandler.java @@ -5,11 +5,11 @@ import gtPlusPlus.core.container.*; import gtPlusPlus.core.gui.beta.Gui_ID_Registry; import gtPlusPlus.core.gui.beta.MU_GuiId; import gtPlusPlus.core.gui.item.GuiBaseBackpack; -import gtPlusPlus.core.gui.machine.GUI_Workbench; -import gtPlusPlus.core.gui.machine.GUI_WorkbenchAdvanced; +import gtPlusPlus.core.gui.machine.*; import gtPlusPlus.core.interfaces.IGuiManager; import gtPlusPlus.core.inventories.BaseInventoryBackpack; import gtPlusPlus.core.lib.CORE; +import gtPlusPlus.core.tileentities.general.TileEntityFishTrap; import gtPlusPlus.core.tileentities.machines.TileEntityWorkbench; import gtPlusPlus.core.tileentities.machines.TileEntityWorkbenchAdvanced; import gtPlusPlus.core.util.Utils; @@ -30,7 +30,7 @@ public class GuiHandler implements IGuiHandler { public static final int GUI3 = 2; //BackpackHandler public static final int GUI4 = 3; //Workbench public static final int GUI5 = 4; //Workbench Adv - public static final int GUI6 = 5; // + public static final int GUI6 = 5; //Fish trap public static final int GUI7 = 6; // public static final int GUI8 = 7; // @@ -79,6 +79,9 @@ public class GuiHandler implements IGuiHandler { return new Container_WorkbenchAdvanced(player.inventory, (TileEntityWorkbenchAdvanced)te); } + if (ID == GUI6){ + return new Container_FishTrap(player.inventory, (TileEntityFishTrap)te); + } } @@ -122,6 +125,9 @@ public class GuiHandler implements IGuiHandler { Utils.LOG_INFO("sad"); return new GUI_WorkbenchAdvanced(player.inventory, (TileEntityWorkbenchAdvanced)te); } + if (ID == GUI6){ + return new GUI_FishTrap(player.inventory, (TileEntityFishTrap)te); + } } return null; diff --git a/src/Java/gtPlusPlus/core/inventories/InventoryFishtrap.java b/src/Java/gtPlusPlus/core/inventories/InventoryFishtrap.java index d7a9d6bfa5..7f518891bf 100644 --- a/src/Java/gtPlusPlus/core/inventories/InventoryFishtrap.java +++ b/src/Java/gtPlusPlus/core/inventories/InventoryFishtrap.java @@ -6,7 +6,7 @@ import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; -public class InventoryFishtrap implements IInventory{ +public class InventoryFishTrap implements IInventory{ private String name = "Fishtrap"; @@ -19,7 +19,7 @@ public class InventoryFishtrap implements IInventory{ /** * @param itemstack - the ItemStack to which this inventory belongs */ - public InventoryFishtrap() + public InventoryFishTrap() { } diff --git a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java index 61cacb06e8..004d551947 100644 --- a/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java +++ b/src/Java/gtPlusPlus/core/tileentities/general/TileEntityFishTrap.java @@ -3,8 +3,13 @@ package gtPlusPlus.core.tileentities.general; import java.util.UUID; import gtPlusPlus.core.inventories.*; +import gtPlusPlus.core.util.Utils; +import gtPlusPlus.core.util.item.ItemUtils; +import gtPlusPlus.core.util.math.MathUtils; import net.minecraft.block.Block; import net.minecraft.init.Blocks; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.tileentity.TileEntity; @@ -13,30 +18,36 @@ public class TileEntityFishTrap extends TileEntity{ private UUID ownerUUID; private int tickCount = 0; private boolean isInWater = false; - private InventoryFishtrap inventoryChest; - private int locationX = this.xCoord; - private int locationY = this.yCoord;; - private int locationZ = this.zCoord;; + private InventoryFishTrap inventoryContents; + private int locationX; + private int locationY; + private int locationZ; public TileEntityFishTrap(){ - this.inventoryChest = new InventoryFishtrap();//number of slots - without product slot + this.inventoryContents = new InventoryFishTrap();//number of slots - without product slot this.canUpdate(); + setTileLocation(); } public boolean setTileLocation(){ if (this.hasWorldObj()){ + if (!this.getWorldObj().isRemote){ locationX = this.xCoord; locationY = this.yCoord; locationZ = this.zCoord; return true; - + } } return false; } public final boolean isSurroundedByWater(){ + setTileLocation(); Block[] surroundingBlocks = new Block[6]; if (this.hasWorldObj()){ + //Utils.LOG_INFO("FT has world object"); + if (!this.getWorldObj().isRemote){ + //Utils.LOG_INFO("running code serverside"); surroundingBlocks[0] = worldObj.getBlock(locationX, locationY+1, locationZ); //Above surroundingBlocks[1] = worldObj.getBlock(locationX, locationY-1, locationZ); //Below surroundingBlocks[2] = worldObj.getBlock(locationX+1, locationY, locationZ); @@ -45,31 +56,66 @@ public class TileEntityFishTrap extends TileEntity{ surroundingBlocks[5] = worldObj.getBlock(locationX, locationY, locationZ-1); int waterCount = 0; for (Block checkBlock : surroundingBlocks){ - if (checkBlock == Blocks.water || checkBlock == Blocks.flowing_water){ + //Utils.LOG_INFO("found "+checkBlock.getLocalizedName()); + if (checkBlock == Blocks.water || checkBlock == Blocks.flowing_water || checkBlock.getUnlocalizedName().toLowerCase().contains("water")){ waterCount++; } } - if (waterCount >= 5){ + if (waterCount >= 4){ + //Utils.LOG_INFO("found water"); return true; } - return false; + } + } + //Utils.LOG_INFO("Error finding water"); + return false; + } + + public InventoryFishTrap getInventory(){ + return this.inventoryContents; + } + + public boolean tryAddLoot(){ + if (this.getInventory().getInventory() != null){ + int checkingSlot = 0; + for (ItemStack contents : this.getInventory().getInventory()){ + if (contents == null){ + this.getInventory().setInventorySlotContents(checkingSlot, ItemUtils.getSimpleStack(Items.fish)); + } + checkingSlot++; + } } + return false; } @Override public void updateEntity(){ - //if (anyPlayerInRange()){ - this.tickCount += 1; - if (this.worldObj.isRemote){ + if (!this.worldObj.isRemote){ + this.tickCount++; + //Utils.LOG_INFO("Ticking "+this.tickCount); + //Check if the Tile is within water once per second. + if (this.tickCount%20==0){ this.isInWater = isSurroundedByWater(); - + Utils.LOG_INFO("In water? "+this.isInWater+" tick:"+this.tickCount); + } + else { + + } + //Try add some loot once every 30 seconds. + if (this.tickCount%300==0){ if (this.isInWater){ - //Add Loot - } - //Add some Loot + //Add loot + Utils.LOG_INFO("Adding Loot to the fishtrap at x["+this.locationX+"] y["+this.locationY+"] z["+this.locationZ+"]"); + } + this.tickCount = 0; } - //} + if (this.tickCount > 1000){ + this.tickCount = 0; + } + + + } } public boolean anyPlayerInRange(){ @@ -96,7 +142,7 @@ public class TileEntityFishTrap extends TileEntity{ @Override public void writeToNBT(NBTTagCompound tagCompound) { super.writeToNBT(tagCompound); - inventoryChest.writeToNBT(getTag(tagCompound, "ContentsChest")); + inventoryContents.writeToNBT(getTag(tagCompound, "ContentsChest")); UUID ownerUUID = getOwnerUUID(); if (ownerUUID != null){ tagCompound.setLong("OwnerUUIDMost", ownerUUID.getMostSignificantBits()); @@ -108,7 +154,7 @@ public class TileEntityFishTrap extends TileEntity{ public void readFromNBT(NBTTagCompound tagCompound) { super.readFromNBT(tagCompound); - inventoryChest.readFromNBT(tagCompound.getCompoundTag("ContentsChest")); + inventoryContents.readFromNBT(tagCompound.getCompoundTag("ContentsChest")); setOwnerUUID(new UUID(tagCompound.getLong("OwnerUUIDMost"), tagCompound.getLong("OwnerUUIDLeast"))); } |