use of blusunrize.immersiveengineering.common.blocks.metal.TileEntityFeedthrough in project ImmersiveEngineering by BluSunrize.
the class FeedthroughModel method getQuads.
@Nonnull
@Override
public List<BakedQuad> getQuads(@Nullable IBlockState state, @Nullable EnumFacing side, long rand) {
IBlockState baseState = Blocks.STONE.getDefaultState();
WireType wire = WireType.COPPER;
EnumFacing facing = EnumFacing.NORTH;
int offset = 1;
BlockPos p = null;
World w = null;
if (state instanceof IExtendedBlockState) {
TileEntity te = ((IExtendedBlockState) state).getValue(IEProperties.TILEENTITY_PASSTHROUGH);
if (te instanceof TileEntityFeedthrough) {
baseState = ((TileEntityFeedthrough) te).stateForMiddle;
wire = ((TileEntityFeedthrough) te).reference;
facing = ((TileEntityFeedthrough) te).getFacing();
offset = ((TileEntityFeedthrough) te).offset;
p = te.getPos();
w = te.getWorld();
}
}
final BlockPos pFinal = p;
final World wFinal = w;
FeedthroughCacheKey key = new FeedthroughCacheKey(wire, baseState, offset, facing, MinecraftForgeClient.getRenderLayer());
try {
return CACHE.get(key, () -> new SpecificFeedthroughModel(key, wFinal, pFinal)).getQuads(state, side, rand);
} catch (ExecutionException e) {
e.printStackTrace();
return ImmutableList.of();
}
}
use of blusunrize.immersiveengineering.common.blocks.metal.TileEntityFeedthrough in project ImmersiveEngineering by BluSunrize.
the class MultiblockFeedthrough method setBlock.
@Nullable
private TileEntityFeedthrough setBlock(World world, BlockPos here, IBlockState newState, WireType wire, IBlockState middle, int offset) {
world.setBlockState(here, newState);
TileEntity te = world.getTileEntity(here);
if (te instanceof TileEntityFeedthrough) {
TileEntityFeedthrough feedthrough = (TileEntityFeedthrough) te;
feedthrough.reference = wire;
feedthrough.stateForMiddle = middle;
feedthrough.offset = offset;
world.checkLight(here);
world.addBlockEvent(here, feedthrough.getBlockType(), 253, 0);
return feedthrough;
}
return null;
}
use of blusunrize.immersiveengineering.common.blocks.metal.TileEntityFeedthrough in project ImmersiveEngineering by BluSunrize.
the class MultiblockFeedthrough method createStructure.
@Override
public boolean createStructure(World world, BlockPos pos, EnumFacing side, EntityPlayer player) {
// Check
IBlockState stateHere = world.getBlockState(pos).getActualState(world, pos);
if (stateHere.getPropertyKeys().contains(IEProperties.FACING_ALL))
side = stateHere.getValue(IEProperties.FACING_ALL);
Set<ImmersiveNetHandler.Connection> connHere = ImmersiveNetHandler.INSTANCE.getConnections(world, pos);
if (connHere == null)
connHere = ImmutableSet.of();
if (connHere.size() > 1)
return false;
WireType wire = WireApi.getWireType(stateHere);
if (// This shouldn't ever happen
wire == null)
return false;
BlockPos middlePos = pos.offset(side);
IBlockState middle = world.getBlockState(middlePos).getActualState(world, middlePos);
if (!middle.isFullCube() || middle.getBlock().hasTileEntity(middle) || middle.getRenderType() != EnumBlockRenderType.MODEL)
return false;
BlockPos otherPos = pos.offset(side, 2);
IBlockState otherConn = world.getBlockState(otherPos).getActualState(world, otherPos);
if (WireApi.getWireType(otherConn) != wire)
return false;
if (otherConn.getValue(IEProperties.FACING_ALL) != side.getOpposite())
return false;
Set<ImmersiveNetHandler.Connection> connOther = ImmersiveNetHandler.INSTANCE.getConnections(world, otherPos);
if (connOther == null)
connOther = ImmutableSet.of();
if (connOther.size() > 1)
return false;
if (connOther.stream().anyMatch(c -> c.end.equals(pos)))
return false;
for (Connection c : connOther) if (connHere.stream().anyMatch(c2 -> c2.end.equals(c.end)))
return false;
ItemStack hammer = player.getHeldItemMainhand().getItem().getToolClasses(player.getHeldItemMainhand()).contains(Lib.TOOL_HAMMER) ? player.getHeldItemMainhand() : player.getHeldItemOffhand();
if (MultiblockHandler.fireMultiblockFormationEventPost(player, this, pos, hammer).isCanceled())
return false;
// Form
if (!world.isRemote) {
IBlockState state = IEContent.blockConnectors.getDefaultState().withProperty(IEContent.blockConnectors.property, BlockTypes_Connector.FEEDTHROUGH).withProperty(IEProperties.FACING_ALL, side);
BlockPos masterPos = pos.offset(side);
TileEntityFeedthrough master = setBlock(world, masterPos, state, wire, middle, 0);
if (master != null) {
moveConnectionsToMaster(connOther, world, true, master);
moveConnectionsToMaster(connHere, world, false, master);
master.markContainingBlockForUpdate(null);
}
setBlock(world, pos, state, wire, middle, -1);
setBlock(world, pos.offset(side, 2), state, wire, middle, 1);
}
return true;
}
Aggregations