Jump to content
  • Home
  • Files
  • Docs
Topics
  • All Content

  • This Topic
  • This Forum

  • Advanced Search
  • Existing user? Sign In  

    Sign In



    • Not recommended on shared computers


    • Forgot your password?

  • Sign Up
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16.3] Tile Entity Won't Break
Currently Supported: 1.16.X (Latest) and 1.15.X (LTS)
Sign in to follow this  
Followers 2
MrInfinity

[1.16.3] Tile Entity Won't Break

By MrInfinity, October 24, 2020 in Modder Support

  • Reply to this topic
  • Start new topic

Recommended Posts

MrInfinity    0

MrInfinity

MrInfinity    0

  • Tree Puncher
  • MrInfinity
  • Members
  • 0
  • 37 posts
Posted October 24, 2020

   I'm making a mod, and have created a hopper-like block. I  used @Override to turn it into a tile entity. It all works, you can put items in it, and hoppers underneath take them out. The problem is that when I break it in creative, it breaks, but the items in it disappear. In survival, it doesn't break at all. It's make the animation, and a new one will immediately appear. Is there an Override command to stop this from happening? It's also a custom block, so it has it's own voxel shape. Here's my code:

 

package com.mrinfinity.motionblocks.blocks;

import com.mrinfinity.motionblocks.BlocksthatMoveyou;
import com.mrinfinity.motionblocks.util.RegistryHandler;
import net.minecraft.block.*;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.container.INamedContainerProvider;
import net.minecraft.item.BlockItemUseContext;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.loot.LootContext;
import net.minecraft.state.DirectionProperty;
import net.minecraft.state.StateContainer;
import net.minecraft.state.properties.BlockStateProperties;
import net.minecraft.tileentity.HopperTileEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.util.math.shapes.IBooleanFunction;
import net.minecraft.util.math.shapes.ISelectionContext;
import net.minecraft.util.math.shapes.VoxelShape;
import net.minecraft.util.math.shapes.VoxelShapes;
import net.minecraft.world.IBlockReader;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraftforge.common.Tags;
import net.minecraftforge.common.ToolType;
import net.minecraftforge.fml.network.NetworkHooks;

import javax.annotation.Nullable;
import java.util.List;
import java.util.stream.Stream;

public class ConveyorHopper extends Block {

    private static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING;

    private static final VoxelShape SHAPE_N = Stream.of(
            Block.makeCuboidShape(0, 10, 0, 16, 16, 16),
            Block.makeCuboidShape(6, 0, 6, 10, 4, 10),
            Block.makeCuboidShape(4, 4, 4, 12, 10, 12)
    ).reduce((v1, v2) -> {return VoxelShapes.combineAndSimplify(v1, v2, IBooleanFunction.OR);}).get();

    private static final VoxelShape SHAPE_E = Stream.of(
            Block.makeCuboidShape(0, 10, 0, 16, 16, 16),
            Block.makeCuboidShape(6, 0, 6, 10, 4, 10),
            Block.makeCuboidShape(4, 4, 4, 12, 10, 12)
    ).reduce((v1, v2) -> {return VoxelShapes.combineAndSimplify(v1, v2, IBooleanFunction.OR);}).get();

    private static final VoxelShape SHAPE_S = Stream.of(
            Block.makeCuboidShape(0, 10, 0, 16, 16, 16),
            Block.makeCuboidShape(6, 0, 6, 10, 4, 10),
            Block.makeCuboidShape(4, 4, 4, 12, 10, 12)
    ).reduce((v1, v2) -> {return VoxelShapes.combineAndSimplify(v1, v2, IBooleanFunction.OR);}).get();

    private static final VoxelShape SHAPE_W = Stream.of(
            Block.makeCuboidShape(0, 10, 0, 16, 16, 16),
            Block.makeCuboidShape(6, 0, 6, 10, 4, 10),
            Block.makeCuboidShape(4, 4, 4, 12, 10, 12)
    ).reduce((v1, v2) -> {return VoxelShapes.combineAndSimplify(v1, v2, IBooleanFunction.OR);}).get();

    public ConveyorHopper() {
        super(AbstractBlock.Properties.create(Material.IRON)
                .hardnessAndResistance(4.0f, 5.0f)
                .sound(SoundType.METAL)
                .harvestLevel(2)
                .harvestTool(ToolType.PICKAXE)
                .func_235859_g_());
    }

