Search in sources :

Example 1 with TileEntityFeedthrough

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();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) EnumFacing(net.minecraft.util.EnumFacing) TileEntityFeedthrough(blusunrize.immersiveengineering.common.blocks.metal.TileEntityFeedthrough) BlockPos(net.minecraft.util.math.BlockPos) WireType(blusunrize.immersiveengineering.api.energy.wires.WireType) World(net.minecraft.world.World) ExecutionException(java.util.concurrent.ExecutionException) Nonnull(javax.annotation.Nonnull)

Example 2 with TileEntityFeedthrough

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;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFeedthrough(blusunrize.immersiveengineering.common.blocks.metal.TileEntityFeedthrough) Nullable(javax.annotation.Nullable)

Example 3 with TileEntityFeedthrough

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;
}
Also used : IEContent(blusunrize.immersiveengineering.common.IEContent) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) Blocks(net.minecraft.init.Blocks) MultiblockHandler(blusunrize.immersiveengineering.api.MultiblockHandler) ImmersiveNetHandler(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler) ClientUtils(blusunrize.immersiveengineering.client.ClientUtils) IngredientStack(blusunrize.immersiveengineering.api.crafting.IngredientStack) ItemStack(net.minecraft.item.ItemStack) BlockTypes_Connector(blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_Connector) Side(net.minecraftforge.fml.relauncher.Side) Lib(blusunrize.immersiveengineering.api.Lib) ItemCameraTransforms(net.minecraft.client.renderer.block.model.ItemCameraTransforms) TileEntityFeedthrough(blusunrize.immersiveengineering.common.blocks.metal.TileEntityFeedthrough) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) IEProperties(blusunrize.immersiveengineering.api.IEProperties) Nullable(javax.annotation.Nullable) ImmutableSet(com.google.common.collect.ImmutableSet) World(net.minecraft.world.World) GlStateManager(net.minecraft.client.renderer.GlStateManager) Collection(java.util.Collection) EnumFacing(net.minecraft.util.EnumFacing) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) WireApi(blusunrize.immersiveengineering.api.energy.wires.WireApi) IBlockState(net.minecraft.block.state.IBlockState) EntityPlayer(net.minecraft.entity.player.EntityPlayer) WireType(blusunrize.immersiveengineering.api.energy.wires.WireType) ApiUtils(blusunrize.immersiveengineering.api.ApiUtils) TileEntity(net.minecraft.tileentity.TileEntity) EnumBlockRenderType(net.minecraft.util.EnumBlockRenderType) IMultiblock(blusunrize.immersiveengineering.api.MultiblockHandler.IMultiblock) IBlockState(net.minecraft.block.state.IBlockState) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) TileEntityFeedthrough(blusunrize.immersiveengineering.common.blocks.metal.TileEntityFeedthrough) BlockPos(net.minecraft.util.math.BlockPos) WireType(blusunrize.immersiveengineering.api.energy.wires.WireType) ItemStack(net.minecraft.item.ItemStack)

Aggregations

TileEntityFeedthrough (blusunrize.immersiveengineering.common.blocks.metal.TileEntityFeedthrough)3 TileEntity (net.minecraft.tileentity.TileEntity)3 WireType (blusunrize.immersiveengineering.api.energy.wires.WireType)2 Nullable (javax.annotation.Nullable)2 IBlockState (net.minecraft.block.state.IBlockState)2 EnumFacing (net.minecraft.util.EnumFacing)2 BlockPos (net.minecraft.util.math.BlockPos)2 World (net.minecraft.world.World)2 ApiUtils (blusunrize.immersiveengineering.api.ApiUtils)1 IEProperties (blusunrize.immersiveengineering.api.IEProperties)1 Lib (blusunrize.immersiveengineering.api.Lib)1 MultiblockHandler (blusunrize.immersiveengineering.api.MultiblockHandler)1 IMultiblock (blusunrize.immersiveengineering.api.MultiblockHandler.IMultiblock)1 IngredientStack (blusunrize.immersiveengineering.api.crafting.IngredientStack)1 ImmersiveNetHandler (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler)1 Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)1 WireApi (blusunrize.immersiveengineering.api.energy.wires.WireApi)1 ClientUtils (blusunrize.immersiveengineering.client.ClientUtils)1 IEContent (blusunrize.immersiveengineering.common.IEContent)1 BlockTypes_Connector (blusunrize.immersiveengineering.common.blocks.metal.BlockTypes_Connector)1