mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-27 13:29:24 +01:00
Some fixes
This commit is contained in:
parent
5b9f668d14
commit
74c16757f8
5 changed files with 87 additions and 4 deletions
|
@ -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){
|
||||
|
|
|
@ -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};
|
||||
}
|
||||
|
||||
|
|
|
@ -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<EntityItem> items = (ArrayList<EntityItem>)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;
|
||||
}
|
||||
}
|
|
@ -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();
|
||||
}
|
||||
|
|
|
@ -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){
|
||||
|
|
Loading…
Reference in a new issue