filename:
common/src/main/java/rearth/oritech/block/blocks/accelerator/AcceleratorPassthroughBlock.java
branch:
1.21
back to repo
package rearth.oritech.block.blocks.accelerator;
import com.mojang.serialization.MapCodec;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRenderType;
import net.minecraft.block.BlockState;
import net.minecraft.block.HorizontalFacingBlock;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.Properties;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion;
import org.jetbrains.annotations.Nullable;
import rearth.oritech.block.entity.accelerator.AcceleratorParticleLogic;
import java.util.Objects;
public class AcceleratorPassthroughBlock extends HorizontalFacingBlock {
public AcceleratorPassthroughBlock(Settings settings) {
super(settings);
setDefaultState(getDefaultState().with(Properties.HORIZONTAL_FACING, Direction.NORTH));
}
@Override
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(Properties.HORIZONTAL_FACING);
}
@Nullable
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return Objects.requireNonNull(super.getPlacementState(ctx)).with(Properties.HORIZONTAL_FACING, ctx.getHorizontalPlayerFacing().getOpposite());
}
@Override
protected void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
super.onStateReplaced(state, world, pos, newState, moved);
AcceleratorParticleLogic.resetCachedGate(pos);
}
@Override
public BlockState onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) {
AcceleratorParticleLogic.resetCachedGate(pos);
return super.onBreak(world, pos, state, player);
}
@Override
protected void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
if (!world.isClient) {
AcceleratorParticleLogic.resetNearbyCache(pos);
}
}
@Override
public void onDestroyedByExplosion(World world, BlockPos pos, Explosion explosion) {
super.onDestroyedByExplosion(world, pos, explosion);
AcceleratorParticleLogic.resetCachedGate(pos);
}
@Override
protected BlockRenderType getRenderType(BlockState state) {
return BlockRenderType.MODEL;
}
@Override
protected MapCodec<? extends HorizontalFacingBlock> getCodec() {
return null;
}
}