Skip to content

Instantly share code, notes, and snippets.

@artillect
Created November 27, 2016 20:56
Show Gist options
  • Save artillect/a4ab6f792b12aa583fc7da2366f23a68 to your computer and use it in GitHub Desktop.
Save artillect/a4ab6f792b12aa583fc7da2366f23a68 to your computer and use it in GitHub Desktop.
package com.artillect.voltaics.block;
import com.artillect.voltaics.tileentity.TileEntityLowVoltageConduit;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class BlockLowVoltageConduit extends BlockTEBase{
public BlockLowVoltageConduit(Material material, String name, boolean addToTab) {
super(material, name, addToTab);
}
@Override
public EnumBlockRenderType getRenderType(IBlockState state)
{
return EnumBlockRenderType.INVISIBLE;
}
@Override
public void onNeighborChange(IBlockAccess world, BlockPos pos, BlockPos neighbor){
if (world.getTileEntity(pos) != null){
((TileEntityLowVoltageConduit)world.getTileEntity(pos)).updateNeighbors(world);
}
}
@Override
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block block){
if (world.getTileEntity(pos) != null){
((TileEntityLowVoltageConduit)world.getTileEntity(pos)).updateNeighbors(world);
world.notifyBlockUpdate(pos, state, world.getBlockState(pos), 3);
}
}
@Override
public void onBlockAdded(World world, BlockPos pos, IBlockState state){
if (world.getTileEntity(pos) != null){
((TileEntityLowVoltageConduit)world.getTileEntity(pos)).updateNeighbors(world);
}
}
@Override
public AxisAlignedBB getBoundingBox(IBlockState state, IBlockAccess source, BlockPos pos){
double x1 = 0.375;
double y1 = 0.375;
double z1 = 0.375;
double x2 = 0.625;
double y2 = 0.625;
double z2 = 0.625;
if (source.getTileEntity(pos) instanceof TileEntityLowVoltageConduit){
TileEntityLowVoltageConduit pipe = ((TileEntityLowVoltageConduit)source.getTileEntity(pos));
if (pipe.up != TileEntityLowVoltageConduit.EnumPipeConnection.NONE){
y2 = 1;
}
if (pipe.down != TileEntityLowVoltageConduit.EnumPipeConnection.NONE){
y1 = 0;
}
if (pipe.north != TileEntityLowVoltageConduit.EnumPipeConnection.NONE){
z1 = 0;
}
if (pipe.south != TileEntityLowVoltageConduit.EnumPipeConnection.NONE){
z2 = 1;
}
if (pipe.west != TileEntityLowVoltageConduit.EnumPipeConnection.NONE){
x1 = 0;
}
if (pipe.east != TileEntityLowVoltageConduit.EnumPipeConnection.NONE){
x2 = 1;
}
}
return new AxisAlignedBB(x1,y1,z1,x2,y2,z2);
}
@Override
public void onBlockHarvested(World world, BlockPos pos, IBlockState state, EntityPlayer player){
super.onBlockHarvested(world, pos, state, player);
if (world.getTileEntity(pos.up()) instanceof TileEntityLowVoltageConduit){
((TileEntityLowVoltageConduit)world.getTileEntity(pos.up())).updateNeighbors(world);
}
if (world.getTileEntity(pos.down()) instanceof TileEntityLowVoltageConduit){
((TileEntityLowVoltageConduit)world.getTileEntity(pos.down())).updateNeighbors(world);
}
if (world.getTileEntity(pos.north()) instanceof TileEntityLowVoltageConduit){
((TileEntityLowVoltageConduit)world.getTileEntity(pos.north())).updateNeighbors(world);
}
if (world.getTileEntity(pos.south()) instanceof TileEntityLowVoltageConduit){
((TileEntityLowVoltageConduit)world.getTileEntity(pos.south())).updateNeighbors(world);
}
if (world.getTileEntity(pos.west()) instanceof TileEntityLowVoltageConduit){
((TileEntityLowVoltageConduit)world.getTileEntity(pos.west())).updateNeighbors(world);
}
if (world.getTileEntity(pos.east()) instanceof TileEntityLowVoltageConduit){
((TileEntityLowVoltageConduit)world.getTileEntity(pos.east())).updateNeighbors(world);
}
}
@Override
public TileEntity createNewTileEntity(World worldIn, int meta) {
return new TileEntityLowVoltageConduit();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment