Search in sources :

Example 1 with TileBPMicroblock

use of com.bluepowermod.tile.TileBPMicroblock 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 2 with TileBPMicroblock

use of com.bluepowermod.tile.TileBPMicroblock 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 3 with TileBPMicroblock

use of com.bluepowermod.tile.TileBPMicroblock 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)

Aggregations

TileBPMicroblock (com.bluepowermod.tile.TileBPMicroblock)3 TileBPMultipart (com.bluepowermod.tile.TileBPMultipart)3 TileEntity (net.minecraft.tileentity.TileEntity)3 ItemStack (net.minecraft.item.ItemStack)2 CompoundNBT (net.minecraft.nbt.CompoundNBT)2 StringTextComponent (net.minecraft.util.text.StringTextComponent)2 TranslationTextComponent (net.minecraft.util.text.TranslationTextComponent)2 IBPPartBlock (com.bluepowermod.api.multipart.IBPPartBlock)1 ArrayList (java.util.ArrayList)1 ResourceLocation (net.minecraft.util.ResourceLocation)1