Search in sources :

Example 1 with TileBPMultipart

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

the class BlockInsulatedAlloyWire method getCloneItemStack.

@Override
public ItemStack getCloneItemStack(IBlockReader world, BlockPos pos, BlockState state) {
    TileEntity tileentity = world.getBlockEntity(pos);
    ItemStack stack = ItemStack.EMPTY;
    if (tileentity instanceof TileBPMultipart) {
        tileentity = ((TileBPMultipart) tileentity).getTileForState(state);
    }
    if (tileentity instanceof TileInsulatedWire) {
        CompoundNBT nbt = new CompoundNBT();
        nbt.putString("color", ((TileInsulatedWire) tileentity).getColor().name());
        stack = new ItemStack(this, 1, nbt);
    }
    return stack;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CompoundNBT(net.minecraft.nbt.CompoundNBT) TileInsulatedWire(com.bluepowermod.tile.tier1.TileInsulatedWire) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) ItemStack(net.minecraft.item.ItemStack)

Example 2 with TileBPMultipart

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

the class BlockBPMicroblock method getCloneItemStack.

@Override
public ItemStack getCloneItemStack(IBlockReader world, BlockPos pos, BlockState state) {
    TileEntity tileentity = world.getBlockEntity(pos);
    ItemStack stack = ItemStack.EMPTY;
    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());
        stack = new ItemStack(this);
        stack.setTag(nbt);
        stack.setHoverName(new TranslationTextComponent(((TileBPMicroblock) tileentity).getBlock().getDescriptionId()).append(new StringTextComponent(" ")).append(new TranslationTextComponent(this.getDescriptionId())));
    }
    return stack;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileBPMicroblock(com.bluepowermod.tile.TileBPMicroblock) CompoundNBT(net.minecraft.nbt.CompoundNBT) TranslationTextComponent(net.minecraft.util.text.TranslationTextComponent) StringTextComponent(net.minecraft.util.text.StringTextComponent) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) ItemStack(net.minecraft.item.ItemStack)

Example 3 with TileBPMultipart

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

the class BlockBPCableBase method neighborChanged.

@Override
public void neighborChanged(BlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos, boolean bool) {
    TileEntity te = world.getBlockEntity(pos);
    // Get new state based on surrounding capabilities
    BlockState newState = getStateForPos(world, pos, defaultBlockState().setValue(FACING, state.getValue(FACING)), state.getValue(FACING));
    if (!(te instanceof TileBPMultipart)) {
        // Change the block state
        world.setBlock(pos, newState, 2);
    } else {
        // Update the state in the Multipart
        ((TileBPMultipart) te).changeState(state, newState);
    }
    state = newState;
    // If not placed on a solid block break off
    if (!world.getBlockState(pos.relative(state.getValue(FACING).getOpposite())).canOcclude()) {
        if (te instanceof TileBPMultipart) {
            ((TileBPMultipart) te).removeState(state);
        } else {
            world.destroyBlock(pos, true);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart)

Example 4 with TileBPMultipart

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

the class BlockBPMultipart method getShape.

@Override
public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
    TileEntity te = worldIn.getBlockEntity(pos);
    if (te instanceof TileBPMultipart) {
        List<VoxelShape> shapeList = new ArrayList<>();
        ((TileBPMultipart) te).getStates().forEach(s -> shapeList.add(s.getShape(worldIn, pos)));
        if (shapeList.size() > 0)
            return shapeList.stream().reduce(shapeList.get(0), VoxelShapes::or);
    }
    // Shouldn't be required but allows the player to break an empty multipart
    return Block.box(6, 6, 6, 10, 10, 10);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ArrayList(java.util.ArrayList) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart)

Example 5 with TileBPMultipart

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

the class ItemBPPart method place.

@Override
public ActionResultType place(BlockItemUseContext context) {
    BlockState state = context.getLevel().getBlockState(context.getClickedPos());
    BlockState thisState = getBlock().getStateForPlacement(context);
    if (state.getBlock() instanceof IBPPartBlock && thisState != null && !AABBUtils.testOcclusion(((IBPPartBlock) thisState.getBlock()).getOcclusionShape(thisState), state.getShape(context.getLevel(), context.getClickedPos()))) {
        // Save the Tile Entity Data
        CompoundNBT nbt = new CompoundNBT();
        TileEntity tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
        if (tileEntity != null) {
            nbt = tileEntity.save(nbt);
        }
        // Replace with Multipart
        context.getLevel().setBlockAndUpdate(context.getClickedPos(), BPBlocks.multipart.defaultBlockState());
        tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
        if (tileEntity instanceof TileBPMultipart) {
            // Add the original State to the Multipart
            ((TileBPMultipart) tileEntity).addState(state);
            // Restore the Tile Entity Data
            TileEntity tile = ((TileBPMultipart) tileEntity).getTileForState(state);
            if (tile != null)
                tile.load(state, nbt);
            // Add the new State
            ((TileBPMultipart) tileEntity).addState(thisState);
            thisState.getBlock().setPlacedBy(context.getLevel(), context.getClickedPos(), thisState, context.getPlayer(), context.getItemInHand());
        }
        // Update Self
        state.neighborChanged(context.getLevel(), context.getClickedPos(), state.getBlock(), context.getClickedPos(), false);
        context.getItemInHand().shrink(1);
        // Place Sound
        context.getLevel().playSound(null, context.getClickedPos(), SoundEvents.STONE_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
        return ActionResultType.SUCCESS;
    } else if (state.getBlock() instanceof BlockBPMultipart && thisState != null && !AABBUtils.testOcclusion(((IBPPartBlock) thisState.getBlock()).getOcclusionShape(thisState), state.getShape(context.getLevel(), context.getClickedPos()))) {
        // Add to the Existing Multipart
        TileEntity tileEntity = context.getLevel().getBlockEntity(context.getClickedPos());
        if (tileEntity instanceof TileBPMultipart) {
            ((TileBPMultipart) tileEntity).addState(thisState);
            thisState.getBlock().setPlacedBy(context.getLevel(), context.getClickedPos(), thisState, context.getPlayer(), context.getItemInHand());
            // Update Neighbors
            for (Direction dir : Direction.values()) {
                context.getLevel().getBlockState(context.getClickedPos().relative(dir)).neighborChanged(context.getLevel(), context.getClickedPos().relative(dir), state.getBlock(), context.getClickedPos(), false);
            }
            // Update Self
            state.neighborChanged(context.getLevel(), context.getClickedPos(), state.getBlock(), context.getClickedPos(), false);
            context.getItemInHand().shrink(1);
            // Place Sound
            context.getLevel().playSound(null, context.getClickedPos(), SoundEvents.STONE_PLACE, SoundCategory.BLOCKS, 1.0F, 1.0F);
            return ActionResultType.SUCCESS;
        }
    }
    return super.place(context);
}
Also used : IBPPartBlock(com.bluepowermod.api.multipart.IBPPartBlock) TileEntity(net.minecraft.tileentity.TileEntity) BlockState(net.minecraft.block.BlockState) CompoundNBT(net.minecraft.nbt.CompoundNBT) BlockBPMultipart(com.bluepowermod.block.BlockBPMultipart) TileBPMultipart(com.bluepowermod.tile.TileBPMultipart) Direction(net.minecraft.util.Direction)

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