From a6b6b599fc1623d7afba889675e4b89ebb2731c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malthe=20S=C3=B8lvberg?= Date: Sun, 22 Jun 2014 15:17:26 +0200 Subject: [PATCH 1/2] Early release of deployer --- .../blocks/machines/BlockDeployer.java | 134 ++--- .../quetzi/bluepower/entity/BPFakePlayer.java | 105 ++++ .../tileentities/tier1/TileDeployer.java | 476 +++++++++++------- 3 files changed, 440 insertions(+), 275 deletions(-) create mode 100644 src/main/java/net/quetzi/bluepower/entity/BPFakePlayer.java diff --git a/src/main/java/net/quetzi/bluepower/blocks/machines/BlockDeployer.java b/src/main/java/net/quetzi/bluepower/blocks/machines/BlockDeployer.java index 322af98..f92027f 100644 --- a/src/main/java/net/quetzi/bluepower/blocks/machines/BlockDeployer.java +++ b/src/main/java/net/quetzi/bluepower/blocks/machines/BlockDeployer.java @@ -16,110 +16,64 @@ import net.quetzi.bluepower.tileentities.tier1.TileDeployer; import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.SideOnly; + /** * * @author TheFjong - * + * */ -public class BlockDeployer extends BlockContainerBase{ - - private IIcon textureFront; - private IIcon textureFront_active; - private IIcon textureBack; - - public BlockDeployer() { - - super(Material.rock); - setCreativeTab(CustomTabs.tabBluePowerMachines); - setBlockName(Refs.BLOCKDEPLOYER_NAME); - } - - @Override - protected Class getTileEntity() { - - return TileDeployer.class; - } - - @Override - public GuiIDs getGuiID() { - - return GuiIDs.DEPLOYER_ID; - } - - @Override +public class BlockDeployer extends BlockContainerBase { + + private IIcon textureFront; + private IIcon textureFront_active; + private IIcon textureBack; + + public BlockDeployer() { + + super(Material.rock); + setCreativeTab(CustomTabs.tabBluePowerMachines); + setBlockName(Refs.BLOCKDEPLOYER_NAME); + } + + @Override + protected Class getTileEntity() { + + return TileDeployer.class; + } + + @Override + public GuiIDs getGuiID() { + + return GuiIDs.DEPLOYER_ID; + } + + @Override @SideOnly(Side.CLIENT) public void registerBlockIcons(IIconRegister iconRegister) { String unlocName = getUnlocalizedName().substring(5); - textureFront_active = iconRegister.registerIcon(Refs.MODID + ":" + Refs.MACHINE_TEXTURE_LOCATION + unlocName + "_front_active"); - + textureFront_active = iconRegister.registerIcon(Refs.MODID + ":" + Refs.MACHINE_TEXTURE_LOCATION + unlocName + "_front_active"); + textureFront = iconRegister.registerIcon(Refs.MODID + ":" + Refs.MACHINE_TEXTURE_LOCATION + unlocName + "_front"); textureBack = iconRegister.registerIcon(Refs.MODID + ":" + Refs.MACHINE_TEXTURE_LOCATION + unlocName + "_back"); blockIcon = iconRegister.registerIcon(Refs.MODID + ":" + Refs.MACHINE_TEXTURE_LOCATION + unlocName + "_side"); } - - - @Override - public IIcon getIcon(int side, int meta) { - - - ForgeDirection direction = ForgeDirection.getOrientation(meta); - if (side == direction.ordinal()) { - return textureFront; - - } else if (side == direction.getOpposite().ordinal()) { return textureBack; } - return blockIcon; - - } - - @SuppressWarnings("cast") - @Override - public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) - { - super.onBlockPlacedBy(world, x, y, z, player, stack); - if (world.getTileEntity(x, y, z) instanceof TileDeployer) - { - int direction = 0; - int facing; + + @Override + public IIcon getIcon(int side, int meta) { + + ForgeDirection direction = ForgeDirection.getOrientation(meta); + if (side == direction.ordinal()) { + return textureFront; - if (player.rotationPitch > 45) { - facing = 5; - } else if (player.rotationPitch < -45) { - facing = 4; - } else { - facing = MathHelper.floor_double((double)(player.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3; - } - - if (facing == 0){ - - direction = ForgeDirection.SOUTH.ordinal(); - }else - if(facing == 1){ - - direction = ForgeDirection.WEST.ordinal(); - }else - if(facing == 2){ - - direction = ForgeDirection.NORTH.ordinal(); - }else - if(facing == 3){ - - direction = ForgeDirection.EAST.ordinal(); - }else - if(facing == 4){ - - direction = ForgeDirection.UP.ordinal(); - }else - if(facing == 5){ - - direction = ForgeDirection.DOWN.ordinal(); - } - TileDeployer tile = (TileDeployer) world.getTileEntity(x, y, z); - tile.setOrientation(direction); - - } + } else if (side == direction.getOpposite().ordinal()) { return textureBack; } + return blockIcon; + } - + + + + } diff --git a/src/main/java/net/quetzi/bluepower/entity/BPFakePlayer.java b/src/main/java/net/quetzi/bluepower/entity/BPFakePlayer.java new file mode 100644 index 0000000..2f475be --- /dev/null +++ b/src/main/java/net/quetzi/bluepower/entity/BPFakePlayer.java @@ -0,0 +1,105 @@ +package net.quetzi.bluepower.entity; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.management.ItemInWorldManager; +import net.minecraft.util.ChunkCoordinates; +import net.minecraft.util.IChatComponent; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; +import net.minecraftforge.common.util.FakePlayer; +import net.quetzi.bluepower.references.Refs; + +import com.mojang.authlib.GameProfile; + +/** + * + * @author modmuss <3 + * + * @Credit Buildcraft + */ +public class BPFakePlayer{ + + + + + + + + public static EntityPlayer fakePlayer; + + public static String playerName() { + return ""; + } + + public static EntityPlayer createNewPlayer(World world) { + EntityPlayer player = new EntityPlayer(world, new GameProfile(null, + "[FakePlayerName]")) { + @Override + public void addChatMessage(IChatComponent var1) { + } + + @Override + public boolean canCommandSenderUseCommand(int var1, String var2) { + return false; + } + + @Override + public ChunkCoordinates getPlayerCoordinates() { + return null; + } + }; + return (EntityPlayer) player; + } + + public static EntityPlayer createNewPlayer(World world, int x, int y, int z) { + EntityPlayer player = new EntityPlayer(world, new GameProfile(null, + "[FakePlayerName]")) { + @Override + public void addChatMessage(IChatComponent var1) { + } + + @Override + public boolean canCommandSenderUseCommand(int var1, String var2) { + return false; + } + + @Override + public ChunkCoordinates getPlayerCoordinates() { + return null; + } + }; + player.posX = x; + player.posY = y; + player.posZ = z; + return (EntityPlayer) player; + } + + public static EntityPlayer getfakePlayer(World world) { + if (fakePlayer == null) { + fakePlayer = createNewPlayer(world); + } else { + fakePlayer.worldObj = world; + } + + return fakePlayer; + } + + public static EntityPlayer getfakePlayer(World world, int x, int y, + int z) { + if (fakePlayer == null) { + fakePlayer = createNewPlayer(world, x, y, z); + } else { + fakePlayer.worldObj = world; + fakePlayer.posX = x; + fakePlayer.posY = y; + fakePlayer.posZ = z; + } + + return fakePlayer; + } + + +} diff --git a/src/main/java/net/quetzi/bluepower/tileentities/tier1/TileDeployer.java b/src/main/java/net/quetzi/bluepower/tileentities/tier1/TileDeployer.java index c14679a..f5dd043 100644 --- a/src/main/java/net/quetzi/bluepower/tileentities/tier1/TileDeployer.java +++ b/src/main/java/net/quetzi/bluepower/tileentities/tier1/TileDeployer.java @@ -2,197 +2,303 @@ import java.util.List; +import scala.util.Random; +import scala.util.automata.WordBerrySethi; + +import com.mojang.authlib.GameProfile; +import com.sun.javafx.geom.Vec3d; +import com.sun.javafx.scene.text.HitInfo; +import com.sun.org.apache.bcel.internal.generic.AALOAD; + +import cpw.mods.fml.relauncher.Side; +import cpw.mods.fml.relauncher.SideOnly; +import net.minecraft.block.Block; +import net.minecraft.block.material.Material; +import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Blocks; import net.minecraft.inventory.ISidedInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemBlock; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.Vec3; +import net.minecraft.world.World; +import net.minecraft.world.WorldServer; import net.minecraftforge.common.util.FakePlayer; +import net.minecraftforge.common.util.FakePlayerFactory; import net.minecraftforge.common.util.ForgeDirection; +import net.minecraftforge.event.entity.minecart.MinecartCollisionEvent; +import net.minecraftforge.oredict.OreDictionary; +import net.quetzi.bluepower.BluePower; +import net.quetzi.bluepower.entity.BPFakePlayer; +import net.quetzi.bluepower.init.BPBlocks; +import net.quetzi.bluepower.references.Refs; import net.quetzi.bluepower.tileentities.TileBase; -public class TileDeployer extends TileBase implements ISidedInventory{ - - public boolean isActive = false; - private ForgeDirection orientation; - private boolean redstoneSignal; - protected static FakePlayer fakeplayer = null; - - @Override - public void updateEntity() { - - isActive = worldObj.isDaytime(); - - - } - - - private final ItemStack[] allInventories = new ItemStack[9]; - - /** - * This function gets called whenever the world/chunk loads - */ - @Override - public void readFromNBT(NBTTagCompound tCompound) { - - super.readFromNBT(tCompound); - - for (int i = 0; i < 9; i++) { - NBTTagCompound tc = tCompound.getCompoundTag("inventory" + i); - allInventories[i] = ItemStack.loadItemStackFromNBT(tc); - } - } - - /** - * This function gets called whenever the world/chunk is saved - */ - @Override - public void writeToNBT(NBTTagCompound tCompound) { - - super.writeToNBT(tCompound); - - for (int i = 0; i < 9; i++) { - if (allInventories[i] != null) { - NBTTagCompound tc = new NBTTagCompound(); - allInventories[i].writeToNBT(tc); - tCompound.setTag("inventory" + i, tc); - } - } - } - - @Override - public int getSizeInventory() { - - return allInventories.length; - } - - @Override - public ItemStack getStackInSlot(int i) { - - return this.allInventories[i]; - } - - @Override - public ItemStack decrStackSize(int slot, int amount) { - - // this needs to be side aware as well - ItemStack itemStack = getStackInSlot(slot); - if (itemStack != null) { - if (itemStack.stackSize <= amount) { - setInventorySlotContents(slot, null); - } else { - itemStack = itemStack.splitStack(amount); - if (itemStack.stackSize == 0) { - setInventorySlotContents(slot, null); - } - } - } - - return itemStack; - } - - @Override - public ItemStack getStackInSlotOnClosing(int i) { - - return getStackInSlot(i); - } - - @Override - public void setInventorySlotContents(int i, ItemStack itemStack) { - - this.allInventories[i] = itemStack; - worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); - } - - @Override - public String getInventoryName() { - - return "tile.buffer.name"; - } - - @Override - public boolean hasCustomInventoryName() { - - return true; - } - - @Override - public int getInventoryStackLimit() { - - return 64; - } - - @Override - public boolean isUseableByPlayer(EntityPlayer player) { - - return true; - } - - @Override - public void openInventory() { - - } - - @Override - public void closeInventory() { - - } - - @Override - public boolean isItemValidForSlot(int i, ItemStack itemStack) { - - return true; - } - - @Override - public List getDrops() { - - List drops = super.getDrops(); - for (ItemStack stack : allInventories) - if (stack != null) drops.add(stack); - return drops; - } - - @Override - public int[] getAccessibleSlotsFromSide(int var1) { - ForgeDirection direction = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); - - if (var1 == direction.ordinal()){ - return new int[]{}; - } - return new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8}; - } - - @Override - public boolean canInsertItem(int slot, ItemStack itemStack, int side) { - - for (int i : this.getAccessibleSlotsFromSide(side)) { - if (slot == i) { return true; } - } - return false; - } - - @Override - public boolean canExtractItem(int slot, ItemStack itemStack, int side) { - - for (int i : this.getAccessibleSlotsFromSide(side)) { - if (slot == i) { return true; } - } - return false; - } - - public void setOrientation(ForgeDirection orientation) - { - this.orientation = orientation; - } - - public void setOrientation(int orientation) - { - this.orientation = ForgeDirection.getOrientation(orientation); - } - - public ForgeDirection getOrientation() - { - return orientation; - } - +/** + * + * @author TheFjong + * + */ +public class TileDeployer extends TileBase implements ISidedInventory { + + private final ItemStack[] allInventories = new ItemStack[9]; + public boolean isActive = false; + private boolean redstoneSignal; + protected static BPFakePlayer fakeplayer = null; + + @Override + public void updateEntity() { + + isActive = worldObj.isDaytime(); + + } + + public void setRedstoneSignal(boolean newValue) { + + if (newValue != redstoneSignal) { + redstoneSignal = newValue; + if (redstoneSignal) { + if (!worldObj.isRemote) { + placeItem(); + } + } + } + } + + private void placeItem() { + + ForgeDirection direction = this.getFacingDirection(); + FakePlayer player = FakePlayerFactory.get((WorldServer) worldObj, new GameProfile(Refs.MODID + ":", "deployer.fakeplayer")); + + player.posX = xCoord + direction.offsetX; + player.posY = yCoord + direction.offsetY; + player.posZ = zCoord + direction.offsetZ; + player.eyeHeight = 0; + player.prevRotationPitch = player.rotationYaw = this.getFacingDirection().ordinal() * 90; + player.prevRotationYaw = player.rotationPitch = direction == ForgeDirection.UP ? 90 : direction == ForgeDirection.DOWN ? -90 : 0; + player.theItemInWorldManager.setBlockReachDistance(1); + + for (int i = 0; i < allInventories.length; i++) { + + if (allInventories != null) { + if (!(allInventories[i] == null)) { + + if (allInventories[i].getItem() instanceof ItemBlock) { + Block block = Block.getBlockFromItem(allInventories[i].getItem()); + Material material = worldObj.getBlock(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ) + .getMaterial(); + if (worldObj.isAirBlock(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ) + || material.isLiquid() || material.isReplaceable()) { + worldObj.setBlock(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ, block); + decrStackSize(i, 1); + break; + } + } else { + + player.inventory.currentItem = 0; + player.inventory.setInventorySlotContents(0, allInventories[i]); + + if (allInventories[i].stackSize > 1) { + + ItemStack result = allInventories[i].useItemRightClick(worldObj, player); + allInventories[getAvailableSlot()] = player.inventory.getStackInSlot(1); + break; + } else { + + ItemStack result = allInventories[i].useItemRightClick(worldObj, player); + + if (result == null || !result.isItemEqual(allInventories[i]) + || !ItemStack.areItemStackTagsEqual(result, allInventories[i])) { + allInventories[i] = result; + break; + } else { + + } + } + } + } + } + + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + for (int k = 0; k < player.inventory.getSizeInventory(); k++) { + player.inventory.setInventorySlotContents(k, null); + } + } + } + + public int getAvailableSlot() { + + for (int i = 0; i < allInventories.length; i++) { + + if (!(allInventories == null)) { + if (allInventories[i] == null) { return i; } + } + } + return 0; + } + + @Override + public void onBlockNeighbourChanged() { + + super.onBlockNeighbourChanged(); + if (!worldObj.isRemote) { + setRedstoneSignal(worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord)); + } + + } + + /** + * This function gets called whenever the world/chunk loads + */ + @Override + public void readFromNBT(NBTTagCompound tCompound) { + + super.readFromNBT(tCompound); + + for (int i = 0; i < 9; i++) { + NBTTagCompound tc = tCompound.getCompoundTag("inventory" + i); + allInventories[i] = ItemStack.loadItemStackFromNBT(tc); + } + } + + /** + * This function gets called whenever the world/chunk is saved + */ + @Override + public void writeToNBT(NBTTagCompound tCompound) { + + super.writeToNBT(tCompound); + + for (int i = 0; i < 9; i++) { + if (allInventories[i] != null) { + NBTTagCompound tc = new NBTTagCompound(); + allInventories[i].writeToNBT(tc); + tCompound.setTag("inventory" + i, tc); + } + } + } + + @Override + public int getSizeInventory() { + + return allInventories.length; + } + + @Override + public ItemStack getStackInSlot(int i) { + + return this.allInventories[i]; + } + + @Override + public ItemStack decrStackSize(int slot, int amount) { + + // this needs to be side aware as well + ItemStack itemStack = getStackInSlot(slot); + if (itemStack != null) { + if (itemStack.stackSize <= amount) { + setInventorySlotContents(slot, null); + } else { + itemStack = itemStack.splitStack(amount); + if (itemStack.stackSize == 0) { + setInventorySlotContents(slot, null); + } + } + } + + return itemStack; + } + + @Override + public ItemStack getStackInSlotOnClosing(int i) { + + return getStackInSlot(i); + } + + @Override + public void setInventorySlotContents(int i, ItemStack itemStack) { + + this.allInventories[i] = itemStack; + worldObj.markBlockForUpdate(xCoord, yCoord, zCoord); + } + + @Override + public String getInventoryName() { + + return "tile.deployer.name"; + } + + @Override + public boolean hasCustomInventoryName() { + + return true; + } + + @Override + public int getInventoryStackLimit() { + + return 64; + } + + @Override + public boolean isUseableByPlayer(EntityPlayer player) { + + return true; + } + + @Override + public void openInventory() { + + } + + @Override + public void closeInventory() { + + } + + @Override + public boolean isItemValidForSlot(int i, ItemStack itemStack) { + + return true; + } + + @Override + public List getDrops() { + + List drops = super.getDrops(); + for (ItemStack stack : allInventories) + if (stack != null) drops.add(stack); + return drops; + } + + @Override + public int[] getAccessibleSlotsFromSide(int var1) { + + ForgeDirection direction = ForgeDirection.getOrientation(worldObj.getBlockMetadata(xCoord, yCoord, zCoord)); + + if (var1 == direction.ordinal()) { return new int[] {}; } + return new int[] { 0, 1, 2, 3, 4, 5, 6, 7, 8 }; + } + + @Override + public boolean canInsertItem(int slot, ItemStack itemStack, int side) { + + for (int i : this.getAccessibleSlotsFromSide(side)) { + if (slot == i) { return true; } + } + return false; + } + + @Override + public boolean canExtractItem(int slot, ItemStack itemStack, int side) { + + for (int i : this.getAccessibleSlotsFromSide(side)) { + if (slot == i) { return true; } + } + return false; + } + } From 6e2b54f9c116f670fc66907c1c8c9a801ced6616 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Malthe=20S=C3=B8lvberg?= Date: Mon, 23 Jun 2014 19:18:15 +0200 Subject: [PATCH 2/2] Setup done --- build.gradle | 100 --- formatter.xml | 579 ------------------ .../blocks/machines/BlockDeployer.java | 3 - .../containers/ContainerDeployer.java | 100 +-- .../tileentities/tier1/TileDeployer.java | 58 +- 5 files changed, 55 insertions(+), 785 deletions(-) delete mode 100644 build.gradle delete mode 100644 formatter.xml diff --git a/build.gradle b/build.gradle deleted file mode 100644 index 9c0e5eb..0000000 --- a/build.gradle +++ /dev/null @@ -1,100 +0,0 @@ -buildscript { - repositories { - mavenCentral() - maven { - name = "forge" - url = "http://files.minecraftforge.net/maven" - } - maven { - name = "sonatype" - url = "https://oss.sonatype.org/content/repositories/snapshots/" - } - } - dependencies { - classpath 'net.minecraftforge.gradle:ForgeGradle:1.2-SNAPSHOT' - } -} - -apply plugin: 'forge' - -project.ext { - major = "0" - minor = "0" -} - - -version = "1.7.2-${project.ext.major}.${project.minor}" -group= "net.quetzi.bluepower" -archivesBaseName = "BluePower" - - -if (System.getenv().BUILD_NUMBER != null){ - version += ".${System.getenv().BUILD_NUMBER}" -}else{ - version += " - err" -} - -def grabDep(name, url){ - ant.get(src: url, dest: 'dep') - file("dep/" + url.substring(url.lastIndexOf("/"))).renameTo(file("dep/" + name + ".jar")) -} - -dependencies { - def f = new File('dep/') - if(f.exists()){ - f.delete() - } - f.mkdirs() - if(!f.exists()){ - f.mkdir() - } - println(" Downloading dependencies!") - grabDep('ccl', 'http://files.minecraftforge.net/maven/codechicken/CodeChickenLib/1.7.2-1.1.1.81/CodeChickenLib-1.7.2-1.1.1.81-dev.jar') - grabDep('fmp', 'http://files.minecraftforge.net/maven/codechicken/ForgeMultipart/1.7.2-1.1.0.282/ForgeMultipart-1.7.2-1.1.0.282-dev.jar') - grabDep('ccc', 'http://www.chickenbones.craftsaddle.org/Files/New_Versions/1.7.2/CodeChickenCore-1.7.2-1.0.0-dev.jar') - grabDep('nei', 'http://www.chickenbones.craftsaddle.org/Files/New_Versions/1.7.2/NotEnoughItems-1.7.2-1.0.1-dev.jar') - grabDep('ccc', 'http://www.chickenbones.craftsaddle.org/Files/New_Versions/1.7.2/CodeChickenCore-1.7.2-1.0.0-dev.jar') - - grabDep('oc', 'http://ci.cil.li/job/OpenComputers-MC1.7/190/artifact/build/libs/OpenComputers-MC1.7.2-1.3.0.190-beta.1-deobf.jar') - grabDep('waila', 'http://mobiusstrip.eu/maven/mcp/mobius/waila/Waila/1.5.2a/Waila-1.5.2a-dev.jar') - - println(" Adding dependencies!") - compile files("dep/ccl.jar", "dep/fmp.jar", "dep/nei.jar", "dep/ccc.jar", "dep/oc.jar", "dep/waila.jar") - println(" Finished adding dependencies!") -} - -minecraft { - version = "1.7.2-10.12.2.1121" - assetDir = "eclipse/assets" - - // replacing stuff in the source - replace '@MAJOR@', project.major - replace '@MINOR@', project.minor - replace '@MC_VERSION@', version - if(System.getenv("BUILD_NUMBER") != null){ - replace '@BUILD_NUMBER@', System.getenv("BUILD_NUMBER") - }else{ - replace '@BUILD_NUMBER@', 0 - } - -} - -processResources -{ - // this will ensure that this task is redone when the versions change. - inputs.property "version", project.version - inputs.property "mcversion", project.minecraft.version - - // replace stuff in mcmod.info, nothing else - from(sourceSets.main.resources.srcDirs) { - include '*.info' - - // replace version and mcversion - expand 'version':project.version, 'mcversion':project.minecraft.version - } - - // copy everything else, thats not the mcmod.info - from(sourceSets.main.resources.srcDirs) { - exclude 'mcmod.info' - } -} diff --git a/formatter.xml b/formatter.xml deleted file mode 100644 index d536adb..0000000 --- a/formatter.xml +++ /dev/null @@ -1,579 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/main/java/net/quetzi/bluepower/blocks/machines/BlockDeployer.java b/src/main/java/net/quetzi/bluepower/blocks/machines/BlockDeployer.java index f92027f..89809b5 100644 --- a/src/main/java/net/quetzi/bluepower/blocks/machines/BlockDeployer.java +++ b/src/main/java/net/quetzi/bluepower/blocks/machines/BlockDeployer.java @@ -73,7 +73,4 @@ public IIcon getIcon(int side, int meta) { } - - - } diff --git a/src/main/java/net/quetzi/bluepower/containers/ContainerDeployer.java b/src/main/java/net/quetzi/bluepower/containers/ContainerDeployer.java index 613d245..8ee2746 100644 --- a/src/main/java/net/quetzi/bluepower/containers/ContainerDeployer.java +++ b/src/main/java/net/quetzi/bluepower/containers/ContainerDeployer.java @@ -25,13 +25,13 @@ import net.quetzi.bluepower.tileentities.tier1.TileDeployer; public class ContainerDeployer extends Container { - + private final TileDeployer tileDeployer; - + public ContainerDeployer(InventoryPlayer invPlayer, TileDeployer deployer) { - - bindPlayerInventory(invPlayer); - this.tileDeployer= deployer; + + bindPlayerInventory(invPlayer); + this.tileDeployer = deployer; for (int i = 0; i < 3; ++i) { for (int j = 0; j < 3; ++j) { @@ -39,16 +39,16 @@ public ContainerDeployer(InventoryPlayer invPlayer, TileDeployer deployer) { } } } - + protected void bindPlayerInventory(InventoryPlayer invPlayer) { - + // Render inventory for (int i = 0; i < 3; i++) { for (int j = 0; j < 9; j++) { addSlotToContainer(new Slot(invPlayer, j + i * 9 + 9, 8 + j * 18, 84 + i * 18)); } } - + // Render hotbar for (int j = 0; j < 9; j++) { addSlotToContainer(new Slot(invPlayer, j, 8 + j * 18, 142)); @@ -56,12 +56,12 @@ protected void bindPlayerInventory(InventoryPlayer invPlayer) { } - @Override public boolean canInteractWith(EntityPlayer player) { return tileDeployer.isUseableByPlayer(player); } + @Override public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { @@ -90,86 +90,4 @@ public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2) { return itemstack; } - @Override - public boolean mergeItemStack(ItemStack par1ItemStack, int par2, int par3, boolean par4) { - - boolean flag1 = false; - int k = par2; - - if (par4) { - k = par3 - 1; - } - - Slot slot; - ItemStack itemstack1; - - if (par1ItemStack.isStackable()) { - while (par1ItemStack.stackSize > 0 && (!par4 && k < par3 || par4 && k >= par2)) { - slot = (Slot) this.inventorySlots.get(k); - itemstack1 = slot.getStack(); - - if (itemstack1 != null && itemstack1.getItem() == par1ItemStack.getItem() - && (!par1ItemStack.getHasSubtypes() || par1ItemStack.getItemDamage() == itemstack1.getItemDamage()) - && ItemStack.areItemStackTagsEqual(par1ItemStack, itemstack1) && slot.isItemValid(par1ItemStack)) { - int l = itemstack1.stackSize + par1ItemStack.stackSize; - - if (l <= par1ItemStack.getMaxStackSize()) { - par1ItemStack.stackSize = 0; - itemstack1.stackSize = l; - slot.onSlotChanged(); - flag1 = true; - } else if (itemstack1.stackSize < par1ItemStack.getMaxStackSize()) { - par1ItemStack.stackSize -= par1ItemStack.getMaxStackSize() - itemstack1.stackSize; - itemstack1.stackSize = par1ItemStack.getMaxStackSize(); - slot.onSlotChanged(); - flag1 = true; - } - } - - if (par4) { - --k; - } else { - ++k; - } - } - } - - if (par1ItemStack.stackSize > 0) { - if (par4) { - k = par3 - 1; - } else { - k = par2; - } - - while (!par4 && k < par3 || par4 && k >= par2) { - slot = (Slot) this.inventorySlots.get(k); - itemstack1 = slot.getStack(); - - if (itemstack1 == null && slot.isItemValid(par1ItemStack)) { - if (1 < par1ItemStack.stackSize) { - ItemStack copy = par1ItemStack.copy(); - copy.stackSize = 1; - slot.putStack(copy); - - par1ItemStack.stackSize -= 1; - flag1 = true; - break; - } else { - slot.putStack(par1ItemStack.copy()); - slot.onSlotChanged(); - par1ItemStack.stackSize = 0; - flag1 = true; - break; - } - } - - if (par4) { - --k; - } else { - ++k; - } - } - } - return flag1; - } } diff --git a/src/main/java/net/quetzi/bluepower/tileentities/tier1/TileDeployer.java b/src/main/java/net/quetzi/bluepower/tileentities/tier1/TileDeployer.java index f5dd043..4f75743 100644 --- a/src/main/java/net/quetzi/bluepower/tileentities/tier1/TileDeployer.java +++ b/src/main/java/net/quetzi/bluepower/tileentities/tier1/TileDeployer.java @@ -2,6 +2,7 @@ import java.util.List; +import scala.runtime.StringFormat; import scala.util.Random; import scala.util.automata.WordBerrySethi; @@ -68,18 +69,29 @@ public void setRedstoneSignal(boolean newValue) { } } + private static final int[] ROTATION_SIDE_MAPPING = { 0, 0, 0, 2, 3, 1 }; + private void placeItem() { ForgeDirection direction = this.getFacingDirection(); - FakePlayer player = FakePlayerFactory.get((WorldServer) worldObj, new GameProfile(Refs.MODID + ":", "deployer.fakeplayer")); + FakePlayer player = new FakePlayer((WorldServer) worldObj, new GameProfile(Refs.MODID + "." + xCoord + "." + yCoord + "." + zCoord,".bluepower.fakeplayer.deployer")); + ForgeDirection side = ForgeDirection.VALID_DIRECTIONS[getBlockMetadata() % ForgeDirection.VALID_DIRECTIONS.length]; - player.posX = xCoord + direction.offsetX; - player.posY = yCoord + direction.offsetY; - player.posZ = zCoord + direction.offsetZ; - player.eyeHeight = 0; - player.prevRotationPitch = player.rotationYaw = this.getFacingDirection().ordinal() * 90; - player.prevRotationYaw = player.rotationPitch = direction == ForgeDirection.UP ? 90 : direction == ForgeDirection.DOWN ? -90 : 0; + player.eyeHeight = .5F; player.theItemInWorldManager.setBlockReachDistance(1); + System.out.println(player); + + + + player.prevRotationPitch = player.rotationYaw = 90; + player.prevRotationYawHead = 50; + player.posX = xCoord; + player.posY = yCoord; + player.posZ = zCoord; + + float hitX = xCoord; + float hitY = xCoord; + float hitZ = xCoord; for (int i = 0; i < allInventories.length; i++) { @@ -88,11 +100,10 @@ private void placeItem() { if (allInventories[i].getItem() instanceof ItemBlock) { Block block = Block.getBlockFromItem(allInventories[i].getItem()); - Material material = worldObj.getBlock(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ) - .getMaterial(); - if (worldObj.isAirBlock(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ) - || material.isLiquid() || material.isReplaceable()) { + Material material = worldObj.getBlock(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ).getMaterial(); + if (worldObj.isAirBlock(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ)|| material.isLiquid() || material.isReplaceable()) { worldObj.setBlock(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ, block); + decrStackSize(i, 1); break; } @@ -105,7 +116,19 @@ private void placeItem() { ItemStack result = allInventories[i].useItemRightClick(worldObj, player); allInventories[getAvailableSlot()] = player.inventory.getStackInSlot(1); - break; + if (result == null || !result.isItemEqual(allInventories[i])|| !ItemStack.areItemStackTagsEqual(result, allInventories[i])) { + } else { + + player.theItemInWorldManager.activateBlockOrUseItem(player, worldObj, allInventories[i], xCoord + direction.offsetX,yCoord + direction.offsetY, zCoord + direction.offsetZ, direction.ordinal(), hitX, hitY, hitZ); + ItemStack playerItem = player.inventory.getStackInSlot(0); + + if (playerItem == null || !playerItem.isItemEqual(allInventories[i])|| !ItemStack.areItemStackTagsEqual(playerItem, allInventories[i])) { + allInventories[i] = null; + } + break; + + } + } else { ItemStack result = allInventories[i].useItemRightClick(worldObj, player); @@ -116,6 +139,15 @@ private void placeItem() { break; } else { + player.theItemInWorldManager.activateBlockOrUseItem(player, worldObj, allInventories[i], xCoord + direction.offsetX, + yCoord + direction.offsetY, zCoord + direction.offsetZ, getFacingDirection().ordinal(), hitX, hitY, hitZ); + + ItemStack playerItem = player.inventory.getStackInSlot(0); + if (playerItem == null || !playerItem.isItemEqual(allInventories[i])|| !ItemStack.areItemStackTagsEqual(playerItem, allInventories[i])) { + allInventories[i] = null; + } + decrStackSize(i, 1); + break; } } } @@ -126,6 +158,8 @@ private void placeItem() { for (int k = 0; k < player.inventory.getSizeInventory(); k++) { player.inventory.setInventorySlotContents(k, null); } + player.setDead(); + worldObj.removeEntity(player); } }