Search in sources :

Example 6 with TileBPMultipart

use of com.bluepowermod.tile.TileBPMultipart in project BluePower by Qmunity.

the class BlockBPMicroblock method setPlacedBy.

@Override
public void setPlacedBy(World worldIn, BlockPos pos, BlockState state, @Nullable LivingEntity placer, ItemStack stack) {
    super.setPlacedBy(worldIn, pos, state, placer, stack);
    TileEntity tileentity = worldIn.getBlockEntity(pos);
    if (tileentity instanceof TileBPMicroblock && stack.hasTag() && stack.getTag().contains("block")) {
        // Update Microblock Type based on Stack
        Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(stack.getTag().getString("block")));
        ((TileBPMicroblock) tileentity).setBlock(block);
    } else if (tileentity instanceof TileBPMultipart && stack.hasTag() && stack.getTag().contains("block")) {
        // Update Multipart Microblock Type based on Stack
        TileBPMicroblock tile = (TileBPMicroblock) ((TileBPMultipart) tileentity).getTileForState(state);
        Block block = ForgeRegistries.BLOCKS.getValue(new ResourceLocation(stack.getTag().getString("block")));
        tile.setBlock(block);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileBPMicroblock(com.bluepowermod.tile.TileBPMicroblock) ResourceLocation(net.minecraft.util.ResourceLocation) IBPPartBlock(com.bluepowermod.api.multipart.IBPPartBlock) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart)

Example 7 with TileBPMultipart

use of com.bluepowermod.tile.TileBPMultipart in project BluePower by Qmunity.

the class BlockBPMicroblock method getDrops.

@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
    TileEntity tileentity = builder.getParameter(LootParameters.BLOCK_ENTITY);
    List<ItemStack> itemStacks = new ArrayList<>();
    if (tileentity instanceof TileBPMultipart) {
        tileentity = ((TileBPMultipart) tileentity).getTileForState(state);
    }
    if (tileentity instanceof TileBPMicroblock) {
        CompoundNBT nbt = new CompoundNBT();
        nbt.putString("block", ((TileBPMicroblock) tileentity).getBlock().getRegistryName().toString());
        ItemStack stack = new ItemStack(this);
        stack.setTag(nbt);
        stack.setHoverName(new TranslationTextComponent(((TileBPMicroblock) tileentity).getBlock().getDescriptionId()).append(new StringTextComponent(" ")).append(new TranslationTextComponent(this.getDescriptionId())));
        itemStacks.add(stack);
    }
    return itemStacks;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileBPMicroblock(com.bluepowermod.tile.TileBPMicroblock) CompoundNBT(net.minecraft.nbt.CompoundNBT) ArrayList(java.util.ArrayList) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) ItemStack(net.minecraft.item.ItemStack)

Example 8 with TileBPMultipart

use of com.bluepowermod.tile.TileBPMultipart in project BluePower by Qmunity.

the class BlockInsulatedAlloyWire method getDrops.

@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
    TileEntity tileentity = builder.getParameter(LootParameters.BLOCK_ENTITY);
    List<ItemStack> itemStacks = new ArrayList<>();
    if (tileentity instanceof TileBPMultipart) {
        tileentity = ((TileBPMultipart) tileentity).getTileForState(state);
    }
    if (tileentity instanceof TileInsulatedWire) {
        CompoundNBT nbt = new CompoundNBT();
        nbt.putString("color", ((TileInsulatedWire) tileentity).getColor().name());
        ItemStack stack = new ItemStack(this, 1, nbt);
        itemStacks.add(stack);
    }
    return itemStacks;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CompoundNBT(net.minecraft.nbt.CompoundNBT) TileInsulatedWire(com.bluepowermod.tile.tier1.TileInsulatedWire) ArrayList(java.util.ArrayList) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) ItemStack(net.minecraft.item.ItemStack)

Example 9 with TileBPMultipart

use of com.bluepowermod.tile.TileBPMultipart in project BluePower by Qmunity.

the class MultipartUtils method getClosestState.

/**
 * Returns the closest Multipart state to the Vec3 in in a given position.
 * @param world
 * @param start
 * @param end
 * @param pos
 */
@Nullable
public static BlockState getClosestState(World world, Vector3d start, Vector3d end, BlockPos pos) {
    TileEntity te = world.getBlockEntity(pos);
    BlockState state = null;
    double distance = Double.POSITIVE_INFINITY;
    if (te instanceof TileBPMultipart) {
        for (BlockState part : ((TileBPMultipart) te).getStates()) {
            RayTraceResult res = part.getVisualShape(world, pos, ISelectionContext.empty()).clip(start, end, pos);
            if (res != null) {
                double partDistance = start.distanceToSqr(res.getLocation());
                if (distance > partDistance) {
                    distance = partDistance;
                    state = part;
                }
            }
        }
    }
    return state;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) Nullable(javax.annotation.Nullable)

