mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-23 21:49:58 +00:00
Added shift click removal to machines.
This commit is contained in:
1 parent
053546be13
commit
0f318da1ca
5 files changed
+82
-56
No files matched your search
@@ -37,6 +37,7 @@ import crazypants.enderio.conduit.geom.ConduitConnectorType;
|
||||
import crazypants.enderio.conduit.redstone.IRedstoneConduit;
|
||||
import crazypants.enderio.machine.painter.PainterUtil;
|
||||
import crazypants.render.BoundingBox;
|
||||
import crazypants.util.Util;
|
||||
|
||||
public class BlockConduitBundle extends Block implements ITileEntityProvider {
|
||||
|
||||
@@ -354,7 +355,7 @@ public class BlockConduitBundle extends Block implements ITileEntityProvider {
|
||||
|
||||
if (!world.isRemote && !player.capabilities.isCreativeMode) {
|
||||
for (ItemStack st : drop) {
|
||||
ConduitUtil.dropItems(world, st, x, y, z);
|
||||
Util.dropItems(world, st, x, y, z);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import crazypants.enderio.conduit.power.IPowerConduit;
|
||||
import crazypants.enderio.conduit.power.PowerConduitNetwork;
|
||||
import crazypants.enderio.conduit.redstone.IRedstoneConduit;
|
||||
import crazypants.enderio.conduit.redstone.RedstoneConduitNetwork;
|
||||
import crazypants.util.Util;
|
||||
|
||||
public class ConduitUtil {
|
||||
|
||||
@@ -76,33 +77,10 @@ public class ConduitUtil {
|
||||
}
|
||||
|
||||
public static void dropConduit(World world, IConduit conduit, int x, int y, int z) {
|
||||
dropItems(world, conduit.createItem(), x, y, z);
|
||||
Util.dropItems(world, conduit.createItem(), x, y, z);
|
||||
}
|
||||
|
||||
public static void dropItems(World world, ItemStack stack, int x, int y, int z) {
|
||||
if (stack.stackSize <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
float f1 = 0.7F;
|
||||
double d = (world.rand.nextFloat() * f1) + (1.0F - f1) * 0.5D;
|
||||
double d1 = (world.rand.nextFloat() * f1) + (1.0F - f1) * 0.5D;
|
||||
double d2 = (world.rand.nextFloat() * f1) + (1.0F - f1) * 0.5D;
|
||||
EntityItem entityitem = new EntityItem(world, x + d, y + d1, z + d2, stack);
|
||||
entityitem.delayBeforeCanPickup = 10;
|
||||
|
||||
world.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
|
||||
public static void dropItems(World world, IInventory inventory, int x, int y, int z) {
|
||||
for (int l = 0; l < inventory.getSizeInventory(); ++l) {
|
||||
ItemStack items = inventory.getStackInSlot(l);
|
||||
|
||||
if (items != null && items.stackSize > 0) {
|
||||
dropItems(world, inventory.getStackInSlot(l).copy(), x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public static boolean renderFacade(IConduitBundle bundle, EntityPlayer player) {
|
||||
return bundle.getFacadeId() > 0 && !isFacadeHidden(bundle, player);
|
||||
|
||||
@@ -2,6 +2,8 @@ package crazypants.enderio.machine;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
|
||||
import net.minecraft.block.BlockContainer;
|
||||
import net.minecraft.block.material.MapColor;
|
||||
import net.minecraft.block.material.Material;
|
||||
@@ -26,7 +28,9 @@ import crazypants.enderio.ClientProxy;
|
||||
import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.EnderIOTab;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.conduit.ConduitUtil;
|
||||
import crazypants.render.IconUtil;
|
||||
import crazypants.util.Util;
|
||||
|
||||
public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> extends BlockContainer implements IGuiHandler {
|
||||
|
||||
@@ -73,7 +77,7 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
|
||||
setHardness(2.0F);
|
||||
setStepSound(soundMetalFootstep);
|
||||
setUnlocalizedName(mo.unlocalisedName);
|
||||
setCreativeTab(EnderIOTab.tabEnderIO);
|
||||
setCreativeTab(EnderIOTab.tabEnderIO);
|
||||
random = new Random();
|
||||
|
||||
}
|
||||
@@ -102,6 +106,17 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) {
|
||||
|
||||
if (ConduitUtil.isToolEquipped(entityPlayer) && entityPlayer.isSneaking()) {
|
||||
//if (world.isRemote) {
|
||||
removeBlockByPlayer(world, entityPlayer, x, y, z);
|
||||
if (entityPlayer.getCurrentEquippedItem().getItem() instanceof IToolWrench) {
|
||||
((IToolWrench) entityPlayer.getCurrentEquippedItem().getItem()).wrenchUsed(entityPlayer, x, y, z);
|
||||
}
|
||||
//}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (entityPlayer.isSneaking()) {
|
||||
return false;
|
||||
}
|
||||
@@ -154,42 +169,32 @@ public abstract class AbstractMachineBlock<T extends AbstractMachineEntity> exte
|
||||
|
||||
@Override
|
||||
public void breakBlock(World world, int x, int y, int z, int par5, int par6) {
|
||||
TileEntity ent = world.getBlockTileEntity(x, y, z);
|
||||
if (ent != null) {
|
||||
if (teClass.isAssignableFrom(ent.getClass())) {
|
||||
@SuppressWarnings("unchecked")
|
||||
T te = (T) world.getBlockTileEntity(x, y, z);
|
||||
if (te != null) {
|
||||
dropContent(0, te, world, te.xCoord, te.yCoord, te.zCoord);
|
||||
if (!world.isRemote) {
|
||||
TileEntity ent = world.getBlockTileEntity(x, y, z);
|
||||
if (ent != null) {
|
||||
if (teClass.isAssignableFrom(ent.getClass())) {
|
||||
@SuppressWarnings("unchecked")
|
||||
T te = (T) world.getBlockTileEntity(x, y, z);
|
||||
Util.dropItems(world, te, x, y, z);
|
||||
}
|
||||
}
|
||||
ItemStack st = new ItemStack(this);
|
||||
Util.dropItems(world, st, x, y, z);
|
||||
}
|
||||
super.breakBlock(world, x, y, z, par5, par6);
|
||||
world.removeBlockTileEntity(x, y, z);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int idDropped(int par1, Random par2Random, int par3) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
public void dropContent(int newSize, T inventory, World world, int xCoord, int yCoord, int zCoord) {
|
||||
for (int i = newSize; i < inventory.getSizeInventory(); i++) {
|
||||
ItemStack itemstack = inventory.getStackInSlot(i);
|
||||
if (itemstack == null) {
|
||||
continue;
|
||||
}
|
||||
float f = random.nextFloat() * 0.8F + 0.1F;
|
||||
float f1 = random.nextFloat() * 0.8F + 0.1F;
|
||||
float f2 = random.nextFloat() * 0.8F + 0.1F;
|
||||
|
||||
EntityItem entityitem = new EntityItem(world, xCoord + f, (float) yCoord + (newSize > 0 ? 1 : 0) + f1, zCoord + f2, new ItemStack(
|
||||
itemstack.itemID, itemstack.stackSize, itemstack.getItemDamage()));
|
||||
float f3 = 0.05F;
|
||||
entityitem.motionX = (float) random.nextGaussian() * f3;
|
||||
entityitem.motionY = (float) random.nextGaussian() * f3 + 0.2F;
|
||||
entityitem.motionZ = (float) random.nextGaussian() * f3;
|
||||
if (itemstack.hasTagCompound()) {
|
||||
entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
|
||||
}
|
||||
world.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
@Override
|
||||
public int quantityDropped(Random r) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
|
||||
super.onBlockPlacedBy(world, x, y, z, player, stack);
|
||||
|
||||
@@ -3,6 +3,8 @@ package crazypants.enderio.machine.power;
|
||||
import java.text.NumberFormat;
|
||||
import java.util.Random;
|
||||
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.ITileEntityProvider;
|
||||
import net.minecraft.block.material.MapColor;
|
||||
@@ -28,6 +30,7 @@ import crazypants.enderio.EnderIO;
|
||||
import crazypants.enderio.EnderIOTab;
|
||||
import crazypants.enderio.GuiHandler;
|
||||
import crazypants.enderio.ModObject;
|
||||
import crazypants.enderio.conduit.ConduitUtil;
|
||||
import crazypants.enderio.machine.painter.PainterUtil;
|
||||
import crazypants.enderio.machine.painter.TileEntityCustomBlock;
|
||||
import crazypants.util.BlockCoord;
|
||||
@@ -63,6 +66,17 @@ public class BlockCapacitorBank extends Block implements ITileEntityProvider, IG
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) {
|
||||
|
||||
if (ConduitUtil.isToolEquipped(entityPlayer) && entityPlayer.isSneaking()) {
|
||||
//if (!world.isRemote) {
|
||||
removeBlockByPlayer(world, entityPlayer, x, y, z);
|
||||
if (entityPlayer.getCurrentEquippedItem().getItem() instanceof IToolWrench) {
|
||||
((IToolWrench) entityPlayer.getCurrentEquippedItem().getItem()).wrenchUsed(entityPlayer, x, y, z);
|
||||
}
|
||||
//}
|
||||
return true;
|
||||
}
|
||||
|
||||
if (entityPlayer.isSneaking()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
package crazypants.util;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class Util {
|
||||
|
||||
@@ -47,5 +50,30 @@ public class Util {
|
||||
return stack;
|
||||
}
|
||||
}
|
||||
|
||||
public static void dropItems(World world, ItemStack stack, int x, int y, int z) {
|
||||
if (stack.stackSize <= 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
float f1 = 0.7F;
|
||||
double d = (world.rand.nextFloat() * f1) + (1.0F - f1) * 0.5D;
|
||||
double d1 = (world.rand.nextFloat() * f1) + (1.0F - f1) * 0.5D;
|
||||
double d2 = (world.rand.nextFloat() * f1) + (1.0F - f1) * 0.5D;
|
||||
EntityItem entityitem = new EntityItem(world, x + d, y + d1, z + d2, stack);
|
||||
entityitem.delayBeforeCanPickup = 10;
|
||||
|
||||
world.spawnEntityInWorld(entityitem);
|
||||
}
|
||||
|
||||
public static void dropItems(World world, IInventory inventory, int x, int y, int z) {
|
||||
for (int l = 0; l < inventory.getSizeInventory(); ++l) {
|
||||
ItemStack items = inventory.getStackInSlot(l);
|
||||
|
||||
if (items != null && items.stackSize > 0) {
|
||||
dropItems(world, inventory.getStackInSlot(l).copy(), x, y, z);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
Reference in new issue
Block a user