2021-04-17 16:07:41 +02:00
|
|
|
package ley.modding.dartcraft.block;
|
|
|
|
|
|
|
|
import cpw.mods.fml.relauncher.Side;
|
|
|
|
import cpw.mods.fml.relauncher.SideOnly;
|
|
|
|
import ley.modding.dartcraft.Dartcraft;
|
|
|
|
import ley.modding.dartcraft.tile.TileEntityForceEngine;
|
|
|
|
import ley.modding.dartcraft.util.DartUtils;
|
2024-04-20 16:19:19 +02:00
|
|
|
import ley.modding.dartcraft.util.FXUtils;
|
2021-04-17 16:07:41 +02:00
|
|
|
import ley.modding.tileralib.api.ITEProvider;
|
|
|
|
import net.minecraft.block.Block;
|
|
|
|
import net.minecraft.block.BlockContainer;
|
|
|
|
import net.minecraft.block.material.Material;
|
|
|
|
import net.minecraft.client.particle.EffectRenderer;
|
|
|
|
import net.minecraft.entity.EntityLivingBase;
|
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.tileentity.TileEntity;
|
|
|
|
import net.minecraft.util.MovingObjectPosition;
|
|
|
|
import net.minecraft.world.IBlockAccess;
|
|
|
|
import net.minecraft.world.World;
|
|
|
|
import net.minecraftforge.common.util.ForgeDirection;
|
|
|
|
import net.minecraftforge.fluids.FluidContainerRegistry;
|
|
|
|
|
|
|
|
public class BlockForceEngine extends BlockContainer implements ITEProvider {
|
|
|
|
public BlockForceEngine() {
|
|
|
|
super(Material.iron);
|
|
|
|
setHardness(3.0F);
|
|
|
|
setResistance(50.0F);
|
|
|
|
setCreativeTab(Dartcraft.tab);
|
|
|
|
setBlockName("forceengine");
|
|
|
|
}
|
|
|
|
|
|
|
|
public TileEntity createNewTileEntity(World world, int var2) {
|
|
|
|
return new TileEntityForceEngine();
|
|
|
|
}
|
|
|
|
|
2024-04-13 18:27:31 +02:00
|
|
|
public boolean onBlockActivated(
|
|
|
|
World world,
|
|
|
|
int x,
|
|
|
|
int y,
|
|
|
|
int z,
|
|
|
|
EntityPlayer player,
|
|
|
|
int par6,
|
|
|
|
float par7,
|
|
|
|
float par8,
|
|
|
|
float par9
|
|
|
|
) {
|
|
|
|
if (!Dartcraft.proxy.isSimulating(world)) {
|
2021-04-17 16:07:41 +02:00
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
TileEntity tile = world.getTileEntity(x, y, z);
|
|
|
|
TileEntityForceEngine engine = null;
|
2024-04-13 18:27:31 +02:00
|
|
|
if (tile instanceof TileEntityForceEngine) {
|
|
|
|
engine = (TileEntityForceEngine) tile;
|
2021-04-17 16:07:41 +02:00
|
|
|
}
|
|
|
|
|
2024-04-13 18:27:31 +02:00
|
|
|
if (engine != null) {
|
|
|
|
if (DartUtils.isHoldingWrench(player)) {
|
2021-04-17 16:07:41 +02:00
|
|
|
engine.rotateBlock();
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-04-13 18:27:31 +02:00
|
|
|
if (player.getCurrentEquippedItem() != null
|
|
|
|
&& FluidContainerRegistry.getFluidForFilledItem(
|
|
|
|
player.getCurrentEquippedItem()
|
|
|
|
) != null) {
|
2021-04-17 16:07:41 +02:00
|
|
|
return DartUtils.fillTankWithContainer(engine, player);
|
|
|
|
}
|
|
|
|
|
2024-04-13 18:27:31 +02:00
|
|
|
if (!player.isSneaking() && !DartUtils.isHoldingWrench(player)) {
|
2021-04-17 16:07:41 +02:00
|
|
|
player.openGui(Dartcraft.instance, 7, world, x, y, z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-04-13 18:27:31 +02:00
|
|
|
public void onBlockPlacedBy(
|
|
|
|
World world, int x, int y, int z, EntityLivingBase living, ItemStack stack
|
|
|
|
) {
|
|
|
|
TileEntityForceEngine tile = (TileEntityForceEngine) world.getTileEntity(x, y, z);
|
|
|
|
if (tile != null) {
|
2021-04-17 16:07:41 +02:00
|
|
|
tile.setFacing(ForgeDirection.UP);
|
|
|
|
tile.rotateBlock();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
public int getLightValue(IBlockAccess world, int x, int y, int z) {
|
|
|
|
TileEntity te = world.getTileEntity(x, y, z);
|
2024-04-13 18:27:31 +02:00
|
|
|
return te instanceof TileEntityForceEngine
|
|
|
|
? ((TileEntityForceEngine) te).getLightValue()
|
|
|
|
: 0;
|
2021-04-17 16:07:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public int getRenderType() {
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean isOpaqueCube() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public boolean renderAsNormalBlock() {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
public void breakBlock(World world, int x, int y, int z, Block par5, int par6) {
|
2024-04-13 18:27:31 +02:00
|
|
|
if (Dartcraft.proxy.isSimulating(world)) {
|
2021-04-17 16:07:41 +02:00
|
|
|
TileEntity tile = world.getTileEntity(x, y, z);
|
2024-04-13 18:27:31 +02:00
|
|
|
if (tile instanceof TileEntityForceEngine) {
|
|
|
|
TileEntityForceEngine engine = (TileEntityForceEngine) tile;
|
2021-04-17 16:07:41 +02:00
|
|
|
|
2024-04-13 18:27:31 +02:00
|
|
|
for (int i = 0; i < engine.liquidInventory.getSizeInventory(); ++i) {
|
2021-04-17 16:07:41 +02:00
|
|
|
ItemStack tempStack = engine.liquidInventory.getStackInSlot(i);
|
2024-04-13 18:27:31 +02:00
|
|
|
if (tempStack != null) {
|
2021-04-17 16:07:41 +02:00
|
|
|
DartUtils.dropItem(tempStack, world, x, y, z);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
super.breakBlock(world, x, y, z, par5, par6);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2024-04-13 18:27:31 +02:00
|
|
|
public boolean
|
|
|
|
isSideSolid(IBlockAccess world, int x, int y, int z, ForgeDirection side) {
|
2021-04-17 16:07:41 +02:00
|
|
|
TileEntity tile = world.getTileEntity(x, y, z);
|
2024-04-13 18:27:31 +02:00
|
|
|
return tile instanceof TileEntityForceEngine
|
|
|
|
? ((TileEntityForceEngine) tile).facing.getOpposite() == side
|
|
|
|
: false;
|
2021-04-17 16:07:41 +02:00
|
|
|
}
|
|
|
|
|
2024-04-20 16:19:19 +02:00
|
|
|
@Override
|
2021-04-17 16:07:41 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2024-04-13 18:27:31 +02:00
|
|
|
public boolean addDestroyEffects(
|
|
|
|
World world, int x, int y, int z, int meta, EffectRenderer renderer
|
|
|
|
) {
|
2024-04-20 16:19:19 +02:00
|
|
|
FXUtils.makeShiny(
|
|
|
|
world,
|
|
|
|
(double) x,
|
|
|
|
(double) y,
|
|
|
|
(double) z,
|
|
|
|
2,
|
|
|
|
BaseBlock.DEFAULT_COLOR,
|
|
|
|
32,
|
|
|
|
true
|
|
|
|
);
|
2021-04-17 16:07:41 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2024-04-20 16:19:19 +02:00
|
|
|
@Override
|
2021-04-17 16:07:41 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
2024-04-13 18:27:31 +02:00
|
|
|
public boolean
|
|
|
|
addHitEffects(World world, MovingObjectPosition target, EffectRenderer renderer) {
|
2024-04-20 16:19:19 +02:00
|
|
|
FXUtils.makeShiny(
|
|
|
|
world,
|
|
|
|
(double) target.blockX,
|
|
|
|
(double) target.blockY,
|
|
|
|
(double) target.blockZ,
|
|
|
|
2,
|
|
|
|
BaseBlock.DEFAULT_COLOR,
|
|
|
|
4,
|
|
|
|
true
|
|
|
|
);
|
2021-04-17 16:07:41 +02:00
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Class<? extends TileEntity> getTEClass() {
|
|
|
|
return TileEntityForceEngine.class;
|
|
|
|
}
|
|
|
|
}
|