Skip to content

Commit

Permalink
Everything is mostly working. shift-clicking more than one item into …
Browse files Browse the repository at this point in the history
…a slot restricted to one Item voids the rest of the items though.
  • Loading branch information
XDjackieXD committed Jun 29, 2017
1 parent e73f901 commit 8321def
Show file tree
Hide file tree
Showing 8 changed files with 69 additions and 37 deletions.
6 changes: 3 additions & 3 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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"
Expand Down Expand Up @@ -116,4 +116,4 @@ publishing {
}
}

idea { module { inheritOutputDirs = true } }
idea { module { inheritOutputDirs = true } }
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
20 changes: 10 additions & 10 deletions src/main/java/at/chaosfield/openradio/container/LaserContainer.java
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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);
}
Expand All @@ -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());

Expand Down Expand Up @@ -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);
Expand Down
15 changes: 10 additions & 5 deletions src/main/java/at/chaosfield/openradio/integration/Init.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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){

Expand All @@ -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 + ".");
}
}
}
3 changes: 2 additions & 1 deletion src/main/java/at/chaosfield/openradio/item/ADCItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ItemStack> itemList) {

for (int i = 0; i < 3; ++i) {
itemList.add(new ItemStack(item, 1, i));
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/at/chaosfield/openradio/item/DSPItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ItemStack> itemList) {

for (int i = 0; i < 3; ++i) {
itemList.add(new ItemStack(item, 1, i));
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/at/chaosfield/openradio/item/LaserItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<ItemStack> itemList) {

for (int i = 0; i < 3; ++i) {
itemList.add(new ItemStack(item, 1, i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 &&
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand All @@ -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();
Expand All @@ -430,7 +454,7 @@ public ItemStack decrStackSize(int slot, int amt){

@Override
public ItemStack removeStackFromSlot(int index){
return null;
return ItemStack.EMPTY;
}

@Override
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8321def

Please sign in to comment.