2020-02-21 18:15:37 +01:00
|
|
|
package de.ellpeck.naturesaura.blocks;
|
|
|
|
|
2021-12-04 15:40:09 +01:00
|
|
|
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityItemDistributor;
|
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;
|
2021-12-04 15:40:09 +01:00
|
|
|
import net.minecraft.entity.player.Player;
|
|
|
|
import net.minecraft.tileentity.BlockEntity;
|
|
|
|
import net.minecraft.util.InteractionResult;
|
2020-02-21 18:15:37 +01:00
|
|
|
import net.minecraft.util.Hand;
|
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.util.math.BlockRayTraceResult;
|
2021-12-04 15:40:09 +01:00
|
|
|
import net.minecraft.level.Level;
|
2020-02-21 18:15:37 +01:00
|
|
|
|
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() {
|
2021-12-04 15:40:09 +01:00
|
|
|
super("item_distributor", BlockEntityItemDistributor::new, Properties.from(Blocks.STONE_BRICKS));
|
2020-02-21 18:15:37 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
2021-12-04 15:40:09 +01:00
|
|
|
public InteractionResult onBlockActivated(BlockState state, Level levelIn, BlockPos pos, Player player, Hand handIn, BlockRayTraceResult hit) {
|
2020-09-22 03:17:02 +02:00
|
|
|
if (!player.isSneaking())
|
2021-12-04 15:40:09 +01:00
|
|
|
return InteractionResult.FAIL;
|
|
|
|
BlockEntity tile = levelIn.getBlockEntity(pos);
|
|
|
|
if (!(tile instanceof BlockEntityItemDistributor))
|
|
|
|
return InteractionResult.FAIL;
|
|
|
|
if (!levelIn.isClientSide) {
|
|
|
|
BlockEntityItemDistributor distributor = (BlockEntityItemDistributor) tile;
|
2020-02-21 18:15:37 +01:00
|
|
|
distributor.isRandomMode = !distributor.isRandomMode;
|
|
|
|
distributor.sendToClients();
|
|
|
|
}
|
2021-12-04 15:40:09 +01:00
|
|
|
return InteractionResult.SUCCESS;
|
2020-02-21 18:15:37 +01:00
|
|
|
}
|
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
|
|
|
}
|