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    77

Beethoven92

Beethoven92    77

  • Dragon Slayer
  • Beethoven92
  • Members
  • 77
  • 609 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    119

poopoodice

poopoodice    119

  • Dragon Slayer
  • poopoodice
  • Members
  • 119
  • 931 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    119

poopoodice

poopoodice    119

  • Dragon Slayer
  • poopoodice
  • Members
  • 119
  • 931 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

    • diesieben07
      Question about itemstack capabilities of crafting results

      By diesieben07 · Posted 8 minutes ago

      You cannot apply default values to all item stacks. There is no way. If you want your capability to have default values, you need to lazily initialize them whenever they are queried. For example in your capability: class MyCap { private String name = null; public String getName() { if (this.name == null) { this.name = "default value"; } return this.name; } }   This sounds very suspicious. What are you talking about?
    • Fizedi
      Loot table change for chest in plains house

      By Fizedi · Posted 15 minutes ago

      Hi All, Been trying to figure this out for a while now.    I want to make a change to the loot table so it will give me sugar cane. I have attached the json file I am testing with that should give suger cane (I replaced all the others with cane). Doesn't matter where I put it I can't get it to work. After each attempt I reload the world and tp to a spot I've never been to and then find a village (it is a flat world so not too hard). But I can't get it to work. Is there something I am missing.   I've tried putting it in saves/worlsname/data/loot_tables/minecraft/chests/village as well as in datapack folders and so many other places mentioned in google searches..   Someone please put me out of my misery...    Local game on PC, 1.15.2   Thanks! Fiz. village_plains_house.json
    • Tavi007
      Question about itemstack capabilities of crafting results

      By Tavi007 · Posted 17 minutes ago

      Hey, I stumbled across a bug in my mod, when using the workbench (and presumably any other sort of crafting station). I have an itemstack capability, that gets its default value through json files. So usually when the AttachCapabilityEvent<ItemStack> triggers, I can succesfully add these values to the item. However when the result slot in the workbench container updates to a new item, the attach event does not trigger and the capability stays empty. I added a hook using ItemCraftedEvent, so the values are being set, when the crafting results gets picked up, but I also added some costum tooltips, that displays the capability data. So currently it will not show any of my data, when the mouse hovers above the crafting result. Only after picking it up, the correct data can be seen. This might confuse the player, so I would like to know, if there is method for setting the default values the moment the resulting stack is generated. Also I fear, that the ItemCraftedEvent does not trigger for machines from other mods. This would mean, that it would be possible to create itemstacks with incorrect capability data. I hope my explanation is clear enough. If not, I can add some pictures to show you, what I mean.
    • diesieben07
      A problem occurred running the Server launcher.java.lang.reflect.InvocationTargetException

      By diesieben07 · Posted 2 hours ago

      1.12 is no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
    • diesieben07
      Please help

      By diesieben07 · Posted 2 hours ago

      Really old Minecraft versions are no longer supported on this forum. Please update to a modern version of Minecraft to receive support.
  • Topics

    • Tavi007
      1
      Question about itemstack capabilities of crafting results

      By Tavi007
      Started 18 minutes ago

    • Fizedi
      0
      Loot table change for chest in plains house

      By Fizedi
      Started 15 minutes ago

    • diseasedworm
      1
      A problem occurred running the Server launcher.java.lang.reflect.InvocationTargetException

      By diseasedworm
      Started 4 hours ago

    • RETARDETH
      1
      Please help

      By RETARDETH
      Started 8 hours ago

    • Gordan
      1
      Game Crashing Exit Code: -1

      By Gordan
      Started 10 hours ago

  • Who's Online (See full list)

    • forgnog
    • DARKHAWX
    • randomdude12300
    • Tavi007
    • diesieben07
    • Fizedi
    • Zeher_Monkey
    • discens
    • Iron1601
    • pupymk1
  • 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