Fixed lenses not syncing correctly on the server when converting Item entities

This commit is contained in:
Ellpeck 2016-01-17 01:50:35 +01:00
parent a4f2251ff6
commit 957acd8ab8
2 changed files with 18 additions and 6 deletions

View file

@ -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<EntityItem> items = (ArrayList<EntityItem>)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);
}
}

View file

@ -65,7 +65,7 @@ public class LensNone extends Lens{
ArrayList<EntityItem> items = (ArrayList<EntityItem>)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<LensNoneRecipe> 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;