    @Override
    public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) {
        switch (state.get(FACING)) {
            case EAST:
                return SHAPE_E;
            case SOUTH:
                return SHAPE_S;
            case WEST:
                return SHAPE_W;
            default:
                return SHAPE_N;
        }
    }

    @Nullable
    @Override
    public BlockState getStateForPlacement(BlockItemUseContext context) {
        return this.getDefaultState().with(FACING, context.getPlacementHorizontalFacing().getOpposite());
    }

    @Override
    public BlockState rotate(BlockState state, Rotation rot) {
        return state.with(FACING, rot.rotate(state.get(FACING)));
    }

    @Override
    public BlockState mirror(BlockState state, Mirror mirrorIn) {
        return state.rotate(mirrorIn.toRotation(state.get(FACING)));
    }

    @Override
    protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) {
        builder.add(FACING);
    }

    @Override
    public float getAmbientOcclusionLightValue(BlockState state, IBlockReader worldIn, BlockPos pos) {
        return 0.5f;
    }

    @Override
    public boolean hasTileEntity(BlockState state) {
        return true;
    }

    @Nullable
    @Override
    public TileEntity createTileEntity(BlockState state, IBlockReader world) {
        return new HopperTileEntity();
    }

    @Override
    public ActionResultType onBlockActivated(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockRayTraceResult trace) {
        if (!world.isRemote) {
            TileEntity tileEntity = world.getTileEntity(pos);
            if (tileEntity instanceof INamedContainerProvider) {
                NetworkHooks.openGui((ServerPlayerEntity) player, (INamedContainerProvider) tileEntity, tileEntity.getPos());
            } else {
                throw new IllegalStateException("Our named container provider is missing!");
            }
            return ActionResultType.SUCCESS;
        }
        return super.onBlockActivated(state, world, pos, player, hand, trace);
    }
}
  • Quote

Share this post


Link to post
Share on other sites

Beethoven92    70

Beethoven92

Beethoven92    70

  • Dragon Slayer
  • Beethoven92
  • Members
  • 70
  • 562 posts
Posted October 24, 2020 (edited)

You have to override the onReplaced method and tell your block to drop the contents of its tile entity when replaced or broken...look at vanilla chest, hopper etc. for examples on how to handle container blocks

Edited October 24, 2020 by Beethoven92
  • Quote

Check out the port of the BetterEnd fabric mod (WIP): https://www.curseforge.com/minecraft/mc-mods/betterend-forge-port

A little fun project: https://www.curseforge.com/minecraft/mc-mods/two-players-one-horse

Share this post


Link to post
Share on other sites

MrInfinity    0

MrInfinity

MrInfinity    0

  • Tree Puncher
  • MrInfinity
  • Members
  • 0
  • 37 posts
Posted October 24, 2020

Where would I find the vanilla files for a hopper or chest? I can't figure out what any of the stuff in the minecraft folder means

 

  • Quote

Share this post


Link to post
Share on other sites

MrInfinity    0

MrInfinity

MrInfinity    0

  • Tree Puncher
  • MrInfinity
  • Members
  • 0
  • 37 posts
Posted October 25, 2020

Found it

  • Quote

Share this post


Link to post
Share on other sites

MrInfinity    0

MrInfinity

MrInfinity    0

  • Tree Puncher
  • MrInfinity
  • Members
  • 0
  • 37 posts
Posted October 25, 2020 (edited)

Ok so now when I have this, and when I break it in creative the items inside drop. In survival, it still refuses to break. Any idea why?

@Override
public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
    if (!state.isIn(newState.getBlock())) {
        TileEntity tileentity = worldIn.getTileEntity(pos);
        if (tileentity instanceof HopperTileEntity) {
            InventoryHelper.dropInventoryItems(worldIn, pos, (HopperTileEntity)tileentity);
            worldIn.updateComparatorOutputLevel(pos, this);
        }

        super.onReplaced(state, worldIn, pos, newState, isMoving);
    }
}

Edit: Using haste 155, or instamine, I can break it. Obviously, you can't get this normally, but it does break. This is in survival

Edited October 25, 2020 by MrInfinity
  • Quote

Share this post


Link to post
Share on other sites

poopoodice    114

poopoodice

poopoodice    114

  • Dragon Slayer
  • poopoodice
  • Members
  • 114
  • 904 posts
