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;
}
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;
}
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);
}
}
}
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);
}
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);
}
Aggregations