From 957acd8ab8ab3efe070840680f7f264265b48813 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Sun, 17 Jan 2016 01:50:35 +0100 Subject: [PATCH] Fixed lenses not syncing correctly on the server when converting Item entities --- .../mod/items/lens/LensColor.java | 16 ++++++++++++---- .../mod/items/lens/LensNone.java | 8 ++++++-- 2 files changed, 18 insertions(+), 6 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensColor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensColor.java index 89e6d898d..5bab22e1e 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensColor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensColor.java @@ -20,6 +20,7 @@ import net.minecraft.block.Block; import net.minecraft.entity.item.EntityItem; import net.minecraft.init.Blocks; import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.BlockPos; @@ -71,15 +72,22 @@ public class LensColor extends Lens{ ArrayList items = (ArrayList)tile.getWorldObject().getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.fromBounds(hitBlock.getX(), hitBlock.getY(), hitBlock.getZ(), hitBlock.getX()+1, hitBlock.getY()+1, hitBlock.getZ()+1)); for(EntityItem item : items){ - if(item.getEntityItem() != null && tile.getEnergy() >= ENERGY_USE){ + if(!item.isDead && item.getEntityItem() != null && tile.getEnergy() >= ENERGY_USE){ if(Util.arrayContains(CONVERTABLE_BLOCKS, item.getEntityItem().getItem()) >= 0 || Util.arrayContains(CONVERTABLE_BLOCKS, Block.getBlockFromItem(item.getEntityItem().getItem())) >= 0){ - int meta = item.getEntityItem().getItemDamage(); + ItemStack newStack = item.getEntityItem().copy(); + int meta = newStack.getItemDamage(); if(meta >= 15){ - item.getEntityItem().setItemDamage(0); + newStack.setItemDamage(0); } else{ - item.getEntityItem().setItemDamage(meta+1); + newStack.setItemDamage(meta+1); } + + item.setDead(); + + EntityItem newItem = new EntityItem(tile.getWorldObject(), item.posX, item.posY, item.posZ, newStack); + tile.getWorldObject().spawnEntityInWorld(newItem); + tile.extractEnergy(ENERGY_USE); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensNone.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensNone.java index d4f270fa8..d5e6ece46 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensNone.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensNone.java @@ -65,7 +65,7 @@ public class LensNone extends Lens{ ArrayList items = (ArrayList)tile.getWorldObject().getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.fromBounds(hitBlock.getX()-range, hitBlock.getY()-range, hitBlock.getZ()-range, hitBlock.getX()+range, hitBlock.getY()+range, hitBlock.getZ()+range)); for(EntityItem item : items){ ItemStack stack = item.getEntityItem(); - if(stack != null){ + if(!item.isDead && stack != null){ List recipes = LensNoneRecipeHandler.getRecipesFor(stack); for(LensNoneRecipe recipe : recipes){ if(recipe != null && tile.getEnergy() >= recipe.energyUse){ @@ -73,7 +73,11 @@ public class LensNone extends Lens{ if(outputs != null && !outputs.isEmpty()){ ItemStack outputCopy = outputs.get(0).copy(); outputCopy.stackSize = stack.stackSize; - item.setEntityItemStack(outputCopy); + + item.setDead(); + + EntityItem newItem = new EntityItem(tile.getWorldObject(), item.posX, item.posY, item.posZ, outputCopy); + tile.getWorldObject().spawnEntityInWorld(newItem); tile.extractEnergy(recipe.energyUse); break;