Posted October 25, 2020

Why do you have this?

.func_235859_g_()
  • Quote

Share this post


Link to post
Share on other sites

MrInfinity    0

MrInfinity

MrInfinity    0

  • Tree Puncher
  • MrInfinity
  • Members
  • 0
  • 37 posts
Posted October 25, 2020

For some reason, SetRequiresTool doesn't work, but that's the code that does it

 

  • Quote

Share this post


Link to post
Share on other sites

MrInfinity    0

MrInfinity

MrInfinity    0

  • Tree Puncher
  • MrInfinity
  • Members
  • 0
  • 37 posts
Posted October 26, 2020

Alright so I think that the problem is that the tile entity is replacing itself every tick. This is why it'll break in creative and instamine, because it's destroyed in less than a tick

  • Quote

Share this post


Link to post
Share on other sites

MrInfinity    0

MrInfinity

MrInfinity    0

  • Tree Puncher
  • MrInfinity
  • Members
  • 0
  • 37 posts
Posted October 26, 2020

 

29 minutes ago, MrInfinity said:

Alright so I think that the problem is that the tile entity is replacing itself every tick. This is why it'll break in creative and instamine, because it's destroyed in less than a tick

Any way to fix that?

 

  • Quote

Share this post


Link to post
Share on other sites

poopoodice    114

poopoodice

poopoodice    114

  • Dragon Slayer
  • poopoodice
  • Members
  • 114
  • 904 posts
Posted October 26, 2020

Remove 

.func_235859_g_()

This is preventing yuor block getting destroyed.

  • Quote

Share this post


Link to post
Share on other sites

MrInfinity    0

MrInfinity

MrInfinity    0

  • Tree Puncher
  • MrInfinity
  • Members
  • 0
  • 37 posts
Posted October 26, 2020

Oh okay thanks

 

  • Quote

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

    • Insert image from URL
×
  • Desktop
  • Tablet
  • Phone
Sign in to follow this  
Followers 2
Go To Topic Listing



  • Recently Browsing

    No registered users viewing this page.

  • Posts

    • Milano
      My forge wont install

      By Milano · Posted 7 minutes ago

      Yes, that actually worked. Thanks for the link.  I am finally able to install. Thankyou for all the support, have a nice day!
    • octa
      Disconnection From Server When Placing Modded Block

      By octa · Posted 9 minutes ago

      Oh, that makes sense. Do you have a suggested way of initializing that BlockPos? I can't think of anything other than assigning a symbolic value which gets verified before use, but that seems clumsy.
    • diesieben07
      My forge wont install

      By diesieben07 · Posted 21 minutes ago

      Some zip managers like to take control of the .jar file extension away from Java. Make sure you have Java installed and try running Jarfix once, then try the installer again.
    • diesieben07
      Disconnection From Server When Placing Modded Block

      By diesieben07 · Posted 22 minutes ago

      That is fine, but then you must use @ObjectHolder instead of manually assigning fields.   It crashes because your TileEntityPortalBase creates an SUpdateTileEntityPacket with a null BlockPos.
    • Purity
      Valhelsia 3 server not starting

      By Purity · Posted 33 minutes ago

      how do i know if i installed correctly? it works good when i run it on my computer any thoughts on how i can fix it on the host?
  • Topics

    • Milano
      4
      My forge wont install

      By Milano
      Started 45 minutes ago

    • octa
      6
      Disconnection From Server When Placing Modded Block

      By octa
      Started 4 hours ago

    • Purity
      10
      Valhelsia 3 server not starting

      By Purity
      Started 17 hours ago

    • Exced
      1
      Minecraft Eternal Modpack Server won't start

      By Exced
      Started 1 hour ago

    • xX_deadbush_Xx
      0
      1.15.2 compiled mod crashes due to IllegalAccessError

      By xX_deadbush_Xx
      Started 47 minutes ago

  • Who's Online (See full list)

    • GermanBucket
    • Nuparu00
    • octa
    • Purity
    • diesieben07
    • Milano
    • SaltBeard
    • Mopaseo
  • All Activity
  • Home
  • Mod Developer Central
  • Modder Support
  • [1.16.3] Tile Entity Won't Break
  • Theme

Copyright © 2019 ForgeDevelopment LLC · Ads by Longitude Ads LLC Powered by Invision Community