NaturesAura/src/main/java/de/ellpeck/naturesaura/blocks/BlockItemDistributor.java

45 lines
1.9 KiB
Java
Raw Normal View History

2020-02-21 18:15:37 +01:00
package de.ellpeck.naturesaura.blocks;
import de.ellpeck.naturesaura.blocks.tiles.TileEntityItemDistributor;
2020-02-22 10:56:29 +01:00
import de.ellpeck.naturesaura.data.BlockStateGenerator;
import de.ellpeck.naturesaura.reg.ICustomBlockState;
2020-02-21 18:15:37 +01:00
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ActionResultType;
import net.minecraft.util.Hand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult;
import net.minecraft.world.World;
2020-02-22 10:56:29 +01:00
public class BlockItemDistributor extends BlockContainerImpl implements ICustomBlockState {
2020-02-21 18:15:37 +01:00
public BlockItemDistributor() {
super("item_distributor", TileEntityItemDistributor::new, ModBlocks.prop(Blocks.FURNACE));
}
@Override
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) {
2020-09-22 03:17:02 +02:00
if (!player.isSneaking())
2020-02-21 18:15:37 +01:00
return ActionResultType.FAIL;
TileEntity tile = worldIn.getTileEntity(pos);
if (!(tile instanceof TileEntityItemDistributor))
return ActionResultType.FAIL;
if (!worldIn.isRemote) {
TileEntityItemDistributor distributor = (TileEntityItemDistributor) tile;
distributor.isRandomMode = !distributor.isRandomMode;
distributor.sendToClients();
}
return ActionResultType.SUCCESS;
}
2020-02-22 10:56:29 +01:00
@Override
public void generateCustomBlockState(BlockStateGenerator generator) {
generator.simpleBlock(this, generator.models().cubeBottomTop(this.getBaseName(),
generator.modLoc("block/" + this.getBaseName()),
generator.modLoc("block/" + this.getBaseName() + "_bottom"),
generator.modLoc("block/" + this.getBaseName() + "_top")));
}
2020-02-21 18:15:37 +01:00
}