From 798a56ec63d78bd9a4092bca72b3f280e5cf3d8b Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 22 Dec 2016 21:20:16 +0100 Subject: [PATCH] Make the reconstructor convert without needing blocks --- .../api/internal/IAtomicReconstructor.java | 3 ++ .../mod/misc/MethodHandler.java | 41 ++++++++++++------- .../tile/TileEntityAtomicReconstructor.java | 6 +++ 3 files changed, 36 insertions(+), 14 deletions(-) diff --git a/src/main/java/de/ellpeck/actuallyadditions/api/internal/IAtomicReconstructor.java b/src/main/java/de/ellpeck/actuallyadditions/api/internal/IAtomicReconstructor.java index bcd2153c3..01a5e1e88 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/api/internal/IAtomicReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/api/internal/IAtomicReconstructor.java @@ -11,6 +11,7 @@ package de.ellpeck.actuallyadditions.api.internal; import de.ellpeck.actuallyadditions.api.lens.Lens; +import net.minecraft.util.EnumFacing; import net.minecraft.world.World; /** @@ -52,4 +53,6 @@ public interface IAtomicReconstructor{ int getEnergy(); Lens getLens(); + + EnumFacing getOrientation(); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/MethodHandler.java b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/MethodHandler.java index 8a3598f95..6379648b5 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/misc/MethodHandler.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/misc/MethodHandler.java @@ -35,11 +35,10 @@ import net.minecraft.item.crafting.IRecipe; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; -import net.minecraft.util.EnumParticleTypes; +import net.minecraft.util.EnumFacing; import net.minecraft.util.ResourceLocation; import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.util.math.BlockPos; -import net.minecraft.world.WorldServer; import java.util.ArrayList; import java.util.List; @@ -133,13 +132,32 @@ public class MethodHandler implements IMethodHandler{ @Override public boolean invokeConversionLens(IBlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile){ - if(hitBlock != null && !hitState.getBlock().isAir(hitState, tile.getWorldObject(), hitBlock)){ - int range = 2; + if(hitBlock != null){ + int range = 1; + int rangeX = 0; + int rangeY = 0; + int rangeZ = 0; + + EnumFacing facing = tile.getOrientation(); + if(facing != EnumFacing.UP && facing != EnumFacing.DOWN){ + rangeY = range; + + if(facing == EnumFacing.NORTH || facing == EnumFacing.SOUTH){ + rangeX = range; + } + else{ + rangeZ = range; + } + } + else{ + rangeX = range; + rangeZ = range; + } //Converting the Blocks - for(int reachX = -range; reachX < range+1; reachX++){ - for(int reachZ = -range; reachZ < range+1; reachZ++){ - for(int reachY = -range; reachY < range+1; reachY++){ + for(int reachX = -rangeX; reachX <= rangeX; reachX++){ + for(int reachZ = -rangeZ; reachZ <= rangeZ; reachZ++){ + for(int reachY = -rangeY; reachY <= rangeY; reachY++){ BlockPos pos = new BlockPos(hitBlock.getX()+reachX, hitBlock.getY()+reachY, hitBlock.getZ()+reachZ); if(!tile.getWorldObject().isAirBlock(pos)){ IBlockState state = tile.getWorldObject().getBlockState(pos); @@ -165,17 +183,12 @@ public class MethodHandler implements IMethodHandler{ } } } - else{ - if(tile.getWorldObject() instanceof WorldServer){ - ((WorldServer)tile.getWorldObject()).spawnParticle(EnumParticleTypes.END_ROD, false, pos.getX()+0.5, pos.getY()+0.5, pos.getZ()+0.5, 1, 0, 0, 0, 0D); - } - } } } } //Converting the Items - ArrayList items = (ArrayList)tile.getWorldObject().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(hitBlock.getX()-range, hitBlock.getY()-range, hitBlock.getZ()-range, hitBlock.getX()+range, hitBlock.getY()+range, hitBlock.getZ()+range)); + ArrayList items = (ArrayList)tile.getWorldObject().getEntitiesWithinAABB(EntityItem.class, new AxisAlignedBB(hitBlock.getX()-rangeX, hitBlock.getY()-rangeY, hitBlock.getZ()-rangeZ, hitBlock.getX()+1+rangeX, hitBlock.getY()+1+rangeY, hitBlock.getZ()+1+rangeZ)); for(EntityItem item : items){ ItemStack stack = item.getEntityItem(); if(!item.isDead && StackUtil.isValid(stack)){ @@ -208,7 +221,7 @@ public class MethodHandler implements IMethodHandler{ } } } - return true; + return !hitState.getBlock().isAir(hitState, tile.getWorldObject(), hitBlock); } return false; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java index 2c8aeba46..461be8371 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java @@ -59,6 +59,12 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple return true; } + @Override + public EnumFacing getOrientation(){ + IBlockState state = this.worldObj.getBlockState(this.pos); + return WorldUtil.getDirectionByPistonRotation(state.getBlock().getMetaFromState(state)); + } + @Override public void readSyncableNBT(NBTTagCompound compound, NBTType type){ super.readSyncableNBT(compound, type);