Skip to content

Commit

Permalink
Slabfish no longer go to powered effigies
Browse files Browse the repository at this point in the history
Also improved throw accuracy
  • Loading branch information
jacksonhardaway committed Apr 6, 2021
1 parent b80ee50 commit 5a59f12
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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<Block, BlockState> builder) {
builder.add(HORIZONTAL_FACING, WATERLOGGED);
builder.add(HORIZONTAL_FACING, POWERED, WATERLOGGED);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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);
}
Expand All @@ -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())
Expand All @@ -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));
Expand Down

0 comments on commit 5a59f12

Please sign in to comment.