User Tools

Site Tools


tutorial:containers

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
tutorial:containers [2020/02/27 16:34]
mkpoli adjusment
tutorial:containers [2020/04/02 12:57] (current)
earthcomputer [Block and BlockItem] Revert BlockWithEntity change
Line 10: Line 10:
         super(settings);​         super(settings);​
     }     }
- +    ​ 
-    // We need to explicitly return a MODEL render type because BlockWithEntity has a side-effect of not showing ​the model. +    // side effect of extending BlockWithEntity is it changes ​the render type to INVISIBLE, so we have to revert this 
-    ​// You can also implement BlockEntityProvider Type to avoid this side-effect.+    ​@Override
     public BlockRenderType getRenderType(BlockState state) {     public BlockRenderType getRenderType(BlockState state) {
         return BlockRenderType.MODEL;​         return BlockRenderType.MODEL;​
Line 18: Line 18:
  
     // We will create the BlockEntity later.     // We will create the BlockEntity later.
 +    @Override
     public BlockEntity createBlockEntity(BlockView view) {     public BlockEntity createBlockEntity(BlockView view) {
         return new BiggerChestBlockEntity();​         return new BiggerChestBlockEntity();​
     }     }
  
 +    @Override
     public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {     public void onPlaced(World world, BlockPos pos, BlockState state, LivingEntity placer, ItemStack itemStack) {
         if (itemStack.hasCustomName()) {         if (itemStack.hasCustomName()) {
Line 31: Line 33:
     }     }
  
 +    @Override
     public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {     public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
         if (!world.isClient) {         if (!world.isClient) {
Line 42: Line 45:
  
     // Scatter the items in the chest when it is removed.     // Scatter the items in the chest when it is removed.
 +    @Override
     public void onBlockRemoved(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {     public void onBlockRemoved(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
         if (state.getBlock() != newState.getBlock()) {         if (state.getBlock() != newState.getBlock()) {
Line 47: Line 51:
             if (blockEntity instanceof BiggerChestBlockEntity) {             if (blockEntity instanceof BiggerChestBlockEntity) {
                 ItemScatterer.spawn(world,​ (BlockPos)pos,​ (Inventory)((BiggerChestBlockEntity)blockEntity));​                 ItemScatterer.spawn(world,​ (BlockPos)pos,​ (Inventory)((BiggerChestBlockEntity)blockEntity));​
 +                // update comparators
                 world.updateHorizontalAdjacent(pos,​ this);                 world.updateHorizontalAdjacent(pos,​ this);
             }             }
Line 53: Line 58:
     }     }
  
 +    @Override
     public boolean hasComparatorOutput(BlockState state) {     public boolean hasComparatorOutput(BlockState state) {
         return true;         return true;
     }     }
  
 +    @Override
     public int getComparatorOutput(BlockState state, World world, BlockPos pos) {     public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
         return Container.calculateComparatorOutput(world.getBlockEntity(pos));​         return Container.calculateComparatorOutput(world.getBlockEntity(pos));​
Line 190: Line 197:
  
     // Shift + Player Inv Slot     // Shift + Player Inv Slot
 +    @Override
     public ItemStack transferSlot(PlayerEntity player, int invSlot) {     public ItemStack transferSlot(PlayerEntity player, int invSlot) {
         ItemStack newStack = ItemStack.EMPTY;​         ItemStack newStack = ItemStack.EMPTY;​
Line 251: Line 259:
     public static final String BIGGER_CHEST_TRANSLATION_KEY = Util.createTranslationKey("​container",​ BIGGER_CHEST);​     public static final String BIGGER_CHEST_TRANSLATION_KEY = Util.createTranslationKey("​container",​ BIGGER_CHEST);​
  
 +    @Override
     public void onInitialize() {     public void onInitialize() {
         [...]         [...]
Line 262: Line 271:
  
 <code java [enable_line_numbers="​true"​]>​ <code java [enable_line_numbers="​true"​]>​
 +    @Override
     public void onInitializeClient() {     public void onInitializeClient() {
         [...]         [...]
tutorial/containers.1582821254.txt.gz · Last modified: 2020/02/27 16:34 by mkpoli