155 lines
7.8 KiB
Java
155 lines
7.8 KiB
Java
package net.minecraft.world.level.block;
|
|
|
|
import net.minecraft.world.level.block.state.AbstractStateHolder;
|
|
import net.minecraft.world.level.BlockGetter;
|
|
import net.minecraft.world.level.block.state.predicate.BlockMaterialPredicate;
|
|
import net.minecraft.world.level.material.Material;
|
|
import net.minecraft.world.level.block.state.predicate.BlockStatePredicate;
|
|
import net.minecraft.world.level.block.state.pattern.BlockPatternBuilder;
|
|
import net.minecraft.world.level.block.state.StateDefinition;
|
|
import net.minecraft.world.item.BlockPlaceContext;
|
|
import java.util.Iterator;
|
|
import net.minecraft.world.level.block.state.pattern.BlockInWorld;
|
|
import net.minecraft.world.entity.animal.IronGolem;
|
|
import net.minecraft.advancements.CriteriaTriggers;
|
|
import net.minecraft.server.level.ServerPlayer;
|
|
import net.minecraft.world.entity.Entity;
|
|
import net.minecraft.world.entity.EntityType;
|
|
import net.minecraft.world.entity.animal.SnowGolem;
|
|
import net.minecraft.world.level.LevelReader;
|
|
import net.minecraft.core.BlockPos;
|
|
import net.minecraft.world.level.Level;
|
|
import net.minecraft.world.level.block.state.properties.Property;
|
|
import net.minecraft.core.Direction;
|
|
import net.minecraft.world.level.block.state.BlockState;
|
|
import java.util.function.Predicate;
|
|
import javax.annotation.Nullable;
|
|
import net.minecraft.world.level.block.state.pattern.BlockPattern;
|
|
import net.minecraft.world.level.block.state.properties.DirectionProperty;
|
|
|
|
public class CarvedPumpkinBlock extends HorizontalDirectionalBlock {
|
|
public static final DirectionProperty FACING;
|
|
@Nullable
|
|
private BlockPattern snowGolemBase;
|
|
@Nullable
|
|
private BlockPattern snowGolemFull;
|
|
@Nullable
|
|
private BlockPattern ironGolemBase;
|
|
@Nullable
|
|
private BlockPattern ironGolemFull;
|
|
private static final Predicate<BlockState> PUMPKINS_PREDICATE;
|
|
|
|
protected CarvedPumpkinBlock(final Properties c) {
|
|
super(c);
|
|
this.registerDefaultState(((AbstractStateHolder<O, BlockState>)this.stateDefinition.any()).<Comparable, Direction>setValue((Property<Comparable>)CarvedPumpkinBlock.FACING, Direction.NORTH));
|
|
}
|
|
|
|
@Override
|
|
public void onPlace(final BlockState byg1, final Level bjt, final BlockPos fk, final BlockState byg4, final boolean boolean5) {
|
|
if (byg4.getBlock() == byg1.getBlock()) {
|
|
return;
|
|
}
|
|
this.trySpawnGolem(bjt, fk);
|
|
}
|
|
|
|
public boolean canSpawnGolem(final LevelReader bjw, final BlockPos fk) {
|
|
return this.getOrCreateSnowGolemBase().find(bjw, fk) != null || this.getOrCreateIronGolemBase().find(bjw, fk) != null;
|
|
}
|
|
|
|
private void trySpawnGolem(final Level bjt, final BlockPos fk) {
|
|
BlockPattern.BlockPatternMatch b4 = this.getOrCreateSnowGolemFull().find(bjt, fk);
|
|
if (b4 != null) {
|
|
for (int integer5 = 0; integer5 < this.getOrCreateSnowGolemFull().getHeight(); ++integer5) {
|
|
final BlockInWorld byk6 = b4.getBlock(0, integer5, 0);
|
|
bjt.setBlock(byk6.getPos(), Blocks.AIR.defaultBlockState(), 2);
|
|
bjt.levelEvent(2001, byk6.getPos(), Block.getId(byk6.getState()));
|
|
}
|
|
final SnowGolem atu5 = EntityType.SNOW_GOLEM.create(bjt);
|
|
final BlockPos fk2 = b4.getBlock(0, 2, 0).getPos();
|
|
atu5.moveTo(fk2.getX() + 0.5, fk2.getY() + 0.05, fk2.getZ() + 0.5, 0.0f, 0.0f);
|
|
bjt.addFreshEntity(atu5);
|
|
for (final ServerPlayer xe8 : bjt.<ServerPlayer>getEntitiesOfClass(ServerPlayer.class, atu5.getBoundingBox().inflate(5.0))) {
|
|
CriteriaTriggers.SUMMONED_ENTITY.trigger(xe8, atu5);
|
|
}
|
|
for (int integer6 = 0; integer6 < this.getOrCreateSnowGolemFull().getHeight(); ++integer6) {
|
|
final BlockInWorld byk7 = b4.getBlock(0, integer6, 0);
|
|
bjt.blockUpdated(byk7.getPos(), Blocks.AIR);
|
|
}
|
|
}
|
|
else {
|
|
b4 = this.getOrCreateIronGolemFull().find(bjt, fk);
|
|
if (b4 != null) {
|
|
for (int integer5 = 0; integer5 < this.getOrCreateIronGolemFull().getWidth(); ++integer5) {
|
|
for (int integer7 = 0; integer7 < this.getOrCreateIronGolemFull().getHeight(); ++integer7) {
|
|
final BlockInWorld byk8 = b4.getBlock(integer5, integer7, 0);
|
|
bjt.setBlock(byk8.getPos(), Blocks.AIR.defaultBlockState(), 2);
|
|
bjt.levelEvent(2001, byk8.getPos(), Block.getId(byk8.getState()));
|
|
}
|
|
}
|
|
final BlockPos fk3 = b4.getBlock(1, 2, 0).getPos();
|
|
final IronGolem ati6 = EntityType.IRON_GOLEM.create(bjt);
|
|
ati6.setPlayerCreated(true);
|
|
ati6.moveTo(fk3.getX() + 0.5, fk3.getY() + 0.05, fk3.getZ() + 0.5, 0.0f, 0.0f);
|
|
bjt.addFreshEntity(ati6);
|
|
for (final ServerPlayer xe8 : bjt.<ServerPlayer>getEntitiesOfClass(ServerPlayer.class, ati6.getBoundingBox().inflate(5.0))) {
|
|
CriteriaTriggers.SUMMONED_ENTITY.trigger(xe8, ati6);
|
|
}
|
|
for (int integer6 = 0; integer6 < this.getOrCreateIronGolemFull().getWidth(); ++integer6) {
|
|
for (int integer8 = 0; integer8 < this.getOrCreateIronGolemFull().getHeight(); ++integer8) {
|
|
final BlockInWorld byk9 = b4.getBlock(integer6, integer8, 0);
|
|
bjt.blockUpdated(byk9.getPos(), Blocks.AIR);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
@Override
|
|
public BlockState getStateForPlacement(final BlockPlaceContext bcn) {
|
|
return ((AbstractStateHolder<O, BlockState>)this.defaultBlockState()).<Comparable, Direction>setValue((Property<Comparable>)CarvedPumpkinBlock.FACING, bcn.getHorizontalDirection().getOpposite());
|
|
}
|
|
|
|
@Override
|
|
protected void createBlockStateDefinition(final StateDefinition.Builder<Block, BlockState> a) {
|
|
a.add(CarvedPumpkinBlock.FACING);
|
|
}
|
|
|
|
private BlockPattern getOrCreateSnowGolemBase() {
|
|
if (this.snowGolemBase == null) {
|
|
this.snowGolemBase = BlockPatternBuilder.start().aisle(" ", "#", "#").where('#', BlockInWorld.hasState(BlockStatePredicate.forBlock(Blocks.SNOW_BLOCK))).build();
|
|
}
|
|
return this.snowGolemBase;
|
|
}
|
|
|
|
private BlockPattern getOrCreateSnowGolemFull() {
|
|
if (this.snowGolemFull == null) {
|
|
this.snowGolemFull = BlockPatternBuilder.start().aisle("^", "#", "#").where('^', BlockInWorld.hasState(CarvedPumpkinBlock.PUMPKINS_PREDICATE)).where('#', BlockInWorld.hasState(BlockStatePredicate.forBlock(Blocks.SNOW_BLOCK))).build();
|
|
}
|
|
return this.snowGolemFull;
|
|
}
|
|
|
|
private BlockPattern getOrCreateIronGolemBase() {
|
|
if (this.ironGolemBase == null) {
|
|
this.ironGolemBase = BlockPatternBuilder.start().aisle("~ ~", "###", "~#~").where('#', BlockInWorld.hasState(BlockStatePredicate.forBlock(Blocks.IRON_BLOCK))).where('~', BlockInWorld.hasState(BlockMaterialPredicate.forMaterial(Material.AIR))).build();
|
|
}
|
|
return this.ironGolemBase;
|
|
}
|
|
|
|
private BlockPattern getOrCreateIronGolemFull() {
|
|
if (this.ironGolemFull == null) {
|
|
this.ironGolemFull = BlockPatternBuilder.start().aisle("~^~", "###", "~#~").where('^', BlockInWorld.hasState(CarvedPumpkinBlock.PUMPKINS_PREDICATE)).where('#', BlockInWorld.hasState(BlockStatePredicate.forBlock(Blocks.IRON_BLOCK))).where('~', BlockInWorld.hasState(BlockMaterialPredicate.forMaterial(Material.AIR))).build();
|
|
}
|
|
return this.ironGolemFull;
|
|
}
|
|
|
|
@Override
|
|
public boolean isValidSpawn(final BlockState byg, final BlockGetter bjd, final BlockPos fk, final EntityType<?> akr) {
|
|
return true;
|
|
}
|
|
|
|
static {
|
|
FACING = HorizontalDirectionalBlock.FACING;
|
|
PUMPKINS_PREDICATE = (byg -> byg != null && (byg.getBlock() == Blocks.CARVED_PUMPKIN || byg.getBlock() == Blocks.JACK_O_LANTERN));
|
|
}
|
|
}
|