From 8321defd199a2d77759590bfc4d2e0c3547b35f5 Mon Sep 17 00:00:00 2001 From: "Jakob (XDjackieXD) Riepler" Date: Fri, 30 Jun 2017 00:37:30 +0200 Subject: [PATCH] Everything is mostly working. shift-clicking more than one item into a slot restricted to one Item voids the rest of the items though. --- build.gradle | 6 +-- .../openradio/block/LaserBlock.java | 2 +- .../openradio/container/LaserContainer.java | 20 +++---- .../openradio/integration/Init.java | 15 ++++-- .../at/chaosfield/openradio/item/ADCItem.java | 3 +- .../at/chaosfield/openradio/item/DSPItem.java | 3 +- .../chaosfield/openradio/item/LaserItem.java | 3 +- .../openradio/tileentity/LaserTileEntity.java | 54 +++++++++++++------ 8 files changed, 69 insertions(+), 37 deletions(-) diff --git a/build.gradle b/build.gradle index 9a9e2f7..d2f3e85 100644 --- a/build.gradle +++ b/build.gradle @@ -24,7 +24,7 @@ if (hasProperty('buildnumber')) { } minecraft { - version = "1.11.2-13.20.0.2259" + version = "1.11.2-13.20.1.2386" runDir = "run" mappings = "snapshot_20161126" @@ -44,7 +44,7 @@ repositories { dependencies { compile "li.cil.oc:OpenComputers:MC1.11.2-1.7.+:api" - compile "de.ellpeck.actuallyadditions:ActuallyAdditions:1.11.2-r106:api" + compile "de.ellpeck.actuallyadditions:ActuallyAdditions-unstable:1.11.2-r110-650:api" //no 1.11.2 version of ae yet :( //compile "appeng:appliedenergistics2:rv2-stable-10:dev" @@ -116,4 +116,4 @@ publishing { } } -idea { module { inheritOutputDirs = true } } \ No newline at end of file +idea { module { inheritOutputDirs = true } } diff --git a/src/main/java/at/chaosfield/openradio/block/LaserBlock.java b/src/main/java/at/chaosfield/openradio/block/LaserBlock.java index 83ce02a..a0aab8d 100644 --- a/src/main/java/at/chaosfield/openradio/block/LaserBlock.java +++ b/src/main/java/at/chaosfield/openradio/block/LaserBlock.java @@ -128,7 +128,7 @@ private void dropItems(World world, BlockPos pos){ for (int i = 0; i < inventory.getSizeInventory(); i++) { ItemStack item = inventory.getStackInSlot(i); - if (item != null && item.getCount() > 0) { + if (item != ItemStack.EMPTY && item.getCount() > 0) { float rx = rand.nextFloat() * 0.8F + 0.1F; float ry = rand.nextFloat() * 0.8F + 0.1F; float rz = rand.nextFloat() * 0.8F + 0.1F; diff --git a/src/main/java/at/chaosfield/openradio/container/LaserContainer.java b/src/main/java/at/chaosfield/openradio/container/LaserContainer.java index e790e50..56a011e 100644 --- a/src/main/java/at/chaosfield/openradio/container/LaserContainer.java +++ b/src/main/java/at/chaosfield/openradio/container/LaserContainer.java @@ -48,7 +48,7 @@ protected void bindPlayerInventory(IInventory inventoryPlayer) { @Override public ItemStack transferStackInSlot(EntityPlayer player, int slot) { - ItemStack currentStack = null; + ItemStack currentStack = ItemStack.EMPTY; Slot slotObject = inventorySlots.get(slot); if (slotObject != null && slotObject.getHasStack()) { @@ -58,38 +58,38 @@ public ItemStack transferStackInSlot(EntityPlayer player, int slot) { //Item is in Container. Transfer to Player inventory if (slot < tileEntity.getSizeInventory()) { if (!this.mergeItemStack(stackInSlot, tileEntity.getSizeInventory(), 36+tileEntity.getSizeInventory(), true)) { - return null; + return ItemStack.EMPTY; } //Item is in Player inventory. Transfer into container }else if(slot >= tileEntity.getSizeInventory()){ if(stackInSlot.getItem() == Items.dspItem){ if(!this.mergeItemStack(stackInSlot, LaserTileEntity.SLOT_DSP, LaserTileEntity.SLOT_DSP+1, false)){ - return null; + return ItemStack.EMPTY; } }else if(stackInSlot.getItem() == Items.photoReceptorItem){ if(!this.mergeItemStack(stackInSlot, LaserTileEntity.SLOT_PHOTO_RECEPTOR, LaserTileEntity.SLOT_PHOTO_RECEPTOR+1, false)){ - return null; + return ItemStack.EMPTY; } }else if(stackInSlot.getItem() == Items.mirrorItem){ if(!this.mergeItemStack(stackInSlot, LaserTileEntity.SLOT_MIRROR, LaserTileEntity.SLOT_MIRROR+1, false)){ - return null; + return ItemStack.EMPTY; } }else if(stackInSlot.getItem() == Items.laserItem){ if(!this.mergeItemStack(stackInSlot, LaserTileEntity.SLOT_LASER, LaserTileEntity.SLOT_LASER+1, false)){ - return null; + return ItemStack.EMPTY; } } } if (stackInSlot.getCount() == 0) { - slotObject.putStack(null); + slotObject.putStack(ItemStack.EMPTY); } else { slotObject.onSlotChanged(); } if (stackInSlot.getCount() == currentStack.getCount()) { - return null; + return ItemStack.EMPTY; } slotObject.onTake(player, stackInSlot); } @@ -112,7 +112,7 @@ protected boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, slot = this.inventorySlots.get(index); stackinslot = slot.getStack(); - if (stackinslot != null && stackinslot.getItem() == stack.getItem() && (!stack.getHasSubtypes() || stack.getItemDamage() == stackinslot.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack, stackinslot)) { + if (stackinslot != ItemStack.EMPTY && stackinslot.getItem() == stack.getItem() && (!stack.getHasSubtypes() || stack.getItemDamage() == stackinslot.getItemDamage()) && ItemStack.areItemStackTagsEqual(stack, stackinslot)) { int l = stackinslot.getCount() + stack.getCount(); int maxsize = Math.min(stack.getMaxStackSize(), slot.getSlotStackLimit()); @@ -149,7 +149,7 @@ protected boolean mergeItemStack(ItemStack stack, int startIndex, int endIndex, stackinslot = slot.getStack(); // Forge: Make sure to respect isItemValid in the slot. - if (stackinslot == null && slot.isItemValid(stack)) { + if (stackinslot == ItemStack.EMPTY && slot.isItemValid(stack)) { if (stack.getCount() < slot.getSlotStackLimit()) { slot.putStack(stack.copy()); stack.setCount(0); diff --git a/src/main/java/at/chaosfield/openradio/integration/Init.java b/src/main/java/at/chaosfield/openradio/integration/Init.java index f4fbfd9..e17fdd3 100644 --- a/src/main/java/at/chaosfield/openradio/integration/Init.java +++ b/src/main/java/at/chaosfield/openradio/integration/Init.java @@ -1,5 +1,6 @@ package at.chaosfield.openradio.integration; +import at.chaosfield.openradio.OpenRadio; import at.chaosfield.openradio.integration.actuallyAdditions.BookletEntry; import net.minecraftforge.fml.common.event.FMLInitializationEvent; import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; @@ -9,11 +10,11 @@ * Created by Jakob Riepler (XDjackieXD) */ public class Init{ - public static int minActAddVersion = 28; + public static int minActAddVersion = 33; public static int loadedActAddVersion = 0; - public static String[] actAddLaserRelayEnergy = {"actuallyadditions:blocklaserrelay", "actuallyadditions:blocklaserrelayadvanced", "actuallyadditions:blocklaserrelayextreme"}; - public static String[] actAddLaserRelayItem = {"actuallyadditions:blocklaserrelayitem", "actuallyadditions:blocklaserrelayitemwhitelist"}; - public static String[] actAddLaserRelayFluid = {"actuallyadditions:blocklaserrelayfluids"}; + public static String[] actAddLaserRelayEnergy = {"actuallyadditions:block_laser_relay", "actuallyadditions:block_laser_relay_advanced", "actuallyadditions:block_laser_relay_extreme"}; + public static String[] actAddLaserRelayItem = {"actuallyadditions:block_laser_relay_item", "actuallyadditions:block_laser_relay_item_whitelist"}; + public static String[] actAddLaserRelayFluid = {"actuallyadditions:block_laser_relay_fluids"}; public static void preInitIntegration(FMLPreInitializationEvent event){ @@ -24,7 +25,11 @@ public static void initIntegration(FMLInitializationEvent event){ } public static void postInitIntegration(FMLPostInitializationEvent event){ - if(Init.loadedActAddVersion >= Init.minActAddVersion) + if(Init.loadedActAddVersion >= Init.minActAddVersion){ + OpenRadio.logger.info("actually adding some features... (loaded Actually Additions integration with api level " + Init.loadedActAddVersion + ")"); BookletEntry.postInit(); + } else { + OpenRadio.logger.info("Actually Additions API version " + Init.loadedActAddVersion + " found but minimum required version for integration is " + Init.minActAddVersion + "."); + } } } diff --git a/src/main/java/at/chaosfield/openradio/item/ADCItem.java b/src/main/java/at/chaosfield/openradio/item/ADCItem.java index 049744d..64f9b93 100644 --- a/src/main/java/at/chaosfield/openradio/item/ADCItem.java +++ b/src/main/java/at/chaosfield/openradio/item/ADCItem.java @@ -2,6 +2,7 @@ import at.chaosfield.openradio.gui.CreativeTab; import at.chaosfield.openradio.OpenRadio; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.MathHelper; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -33,7 +34,7 @@ public String getUnlocalizedName(ItemStack par1ItemStack) } @SideOnly(Side.CLIENT) - public void getSubItems(Item item, CreativeTabs tab, List itemList) { + public void getSubItems(Item item, CreativeTabs tab, NonNullList itemList) { for (int i = 0; i < 3; ++i) { itemList.add(new ItemStack(item, 1, i)); diff --git a/src/main/java/at/chaosfield/openradio/item/DSPItem.java b/src/main/java/at/chaosfield/openradio/item/DSPItem.java index 3578e3c..2f7f62b 100644 --- a/src/main/java/at/chaosfield/openradio/item/DSPItem.java +++ b/src/main/java/at/chaosfield/openradio/item/DSPItem.java @@ -2,6 +2,7 @@ import at.chaosfield.openradio.gui.CreativeTab; import at.chaosfield.openradio.OpenRadio; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.MathHelper; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -33,7 +34,7 @@ public String getUnlocalizedName(ItemStack par1ItemStack) } @SideOnly(Side.CLIENT) - public void getSubItems(Item item, CreativeTabs tab, List itemList) { + public void getSubItems(Item item, CreativeTabs tab, NonNullList itemList) { for (int i = 0; i < 3; ++i) { itemList.add(new ItemStack(item, 1, i)); diff --git a/src/main/java/at/chaosfield/openradio/item/LaserItem.java b/src/main/java/at/chaosfield/openradio/item/LaserItem.java index fb4fa3d..ad3ef93 100644 --- a/src/main/java/at/chaosfield/openradio/item/LaserItem.java +++ b/src/main/java/at/chaosfield/openradio/item/LaserItem.java @@ -2,6 +2,7 @@ import at.chaosfield.openradio.gui.CreativeTab; import at.chaosfield.openradio.OpenRadio; +import net.minecraft.util.NonNullList; import net.minecraft.util.math.MathHelper; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; @@ -33,7 +34,7 @@ public String getUnlocalizedName(ItemStack par1ItemStack) } @SideOnly(Side.CLIENT) - public void getSubItems(Item item, CreativeTabs tab, List itemList) { + public void getSubItems(Item item, CreativeTabs tab, NonNullList itemList) { for (int i = 0; i < 3; ++i) { itemList.add(new ItemStack(item, 1, i)); diff --git a/src/main/java/at/chaosfield/openradio/tileentity/LaserTileEntity.java b/src/main/java/at/chaosfield/openradio/tileentity/LaserTileEntity.java index 97b225a..077ffc8 100644 --- a/src/main/java/at/chaosfield/openradio/tileentity/LaserTileEntity.java +++ b/src/main/java/at/chaosfield/openradio/tileentity/LaserTileEntity.java @@ -199,10 +199,10 @@ public boolean isConnected(){ } public boolean hasNeededComponents(){ - return inv[SLOT_DSP] != null && - inv[SLOT_PHOTO_RECEPTOR] != null && - inv[SLOT_MIRROR] != null && - inv[SLOT_LASER] != null && + return inv[SLOT_DSP] != ItemStack.EMPTY && + inv[SLOT_PHOTO_RECEPTOR] != ItemStack.EMPTY && + inv[SLOT_MIRROR] != ItemStack.EMPTY && + inv[SLOT_LASER] != ItemStack.EMPTY && inv[SLOT_DSP].getItem() == Items.dspItem && inv[SLOT_PHOTO_RECEPTOR].getItem() == Items.photoReceptorItem && inv[SLOT_MIRROR].getItem() == Items.mirrorItem && @@ -230,7 +230,7 @@ public ILaserAddon[] getAddons(){ } public int getItemTier(int slot, Object item){ - if(inv[slot] != null) + if(inv[slot] != ItemStack.EMPTY) if(inv[slot].getItem() == item) if(inv[slot].getItemDamage() <= 2 && inv[slot].getItemDamage() >= 0) return inv[slot].getItemDamage() + 1; @@ -294,11 +294,35 @@ public void onNeighbourChanged(BlockPos neighbour){ String name; tile = this.getWorld().getTileEntity(neighbour); - name = checkAddon(tile, EnumFacing.EAST); + + EnumFacing facing = EnumFacing.DOWN; + if(neighbour.getX() == this.pos.getX()){ + if(neighbour.getY() == this.pos.getY()) { + if(neighbour.getZ() > this.pos.getZ()) { + facing = EnumFacing.SOUTH; + } else { + facing = EnumFacing.NORTH; + } + } else if(neighbour.getZ() == this.pos.getZ()) { + if(neighbour.getY() > this.pos.getY()) { + facing = EnumFacing.UP; + } else { + facing = EnumFacing.DOWN; + } + } + } else if(neighbour.getY() == this.pos.getY() && neighbour.getZ() == this.pos.getZ()) { + if(neighbour.getX() > this.pos.getX()) { + facing = EnumFacing.EAST; + } else { + facing = EnumFacing.WEST; + } + } + + name = checkAddon(tile, facing); if(name != null){ - connectAddon(name, getAddon(tile, EnumFacing.EAST), EnumFacing.EAST); + connectAddon(name, getAddon(tile, facing), facing); }else{ - disconnectAddon(EnumFacing.EAST); + disconnectAddon(facing); } addonEnergyUsage = 0; @@ -405,7 +429,7 @@ public ItemStack getStackInSlot(int slot){ @Override public void setInventorySlotContents(int slot, ItemStack stack){ inv[slot] = stack; - if(stack != null && stack.getCount() > getInventoryStackLimit()){ + if(stack != ItemStack.EMPTY && stack.getCount() > getInventoryStackLimit()){ stack.setCount(getInventoryStackLimit()); } this.markDirty(); @@ -414,13 +438,13 @@ public void setInventorySlotContents(int slot, ItemStack stack){ @Override public ItemStack decrStackSize(int slot, int amt){ ItemStack stack = getStackInSlot(slot); - if(stack != null){ + if(stack != ItemStack.EMPTY){ if(stack.getCount() <= amt){ - setInventorySlotContents(slot, null); + setInventorySlotContents(slot, ItemStack.EMPTY); }else{ stack = stack.splitStack(amt); if(stack.getCount() == 0){ - setInventorySlotContents(slot, null); + setInventorySlotContents(slot, ItemStack.EMPTY); } } this.markDirty(); @@ -430,7 +454,7 @@ public ItemStack decrStackSize(int slot, int amt){ @Override public ItemStack removeStackFromSlot(int index){ - return null; + return ItemStack.EMPTY; } @Override @@ -487,7 +511,7 @@ public int getFieldCount(){ @Override public void clear(){ for(int i = 0; i < this.getSizeInventory(); i++) - this.setInventorySlotContents(i, null); + this.setInventorySlotContents(i, ItemStack.EMPTY); } @Override @@ -529,7 +553,7 @@ public NBTTagCompound writeToNBT(NBTTagCompound tagCompound){ NBTTagList itemList = new NBTTagList(); for(int i = 0; i < inv.length; i++){ ItemStack stack = inv[i]; - if(stack != null){ + if(stack != ItemStack.EMPTY){ NBTTagCompound tag = new NBTTagCompound(); tag.setByte("Slot", (byte) i); stack.writeToNBT(tag);