Example 10 with TileBPMultipart

use of com.bluepowermod.tile.TileBPMultipart in project BluePower by Qmunity.

the class BlockBPCableBase method getStateForPos.

private BlockState getStateForPos(World world, BlockPos pos, BlockState state, Direction face) {
    List<Direction> directions = new ArrayList<>(FACING.getPossibleValues());
    List<Direction> internal = null;
    boolean connected_left = false;
    boolean connected_right = false;
    boolean connected_front = false;
    boolean connected_back = false;
    boolean join_left = false;
    boolean join_right = false;
    boolean join_front = false;
    boolean join_back = false;
    // Make sure the side we are trying to connect on isn't blocked.
    TileEntity ownTile = world.getBlockEntity(pos);
    if (ownTile instanceof TileBPMultipart) {
        directions.removeIf(d -> ((TileBPMultipart) ownTile).isSideBlocked(getCapability(), d));
        internal = ((TileBPMultipart) ownTile).getStates().stream().filter(s -> s.getBlock() == this).map(s -> s.getValue(FACING)).collect(Collectors.toList());
    }
    // Make sure the cable is on the same side of the block
    directions.removeIf(d -> {
        TileEntity t = world.getBlockEntity(pos.relative(d));
        return (world.getBlockState(pos.relative(d)).getBlock() == this && world.getBlockState(pos.relative(d)).getValue(FACING) != face) || (t instanceof TileBPMultipart && ((TileBPMultipart) t).getStates().stream().noneMatch(s -> s.getValue(FACING) == face));
    });
    // Populate all directions
    for (Direction d : directions) {
        TileEntity tileEntity = world.getBlockEntity(pos.relative(d));
        BlockState dirState = world.getBlockState(pos.relative(d));
        BlockPos dirPos = pos.relative(d);
        boolean join = false;
        // If Air look for a change in Direction
        if (world.getBlockState(pos.relative(d)).getBlock() == Blocks.AIR) {
            dirState = world.getBlockState(pos.relative(d).relative(face.getOpposite()));
            dirPos = pos.relative(d).relative(face.getOpposite());
            if (dirState.getBlock() == this && dirState.getValue(FACING) == d) {
                tileEntity = world.getBlockEntity(pos.relative(d).relative(face.getOpposite()));
                join = true;
            } else if (dirState.getBlock() instanceof BlockBPMultipart) {
                tileEntity = world.getBlockEntity(pos.relative(d).relative(face.getOpposite()));
                if (tileEntity instanceof TileBPMultipart && ((TileBPMultipart) tileEntity).getStates().stream().filter(s -> s.getBlock() == this).anyMatch(s -> s.getValue(FACING) == d)) {
                    join = true;
                } else {
                    tileEntity = null;
                }
            }
        }
        // Check Capability for Direction
        switch(state.getValue(FACING)) {
            case UP:
            case DOWN:
                switch(d) {
                    case EAST:
                        connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case WEST:
                        connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case NORTH:
                        connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case SOUTH:
                        connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                }
                break;
            case NORTH:
                switch(d) {
                    case WEST:
                        connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case EAST:
                        connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case UP:
                        connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case DOWN:
                        connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                }
                break;
            case SOUTH:
                switch(d) {
                    case EAST:
                        connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case WEST:
                        connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case UP:
                        connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case DOWN:
                        connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                }
                break;
            case EAST:
                switch(d) {
                    case NORTH:
                        connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case SOUTH:
                        connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case UP:
                        connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case DOWN:
                        connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                }
                break;
            case WEST:
                switch(d) {
                    case SOUTH:
                        connected_right = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_right = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case NORTH:
                        connected_left = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_left = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case UP:
                        connected_front = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_front = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                    case DOWN:
                        connected_back = canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        join_back = join && canConnect(world, dirPos, dirState, tileEntity, d.getOpposite());
                        break;
                }
        }
    }
    if (internal != null)
        for (Direction d : internal) {
            switch(state.getValue(FACING)) {
                case UP:
                case DOWN:
                    switch(d) {
                        case EAST:
                            connected_left = true;
                            break;
                        case WEST:
                            connected_right = true;
                            break;
                        case NORTH:
                            connected_back = true;
                            break;
                        case SOUTH:
                            connected_front = true;
                            break;
                    }
                    break;
                case NORTH:
                    switch(d) {
                        case WEST:
                            connected_left = true;
                            break;
                        case EAST:
                            connected_right = true;
                            break;
                        case UP:
                            connected_back = true;
                            break;
                        case DOWN:
                            connected_front = true;
                            break;
                    }
                    break;
                case SOUTH:
                    switch(d) {
                        case EAST:
                            connected_left = true;
                            break;
                        case WEST:
                            connected_right = true;
                            break;
                        case UP:
                            connected_back = true;
                            break;
                        case DOWN:
                            connected_front = true;
                            break;
                    }
                    break;
                case EAST:
                    switch(d) {
                        case NORTH:
                            connected_left = true;
                            break;
                        case SOUTH:
                            connected_right = true;
                            break;
                        case UP:
                            connected_back = true;
                            break;
                        case DOWN:
                            connected_front = true;
                            break;
                    }
                    break;
                case WEST:
                    switch(d) {
                        case SOUTH:
                            connected_left = true;
                            break;
                        case NORTH:
                            connected_right = true;
                            break;
                        case UP:
                            connected_back = true;
                            break;
                        case DOWN:
                            connected_front = true;
                            break;
                    }
            }
        }
    FluidState fluidstate = world.getFluidState(pos);
    return state.setValue(CONNECTED_LEFT, connected_left).setValue(CONNECTED_RIGHT, connected_right).setValue(CONNECTED_FRONT, connected_front).setValue(CONNECTED_BACK, connected_back).setValue(JOIN_LEFT, join_left).setValue(JOIN_RIGHT, join_right).setValue(JOIN_FRONT, join_front).setValue(JOIN_BACK, join_back).setValue(WATERLOGGED, fluidstate.getType() == Fluids.WATER);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) FluidState(net.minecraft.fluid.FluidState) IWorld(net.minecraft.world.IWorld) Direction(net.minecraft.util.Direction) IWorldReader(net.minecraft.world.IWorldReader) ArrayList(java.util.ArrayList) ItemStack(net.minecraft.item.ItemStack) StateContainer(net.minecraft.state.StateContainer) IBlockReader(net.minecraft.world.IBlockReader) net.minecraft.block(net.minecraft.block) ISelectionContext(net.minecraft.util.math.shapes.ISelectionContext) VoxelShape(net.minecraft.util.math.shapes.VoxelShape) Nullable(javax.annotation.Nullable) Fluids(net.minecraft.fluid.Fluids) BooleanProperty(net.minecraft.state.BooleanProperty) LivingEntity(net.minecraft.entity.LivingEntity) World(net.minecraft.world.World) BlockPos(net.minecraft.util.math.BlockPos) BlockItemUseContext(net.minecraft.item.BlockItemUseContext) Collectors(java.util.stream.Collectors) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) Capability(net.minecraftforge.common.capabilities.Capability) AABBUtils(com.bluepowermod.util.AABBUtils) List(java.util.List) IBPPartBlock(com.bluepowermod.api.multipart.IBPPartBlock) Material(net.minecraft.block.material.Material) TileEntity(net.minecraft.tileentity.TileEntity) VoxelShapes(net.minecraft.util.math.shapes.VoxelShapes) DirectionProperty(net.minecraft.state.DirectionProperty) BlockStateProperties(net.minecraft.state.properties.BlockStateProperties) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) Direction(net.minecraft.util.Direction) FluidState(net.minecraft.fluid.FluidState)

Aggregations

TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)12 TileEntity (net.minecraft.tileentity.TileEntity)12 ItemStack (net.minecraft.item.ItemStack)6 ArrayList (java.util.ArrayList)5 CompoundNBT (net.minecraft.nbt.CompoundNBT)5 IBPPartBlock (com.bluepowermod.api.multipart.IBPPartBlock)4 TileBPMicroblock (com.bluepowermod.tile.TileBPMicroblock)3 TileInsulatedWire (com.bluepowermod.tile.tier1.TileInsulatedWire)2 Nullable (javax.annotation.Nullable)2 BlockState (net.minecraft.block.BlockState)2 Direction (net.minecraft.util.Direction)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 BlockBPMultipart (com.bluepowermod.block.BlockBPMultipart)1 AABBUtils (com.bluepowermod.util.AABBUtils)1 List (java.util.List)1 Collectors (java.util.stream.Collectors)1 net.minecraft.block (net.minecraft.block)1 Material (net.minecraft.block.material.Material)1 LivingEntity (net.minecraft.entity.LivingEntity)1