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