From 74c16757f837ffa85eeeea74aa8117812ebfdd84 Mon Sep 17 00:00:00 2001 From: Ellpeck Date: Thu, 5 May 2016 00:06:02 +0200 Subject: [PATCH] Some fixes --- .../mod/blocks/BlockAtomicReconstructor.java | 10 ++- .../mod/items/lens/LensColor.java | 4 +- .../mod/items/lens/LensDisruption.java | 71 +++++++++++++++++++ .../mod/items/lens/Lenses.java | 1 + .../tile/TileEntityAtomicReconstructor.java | 5 +- 5 files changed, 87 insertions(+), 4 deletions(-) create mode 100644 src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensDisruption.java diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java index e7eaaf5cb..b90d3110b 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockAtomicReconstructor.java @@ -25,7 +25,9 @@ import net.minecraft.client.Minecraft; import net.minecraft.client.gui.ScaledResolution; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.init.Items; import net.minecraft.item.EnumRarity; +import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.profiler.Profiler; import net.minecraft.tileentity.TileEntity; @@ -68,12 +70,18 @@ public class BlockAtomicReconstructor extends BlockContainerBase implements IHud TileEntityAtomicReconstructor reconstructor = (TileEntityAtomicReconstructor)world.getTileEntity(pos); if(reconstructor != null){ if(heldItem != null){ - if(heldItem.getItem() instanceof ILensItem && reconstructor.getStackInSlot(0) == null){ + Item item = heldItem.getItem(); + if(item instanceof ILensItem && reconstructor.getStackInSlot(0) == null){ ItemStack toPut = heldItem.copy(); toPut.stackSize = 1; reconstructor.setInventorySlotContents(0, toPut); player.inventory.decrStackSize(player.inventory.currentItem, 1); } + //Shush, don't tell anyone! + else if(item == Items.RECORD_11){ + reconstructor.counter++; + reconstructor.markDirty(); + } } else{ if(reconstructor.getStackInSlot(0) != null){ 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 8e81d4ed2..3d23f2748 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 @@ -41,7 +41,7 @@ public class LensColor extends Lens{ InitBlocks.blockColoredLampOn }; //Thanks to xdjackiexd for this, as I couldn't be bothered - private static final float[][] possibleColorLensColors = { + private static final float[][] POSSIBLE_COLORS = { {158F, 43F, 39F}, //Red {234F, 126F, 53F}, //Orange {194F, 181F, 28F}, //Yellow @@ -99,7 +99,7 @@ public class LensColor extends Lens{ @Override public float[] getColor(){ - float[] colors = possibleColorLensColors[Util.RANDOM.nextInt(possibleColorLensColors.length)]; + float[] colors = POSSIBLE_COLORS[Util.RANDOM.nextInt(POSSIBLE_COLORS.length)]; return new float[]{colors[0]/255F, colors[1]/255F, colors[2]/255F}; } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensDisruption.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensDisruption.java new file mode 100644 index 000000000..62da1ae6d --- /dev/null +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/LensDisruption.java @@ -0,0 +1,71 @@ +package de.ellpeck.actuallyadditions.mod.items.lens; + +import de.ellpeck.actuallyadditions.api.internal.IAtomicReconstructor; +import de.ellpeck.actuallyadditions.api.lens.Lens; +import de.ellpeck.actuallyadditions.mod.util.ModUtil; +import de.ellpeck.actuallyadditions.mod.util.PosUtil; +import de.ellpeck.actuallyadditions.mod.util.Util; +import net.minecraft.block.Block; +import net.minecraft.block.state.IBlockState; +import net.minecraft.entity.item.EntityItem; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.nbt.NBTTagCompound; +import net.minecraft.util.math.AxisAlignedBB; +import net.minecraft.util.math.BlockPos; + +import java.util.ArrayList; + +public class LensDisruption extends Lens{ + + @Override + public boolean invoke(IBlockState hitState, BlockPos hitBlock, IAtomicReconstructor tile){ + int energyUse = 150000; + if(tile.getEnergy() >= energyUse && hitBlock != null && !PosUtil.getBlock(hitBlock, tile.getWorldObject()).isAir(hitState, tile.getWorldObject(), hitBlock)){ + int range = 2; + 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)); + for(EntityItem item : items){ + ItemStack stack = item.getEntityItem(); + if(!item.isDead && stack != null){ + if(!stack.hasTagCompound() || !stack.getTagCompound().getBoolean(ModUtil.MOD_ID+"DisruptedAlready")){ + ItemStack newStack = null; + + while(newStack == null || newStack.getItem() == null){ + if(Util.RANDOM.nextBoolean()){ + newStack = new ItemStack(Item.REGISTRY.getRandomObject(Util.RANDOM)); + } + else{ + newStack = new ItemStack(Block.REGISTRY.getRandomObject(Util.RANDOM)); + } + } + newStack.stackSize = stack.stackSize; + + if(!newStack.hasTagCompound()){ + newStack.setTagCompound(new NBTTagCompound()); + } + newStack.getTagCompound().setBoolean(ModUtil.MOD_ID+"DisruptedAlready", true); + + item.setDead(); + + EntityItem newItem = new EntityItem(tile.getWorldObject(), item.posX, item.posY, item.posZ, newStack); + tile.getWorldObject().spawnEntityInWorld(newItem); + + tile.extractEnergy(energyUse); + } + } + } + return true; + } + return false; + } + + @Override + public float[] getColor(){ + return new float[]{246F/255F, 255F/255F, 183F/255F}; + } + + @Override + public int getDistance(){ + return 3; + } +} diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/Lenses.java b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/Lenses.java index f09d0c45d..fd2a8169f 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/Lenses.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/items/lens/Lenses.java @@ -18,4 +18,5 @@ public class Lenses{ public static final Lens LENS_DETONATION = new LensDetonation(); public static final Lens LENS_DEATH = new LensDeath(); public static final Lens LENS_COLOR = new LensColor(); + public static final Lens LENS_DISRUPTION = new LensDisruption(); } 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 c214ee763..6af2afbec 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityAtomicReconstructor.java @@ -39,6 +39,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple private int currentTime; private boolean activateOnceWithSignal; private int oldEnergy; + public int counter; public TileEntityAtomicReconstructor(){ super(1, "reconstructor"); @@ -48,6 +49,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple public void writeSyncableNBT(NBTTagCompound compound, boolean sync){ super.writeSyncableNBT(compound, sync); compound.setInteger("CurrentTime", this.currentTime); + compound.setInteger("Counter", this.counter); this.storage.writeToNBT(compound); } @@ -60,6 +62,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple public void readSyncableNBT(NBTTagCompound compound, boolean sync){ super.readSyncableNBT(compound, sync); this.currentTime = compound.getInteger("CurrentTime"); + this.counter = compound.getInteger("Counter"); this.storage.readFromNBT(compound); } @@ -116,7 +119,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple return ((ILensItem)this.slots[0].getItem()).getLens(); } } - return Lenses.LENS_NONE; + return this.counter >= 500 ? Lenses.LENS_DISRUPTION : Lenses.LENS_NONE; } private void shootLaser(int endX, int endY, int endZ, Lens currentLens){