From 5a59f12dce27adcf83619d57a79765d5334ffbc8 Mon Sep 17 00:00:00 2001 From: Jackson H Date: Mon, 5 Apr 2021 23:34:42 -0700 Subject: [PATCH] Slabfish no longer go to powered effigies Also improved throw accuracy --- .../common/block/SlabfishEffigyBlock.java | 40 +++++++++++++++---- .../entity/goals/SlabbyPraiseEffigyGoal.java | 9 ++++- 2 files changed, 40 insertions(+), 9 deletions(-) diff --git a/src/main/java/com/minecraftabnormals/environmental/common/block/SlabfishEffigyBlock.java b/src/main/java/com/minecraftabnormals/environmental/common/block/SlabfishEffigyBlock.java index 6440d706d..53f406dcf 100644 --- a/src/main/java/com/minecraftabnormals/environmental/common/block/SlabfishEffigyBlock.java +++ b/src/main/java/com/minecraftabnormals/environmental/common/block/SlabfishEffigyBlock.java @@ -4,6 +4,7 @@ import net.minecraft.block.BlockState; import net.minecraft.block.HorizontalBlock; import net.minecraft.block.IWaterLoggable; +import net.minecraft.block.RedstoneTorchBlock; import net.minecraft.fluid.FluidState; import net.minecraft.fluid.Fluids; import net.minecraft.item.BlockItemUseContext; @@ -16,14 +17,19 @@ import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.IBlockReader; import net.minecraft.world.IWorld; +import net.minecraft.world.World; +import net.minecraft.world.server.ServerWorld; + +import java.util.Random; public class SlabfishEffigyBlock extends HorizontalBlock implements IWaterLoggable { protected static final VoxelShape SHAPE = Block.makeCuboidShape(3.0D, 0.0D, 3.0D, 13.0D, 16.0D, 13.0D); + public static final BooleanProperty POWERED = BlockStateProperties.POWERED; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; public SlabfishEffigyBlock(Properties properties) { super(properties); - this.setDefaultState(this.getDefaultState().with(HORIZONTAL_FACING, Direction.NORTH).with(WATERLOGGED, false)); + this.setDefaultState(this.getDefaultState().with(HORIZONTAL_FACING, Direction.NORTH).with(POWERED, false).with(WATERLOGGED, false)); } @Override @@ -36,28 +42,48 @@ public boolean propagatesSkylightDown(BlockState state, IBlockReader reader, Blo return true; } + @Override + public BlockState getStateForPlacement(BlockItemUseContext context) { + return this.getDefaultState().with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite()).with(POWERED, context.getWorld().isBlockPowered(context.getPos())).with(WATERLOGGED, context.getWorld().getFluidState(context.getPos()).getFluid() == Fluids.WATER); + } + @Override public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { if (stateIn.get(WATERLOGGED)) { worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn)); } - return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos); } @Override - public FluidState getFluidState(BlockState state) { - return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state); + public void neighborChanged(BlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos, boolean isMoving) { + if (!worldIn.isRemote) { + boolean flag = state.get(POWERED); + if (flag != worldIn.isBlockPowered(pos)) { + if (flag) { + worldIn.getPendingBlockTicks().scheduleTick(pos, this, 4); + } else { + worldIn.setBlockState(pos, state.func_235896_a_(POWERED), 2); + } + } + } } @Override - public BlockState getStateForPlacement(BlockItemUseContext context) { - return this.getDefaultState().with(HORIZONTAL_FACING, context.getPlacementHorizontalFacing().getOpposite()).with(WATERLOGGED, context.getWorld().getFluidState(context.getPos()).getFluid() == Fluids.WATER); + public void tick(BlockState state, ServerWorld worldIn, BlockPos pos, Random rand) { + if (state.get(POWERED) && !worldIn.isBlockPowered(pos)) { + worldIn.setBlockState(pos, state.func_235896_a_(POWERED), 2); + } + } + + @Override + public FluidState getFluidState(BlockState state) { + return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state); } @Override protected void fillStateContainer(StateContainer.Builder builder) { - builder.add(HORIZONTAL_FACING, WATERLOGGED); + builder.add(HORIZONTAL_FACING, POWERED, WATERLOGGED); } } diff --git a/src/main/java/com/minecraftabnormals/environmental/common/entity/goals/SlabbyPraiseEffigyGoal.java b/src/main/java/com/minecraftabnormals/environmental/common/entity/goals/SlabbyPraiseEffigyGoal.java index 674652a7e..b29d221b7 100644 --- a/src/main/java/com/minecraftabnormals/environmental/common/entity/goals/SlabbyPraiseEffigyGoal.java +++ b/src/main/java/com/minecraftabnormals/environmental/common/entity/goals/SlabbyPraiseEffigyGoal.java @@ -3,11 +3,13 @@ import com.minecraftabnormals.environmental.common.block.SlabfishEffigyBlock; import com.minecraftabnormals.environmental.common.entity.SlabfishEntity; import net.minecraft.block.BlockState; +import net.minecraft.command.arguments.EntityAnchorArgument; import net.minecraft.entity.ai.goal.Goal; import net.minecraft.entity.item.ItemEntity; import net.minecraft.item.ItemStack; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.vector.Vector3d; import java.util.EnumSet; import java.util.Random; @@ -39,6 +41,8 @@ else if (this.slabfish.isSitting()) return false; else if (isBackpackEmpty()) return false; + else if (state.get(SlabfishEffigyBlock.POWERED)) + return false; else return this.slabfish.world.isNightTime(); } @@ -67,8 +71,9 @@ public void tick() { return; this.slabfish.getNavigator().tryMoveToXYZ(this.effigyPos.getX() + 0.5, this.effigyPos.getY(), this.effigyPos.getZ() + 0.5, 1.1D); + this.slabfish.lookAt(EntityAnchorArgument.Type.EYES, new Vector3d(this.effigyPos.getX() + 0.5, this.effigyPos.getY() - 1, this.effigyPos.getZ() + 0.5)); + if (this.slabfish.getDistanceSq(this.effigyPos.getX() + 0.5, this.effigyPos.getY(), this.effigyPos.getZ() + 0.5) < 3.5D) { - this.slabfish.getLookController().setLookPosition(this.effigyPos.getX() + 0.5, this.effigyPos.getY() - 1, this.effigyPos.getZ() + 0.5); this.slabfish.getNavigator().clearPath(); this.throwItems(this.effigyPos); } @@ -77,6 +82,7 @@ public void tick() { private void throwItems(BlockPos pos) { Random rand = this.slabfish.getRNG(); + for (int i = 3; i < this.slabfish.slabfishBackpack.getSizeInventory(); i++) { ItemStack stack = this.slabfish.slabfishBackpack.getStackInSlot(i); if (stack.isEmpty()) @@ -87,7 +93,6 @@ private void throwItems(BlockPos pos) { item.setThrowerId(this.slabfish.getUniqueID()); item.getPersistentData().putBoolean("EffigyItem", true); - this.slabfish.getLookController().setLookPosition(pos.getX() + 0.5, pos.getY() - 1F, pos.getZ() + 0.5); float f8 = MathHelper.sin(this.slabfish.rotationPitch * ((float) Math.PI / 180F)); float f2 = MathHelper.cos(this.slabfish.rotationPitch * ((float) Math.PI / 180F)); float f3 = MathHelper.sin(this.slabfish.rotationYaw * ((float) Math.PI / 180F));