Migrate the Carpet codebase to Mojang Mappings
This commit is contained in:
346 files changed
+8353
-8492
No files matched your search
@@ -1,55 +1,55 @@
|
||||
package carpet.helpers;
|
||||
|
||||
import carpet.fakes.PistonBlockInterface;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.BlockSource;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.dispenser.DispenseItemBehavior;
|
||||
import net.minecraft.core.dispenser.OptionalDispenseItemBehavior;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.context.BlockPlaceContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.BaseRailBlock;
|
||||
import net.minecraft.world.level.block.BedBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.ComparatorBlock;
|
||||
import net.minecraft.world.level.block.DiodeBlock;
|
||||
import net.minecraft.world.level.block.DirectionalBlock;
|
||||
import net.minecraft.world.level.block.DispenserBlock;
|
||||
import net.minecraft.world.level.block.EndRodBlock;
|
||||
import net.minecraft.world.level.block.FenceGateBlock;
|
||||
import net.minecraft.world.level.block.GlazedTerracottaBlock;
|
||||
import net.minecraft.world.level.block.HopperBlock;
|
||||
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
|
||||
import net.minecraft.world.level.block.LeverBlock;
|
||||
import net.minecraft.world.level.block.ObserverBlock;
|
||||
import net.minecraft.world.level.block.RepeaterBlock;
|
||||
import net.minecraft.world.level.block.RotatedPillarBlock;
|
||||
import net.minecraft.world.level.block.Rotation;
|
||||
import net.minecraft.world.level.block.SlabBlock;
|
||||
import net.minecraft.world.level.block.StairBlock;
|
||||
import net.minecraft.world.level.block.TrapDoorBlock;
|
||||
import net.minecraft.world.level.block.piston.PistonBaseBlock;
|
||||
import net.minecraft.world.level.block.piston.PistonStructureResolver;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.block.state.properties.ComparatorMode;
|
||||
import net.minecraft.world.level.block.state.properties.Half;
|
||||
import net.minecraft.world.level.block.state.properties.SlabType;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import carpet.CarpetSettings;
|
||||
import net.minecraft.block.AbstractRailBlock;
|
||||
import net.minecraft.block.AbstractRedstoneGateBlock;
|
||||
import net.minecraft.block.BedBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.ComparatorBlock;
|
||||
import net.minecraft.block.DispenserBlock;
|
||||
import net.minecraft.block.EndRodBlock;
|
||||
import net.minecraft.block.FacingBlock;
|
||||
import net.minecraft.block.FenceGateBlock;
|
||||
import net.minecraft.block.GlazedTerracottaBlock;
|
||||
import net.minecraft.block.HopperBlock;
|
||||
import net.minecraft.block.HorizontalFacingBlock;
|
||||
import net.minecraft.block.LeverBlock;
|
||||
import net.minecraft.block.ObserverBlock;
|
||||
import net.minecraft.block.PillarBlock;
|
||||
import net.minecraft.block.PistonBlock;
|
||||
import net.minecraft.block.RepeaterBlock;
|
||||
import net.minecraft.block.SlabBlock;
|
||||
import net.minecraft.block.StairsBlock;
|
||||
import net.minecraft.block.TrapdoorBlock;
|
||||
import net.minecraft.block.dispenser.DispenserBehavior;
|
||||
import net.minecraft.block.dispenser.FallibleItemDispenserBehavior;
|
||||
import net.minecraft.block.enums.BlockHalf;
|
||||
import net.minecraft.block.enums.ComparatorMode;
|
||||
import net.minecraft.block.enums.SlabType;
|
||||
import net.minecraft.block.piston.PistonHandler;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.BlockRotation;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPointer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class BlockRotator
|
||||
{
|
||||
public static boolean flipBlockWithCactus(BlockState state, World world, PlayerEntity player, Hand hand, BlockHitResult hit)
|
||||
public static boolean flipBlockWithCactus(BlockState state, Level world, Player player, InteractionHand hand, BlockHitResult hit)
|
||||
{ //getAbilities()
|
||||
if (!player.getAbilities().allowModifyWorld || !CarpetSettings.flippinCactus || !player_holds_cactus_mainhand(player))
|
||||
if (!player.getAbilities().mayBuild || !CarpetSettings.flippinCactus || !player_holds_cactus_mainhand(player))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
@@ -59,14 +59,14 @@ public class BlockRotator
|
||||
return retval;
|
||||
}
|
||||
|
||||
public static BlockState alternativeBlockPlacement(Block block, ItemPlacementContext context)//World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
|
||||
public static BlockState alternativeBlockPlacement(Block block, BlockPlaceContext context)//World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer)
|
||||
{
|
||||
//actual alternative block placement code
|
||||
//
|
||||
if (true) throw new UnsupportedOperationException("Alternative Block Placement / client controlled / is not implemnted");
|
||||
|
||||
Direction facing;
|
||||
Vec3d vec3d = context.getHitPos();
|
||||
Vec3 vec3d = context.getClickLocation();
|
||||
float hitX = (float) vec3d.x;
|
||||
|
||||
if (hitX<2) // vanilla
|
||||
@@ -76,75 +76,75 @@ public class BlockRotator
|
||||
// now it would be great if hitX was adjusted in context to original range from 0.0 to 1.0
|
||||
// since its actually using it. Its private - maybe with Reflections?
|
||||
//
|
||||
PlayerEntity placer = context.getPlayer();
|
||||
BlockPos pos = context.getBlockPos();
|
||||
World world = context.getWorld();
|
||||
Player placer = context.getPlayer();
|
||||
BlockPos pos = context.getClickedPos();
|
||||
Level world = context.getLevel();
|
||||
|
||||
if (block instanceof GlazedTerracottaBlock)
|
||||
{
|
||||
facing = Direction.byId(code);
|
||||
facing = Direction.from3DDataValue(code);
|
||||
if(facing == Direction.UP || facing == Direction.DOWN)
|
||||
{
|
||||
facing = placer.getHorizontalFacing().getOpposite();
|
||||
facing = placer.getDirection().getOpposite();
|
||||
}
|
||||
return block.getDefaultState().with(HorizontalFacingBlock.FACING, facing);
|
||||
return block.defaultBlockState().setValue(HorizontalDirectionalBlock.FACING, facing);
|
||||
}
|
||||
else if (block instanceof ObserverBlock)
|
||||
{
|
||||
return block.getDefaultState()
|
||||
.with(FacingBlock.FACING, Direction.byId(code))
|
||||
.with(ObserverBlock.POWERED, true);
|
||||
return block.defaultBlockState()
|
||||
.setValue(DirectionalBlock.FACING, Direction.from3DDataValue(code))
|
||||
.setValue(ObserverBlock.POWERED, true);
|
||||
}
|
||||
else if (block instanceof RepeaterBlock)
|
||||
{
|
||||
facing = Direction.byId(code % 16);
|
||||
facing = Direction.from3DDataValue(code % 16);
|
||||
if(facing == Direction.UP || facing == Direction.DOWN)
|
||||
{
|
||||
facing = placer.getHorizontalFacing().getOpposite();
|
||||
facing = placer.getDirection().getOpposite();
|
||||
}
|
||||
return block.getDefaultState()
|
||||
.with(HorizontalFacingBlock.FACING, facing)
|
||||
.with(RepeaterBlock.DELAY, MathHelper.clamp(code / 16, 1, 4))
|
||||
.with(RepeaterBlock.LOCKED, Boolean.FALSE);
|
||||
return block.defaultBlockState()
|
||||
.setValue(HorizontalDirectionalBlock.FACING, facing)
|
||||
.setValue(RepeaterBlock.DELAY, Mth.clamp(code / 16, 1, 4))
|
||||
.setValue(RepeaterBlock.LOCKED, Boolean.FALSE);
|
||||
}
|
||||
else if (block instanceof TrapdoorBlock)
|
||||
else if (block instanceof TrapDoorBlock)
|
||||
{
|
||||
return block.getDefaultState()
|
||||
.with(TrapdoorBlock.FACING, Direction.byId(code % 16))
|
||||
.with(TrapdoorBlock.OPEN, Boolean.FALSE)
|
||||
.with(TrapdoorBlock.HALF, (code >= 16) ? BlockHalf.TOP : BlockHalf.BOTTOM)
|
||||
.with(TrapdoorBlock.OPEN, world.isReceivingRedstonePower(pos));
|
||||
return block.defaultBlockState()
|
||||
.setValue(TrapDoorBlock.FACING, Direction.from3DDataValue(code % 16))
|
||||
.setValue(TrapDoorBlock.OPEN, Boolean.FALSE)
|
||||
.setValue(TrapDoorBlock.HALF, (code >= 16) ? Half.TOP : Half.BOTTOM)
|
||||
.setValue(TrapDoorBlock.OPEN, world.hasNeighborSignal(pos));
|
||||
}
|
||||
else if (block instanceof ComparatorBlock)
|
||||
{
|
||||
facing = Direction.byId(code % 16);
|
||||
facing = Direction.from3DDataValue(code % 16);
|
||||
if((facing == Direction.UP) || (facing == Direction.DOWN))
|
||||
{
|
||||
facing = placer.getHorizontalFacing().getOpposite();
|
||||
facing = placer.getDirection().getOpposite();
|
||||
}
|
||||
ComparatorMode m = (hitX >= 16)?ComparatorMode.SUBTRACT: ComparatorMode.COMPARE;
|
||||
return block.getDefaultState()
|
||||
.with(HorizontalFacingBlock.FACING, facing)
|
||||
.with(ComparatorBlock.POWERED, Boolean.FALSE)
|
||||
.with(ComparatorBlock.MODE, m);
|
||||
return block.defaultBlockState()
|
||||
.setValue(HorizontalDirectionalBlock.FACING, facing)
|
||||
.setValue(ComparatorBlock.POWERED, Boolean.FALSE)
|
||||
.setValue(ComparatorBlock.MODE, m);
|
||||
}
|
||||
else if (block instanceof DispenserBlock)
|
||||
{
|
||||
return block.getDefaultState()
|
||||
.with(DispenserBlock.FACING, Direction.byId(code))
|
||||
.with(DispenserBlock.TRIGGERED, Boolean.FALSE);
|
||||
return block.defaultBlockState()
|
||||
.setValue(DispenserBlock.FACING, Direction.from3DDataValue(code))
|
||||
.setValue(DispenserBlock.TRIGGERED, Boolean.FALSE);
|
||||
}
|
||||
else if (block instanceof PistonBlock)
|
||||
else if (block instanceof PistonBaseBlock)
|
||||
{
|
||||
return block.getDefaultState()
|
||||
.with(FacingBlock.FACING, Direction.byId(code))
|
||||
.with(PistonBlock.EXTENDED, Boolean.FALSE);
|
||||
return block.defaultBlockState()
|
||||
.setValue(DirectionalBlock.FACING, Direction.from3DDataValue(code))
|
||||
.setValue(PistonBaseBlock.EXTENDED, Boolean.FALSE);
|
||||
}
|
||||
else if (block instanceof StairsBlock)
|
||||
else if (block instanceof StairBlock)
|
||||
{
|
||||
return block.getPlacementState(context)//worldIn, pos, facing, hitX, hitY, hitZ, meta, placer)
|
||||
.with(StairsBlock.FACING, Direction.byId(code % 16))
|
||||
.with(StairsBlock.HALF, ( hitX >= 16)?BlockHalf.TOP : BlockHalf.BOTTOM);
|
||||
return block.getStateForPlacement(context)//worldIn, pos, facing, hitX, hitY, hitZ, meta, placer)
|
||||
.setValue(StairBlock.FACING, Direction.from3DDataValue(code % 16))
|
||||
.setValue(StairBlock.HALF, ( hitX >= 16)?Half.TOP : Half.BOTTOM);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -222,109 +222,109 @@ public class BlockRotator
|
||||
}
|
||||
}
|
||||
|
||||
public static ItemStack dispenserRotate(BlockPointer source, ItemStack stack)
|
||||
public static ItemStack dispenserRotate(BlockSource source, ItemStack stack)
|
||||
{
|
||||
Direction sourceFace = source.getBlockState().get(DispenserBlock.FACING);
|
||||
World world = source.getWorld();
|
||||
BlockPos blockpos = source.getPos().offset(sourceFace); // offset
|
||||
Direction sourceFace = source.getBlockState().getValue(DispenserBlock.FACING);
|
||||
Level world = source.getLevel();
|
||||
BlockPos blockpos = source.getPos().relative(sourceFace); // offset
|
||||
BlockState iblockstate = world.getBlockState(blockpos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
// Block rotation for blocks that can be placed in all 6 or 4 rotations.
|
||||
if(block instanceof FacingBlock || block instanceof DispenserBlock)
|
||||
if(block instanceof DirectionalBlock || block instanceof DispenserBlock)
|
||||
{
|
||||
Direction face = iblockstate.get(FacingBlock.FACING);
|
||||
if (block instanceof PistonBlock && (
|
||||
iblockstate.get(PistonBlock.EXTENDED)
|
||||
|| ( ((PistonBlockInterface)block).publicShouldExtend(world, blockpos, face) && (new PistonHandler(world, blockpos, face, true)).calculatePush() )
|
||||
Direction face = iblockstate.getValue(DirectionalBlock.FACING);
|
||||
if (block instanceof PistonBaseBlock && (
|
||||
iblockstate.getValue(PistonBaseBlock.EXTENDED)
|
||||
|| ( ((PistonBlockInterface)block).publicShouldExtend(world, blockpos, face) && (new PistonStructureResolver(world, blockpos, face, true)).resolve() )
|
||||
)
|
||||
)
|
||||
return stack;
|
||||
|
||||
Direction rotated_face = rotateClockwise(face, sourceFace.getAxis());
|
||||
if(sourceFace.getId() % 2 == 0 || rotated_face == face)
|
||||
if(sourceFace.get3DDataValue() % 2 == 0 || rotated_face == face)
|
||||
{ // Flip to make blocks always rotate clockwise relative to the dispenser
|
||||
// when index is equal to zero. when index is equal to zero the dispenser is in the opposite direction.
|
||||
rotated_face = rotated_face.getOpposite();
|
||||
}
|
||||
world.setBlockState(blockpos, iblockstate.with(FacingBlock.FACING, rotated_face), 3);
|
||||
world.setBlock(blockpos, iblockstate.setValue(DirectionalBlock.FACING, rotated_face), 3);
|
||||
|
||||
|
||||
}
|
||||
else if(block instanceof HorizontalFacingBlock) // Block rotation for blocks that can be placed in only 4 horizontal rotations.
|
||||
else if(block instanceof HorizontalDirectionalBlock) // Block rotation for blocks that can be placed in only 4 horizontal rotations.
|
||||
{
|
||||
if (block instanceof BedBlock)
|
||||
return stack;
|
||||
Direction face = iblockstate.get(HorizontalFacingBlock.FACING);
|
||||
Direction face = iblockstate.getValue(HorizontalDirectionalBlock.FACING);
|
||||
face = rotateClockwise(face, Direction.Axis.Y);
|
||||
|
||||
if(sourceFace == Direction.DOWN)
|
||||
{ // same as above.
|
||||
face = face.getOpposite();
|
||||
}
|
||||
world.setBlockState(blockpos, iblockstate.with(HorizontalFacingBlock.FACING, face), 3);
|
||||
world.setBlock(blockpos, iblockstate.setValue(HorizontalDirectionalBlock.FACING, face), 3);
|
||||
}
|
||||
else if(block == Blocks.HOPPER )
|
||||
{
|
||||
Direction face = iblockstate.get(HopperBlock.FACING);
|
||||
Direction face = iblockstate.getValue(HopperBlock.FACING);
|
||||
if (face != Direction.DOWN)
|
||||
{
|
||||
face = rotateClockwise(face, Direction.Axis.Y);
|
||||
world.setBlockState(blockpos, iblockstate.with(HopperBlock.FACING, face), 3);
|
||||
world.setBlock(blockpos, iblockstate.setValue(HopperBlock.FACING, face), 3);
|
||||
}
|
||||
}
|
||||
// Send block update to the block that just have been rotated.
|
||||
world.updateNeighbor(blockpos, block, source.getPos());
|
||||
world.neighborChanged(blockpos, block, source.getPos());
|
||||
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
||||
public static boolean flip_block(BlockState state, World world, PlayerEntity player, Hand hand, BlockHitResult hit)
|
||||
public static boolean flip_block(BlockState state, Level world, Player player, InteractionHand hand, BlockHitResult hit)
|
||||
{
|
||||
Block block = state.getBlock();
|
||||
BlockPos pos = hit.getBlockPos();
|
||||
Vec3d hitVec = hit.getPos().subtract(pos.getX(), pos.getY(), pos.getZ());
|
||||
Direction facing = hit.getSide();
|
||||
Vec3 hitVec = hit.getLocation().subtract(pos.getX(), pos.getY(), pos.getZ());
|
||||
Direction facing = hit.getDirection();
|
||||
BlockState newState = null;
|
||||
if ( (block instanceof GlazedTerracottaBlock) || (block instanceof AbstractRedstoneGateBlock) || (block instanceof AbstractRailBlock) ||
|
||||
(block instanceof TrapdoorBlock) || (block instanceof LeverBlock) || (block instanceof FenceGateBlock))
|
||||
if ( (block instanceof GlazedTerracottaBlock) || (block instanceof DiodeBlock) || (block instanceof BaseRailBlock) ||
|
||||
(block instanceof TrapDoorBlock) || (block instanceof LeverBlock) || (block instanceof FenceGateBlock))
|
||||
{
|
||||
newState = state.rotate(BlockRotation.CLOCKWISE_90);
|
||||
newState = state.rotate(Rotation.CLOCKWISE_90);
|
||||
}
|
||||
else if ((block instanceof ObserverBlock) || (block instanceof EndRodBlock))
|
||||
{
|
||||
newState = state.with(FacingBlock.FACING, state.get(FacingBlock.FACING).getOpposite());
|
||||
newState = state.setValue(DirectionalBlock.FACING, state.getValue(DirectionalBlock.FACING).getOpposite());
|
||||
}
|
||||
else if (block instanceof DispenserBlock)
|
||||
{
|
||||
newState = state.with(DispenserBlock.FACING, state.get(DispenserBlock.FACING).getOpposite());
|
||||
newState = state.setValue(DispenserBlock.FACING, state.getValue(DispenserBlock.FACING).getOpposite());
|
||||
}
|
||||
else if (block instanceof PistonBlock)
|
||||
else if (block instanceof PistonBaseBlock)
|
||||
{
|
||||
if (!(state.get(PistonBlock.EXTENDED)))
|
||||
newState = state.with(FacingBlock.FACING, state.get(FacingBlock.FACING).getOpposite());
|
||||
if (!(state.getValue(PistonBaseBlock.EXTENDED)))
|
||||
newState = state.setValue(DirectionalBlock.FACING, state.getValue(DirectionalBlock.FACING).getOpposite());
|
||||
}
|
||||
else if (block instanceof SlabBlock)
|
||||
{
|
||||
if (((SlabBlock) block).hasSidedTransparency(state))
|
||||
if (((SlabBlock) block).useShapeForLightOcclusion(state))
|
||||
{
|
||||
newState = state.with(SlabBlock.TYPE, state.get(SlabBlock.TYPE) == SlabType.TOP ? SlabType.BOTTOM : SlabType.TOP);
|
||||
newState = state.setValue(SlabBlock.TYPE, state.getValue(SlabBlock.TYPE) == SlabType.TOP ? SlabType.BOTTOM : SlabType.TOP);
|
||||
}
|
||||
}
|
||||
else if (block instanceof HopperBlock)
|
||||
{
|
||||
if (state.get(HopperBlock.FACING) != Direction.DOWN)
|
||||
if (state.getValue(HopperBlock.FACING) != Direction.DOWN)
|
||||
{
|
||||
newState = state.with(HopperBlock.FACING, state.get(HopperBlock.FACING).rotateYClockwise());
|
||||
newState = state.setValue(HopperBlock.FACING, state.getValue(HopperBlock.FACING).getClockWise());
|
||||
}
|
||||
}
|
||||
else if (block instanceof StairsBlock)
|
||||
else if (block instanceof StairBlock)
|
||||
{
|
||||
//LOG.error(String.format("hit with facing: %s, at side %.1fX, X %.1fY, Y %.1fZ",facing, hitX, hitY, hitZ));
|
||||
if ((facing == Direction.UP && hitVec.y == 1.0f) || (facing == Direction.DOWN && hitVec.y == 0.0f))
|
||||
{
|
||||
newState = state.with(StairsBlock.HALF, state.get(StairsBlock.HALF) == BlockHalf.TOP ? BlockHalf.BOTTOM : BlockHalf.TOP );
|
||||
newState = state.setValue(StairBlock.HALF, state.getValue(StairBlock.HALF) == Half.TOP ? Half.BOTTOM : Half.TOP );
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -351,25 +351,25 @@ public class BlockRotator
|
||||
}
|
||||
if (turn_right)
|
||||
{
|
||||
newState = state.rotate(BlockRotation.COUNTERCLOCKWISE_90);
|
||||
newState = state.rotate(Rotation.COUNTERCLOCKWISE_90);
|
||||
}
|
||||
else
|
||||
{
|
||||
newState = state.rotate(BlockRotation.CLOCKWISE_90);
|
||||
newState = state.rotate(Rotation.CLOCKWISE_90);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (block instanceof PillarBlock)
|
||||
else if (block instanceof RotatedPillarBlock)
|
||||
{
|
||||
switch((Direction.Axis)state.get(PillarBlock.AXIS)) {
|
||||
switch((Direction.Axis)state.getValue(RotatedPillarBlock.AXIS)) {
|
||||
case X:
|
||||
newState = (BlockState)state.with(PillarBlock.AXIS, Direction.Axis.Z);
|
||||
newState = (BlockState)state.setValue(RotatedPillarBlock.AXIS, Direction.Axis.Z);
|
||||
break;
|
||||
case Z:
|
||||
newState = (BlockState)state.with(PillarBlock.AXIS, Direction.Axis.Y);
|
||||
newState = (BlockState)state.setValue(RotatedPillarBlock.AXIS, Direction.Axis.Y);
|
||||
break;
|
||||
case Y:
|
||||
newState = (BlockState)state.with(PillarBlock.AXIS, Direction.Axis.X);
|
||||
newState = (BlockState)state.setValue(RotatedPillarBlock.AXIS, Direction.Axis.X);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -379,34 +379,34 @@ public class BlockRotator
|
||||
}
|
||||
if (newState != null)
|
||||
{
|
||||
world.setBlockState(pos, newState, 2 | 1024);
|
||||
world.scheduleBlockRerenderIfNeeded(pos, state, newState);
|
||||
world.setBlock(pos, newState, 2 | 1024);
|
||||
world.setBlocksDirty(pos, state, newState);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
private static boolean player_holds_cactus_mainhand(PlayerEntity playerIn)
|
||||
private static boolean player_holds_cactus_mainhand(Player playerIn)
|
||||
{
|
||||
return (!playerIn.getMainHandStack().isEmpty()
|
||||
&& playerIn.getMainHandStack().getItem() instanceof BlockItem &&
|
||||
((BlockItem) (playerIn.getMainHandStack().getItem())).getBlock() == Blocks.CACTUS);
|
||||
return (!playerIn.getMainHandItem().isEmpty()
|
||||
&& playerIn.getMainHandItem().getItem() instanceof BlockItem &&
|
||||
((BlockItem) (playerIn.getMainHandItem().getItem())).getBlock() == Blocks.CACTUS);
|
||||
}
|
||||
public static boolean flippinEligibility(Entity entity)
|
||||
{
|
||||
if (CarpetSettings.flippinCactus && (entity instanceof PlayerEntity))
|
||||
if (CarpetSettings.flippinCactus && (entity instanceof Player))
|
||||
{
|
||||
PlayerEntity player = (PlayerEntity)entity;
|
||||
return (!player.getOffHandStack().isEmpty()
|
||||
&& player.getOffHandStack().getItem() instanceof BlockItem &&
|
||||
((BlockItem) (player.getOffHandStack().getItem())).getBlock() == Blocks.CACTUS);
|
||||
Player player = (Player)entity;
|
||||
return (!player.getOffhandItem().isEmpty()
|
||||
&& player.getOffhandItem().getItem() instanceof BlockItem &&
|
||||
((BlockItem) (player.getOffhandItem().getItem())).getBlock() == Blocks.CACTUS);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public static class CactusDispenserBehaviour extends FallibleItemDispenserBehavior implements DispenserBehavior
|
||||
public static class CactusDispenserBehaviour extends OptionalDispenseItemBehavior implements DispenseItemBehavior
|
||||
{
|
||||
@Override
|
||||
protected ItemStack dispenseSilently(BlockPointer source, ItemStack stack)
|
||||
protected ItemStack execute(BlockSource source, ItemStack stack)
|
||||
{
|
||||
if (CarpetSettings.rotatorBlock)
|
||||
{
|
||||
@@ -414,7 +414,7 @@ public class BlockRotator
|
||||
}
|
||||
else
|
||||
{
|
||||
return super.dispenseSilently(source, stack);
|
||||
return super.execute(source, stack);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,15 +1,15 @@
|
||||
package carpet.helpers;
|
||||
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.LevelAccessor;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
|
||||
public class BlockSaplingHelper
|
||||
{
|
||||
// Added code for checking water for dead shrub rule
|
||||
public static boolean hasWater(WorldAccess worldIn, BlockPos pos)
|
||||
public static boolean hasWater(LevelAccessor worldIn, BlockPos pos)
|
||||
{
|
||||
for (BlockPos blockpos$mutableblockpos : BlockPos.iterate(pos.add(-4, -4, -4), pos.add(4, 1, 4)))
|
||||
for (BlockPos blockpos$mutableblockpos : BlockPos.betweenClosed(pos.offset(-4, -4, -4), pos.offset(4, 1, 4)))
|
||||
{
|
||||
if (worldIn.getBlockState(blockpos$mutableblockpos).getMaterial() == Material.WATER)
|
||||
{
|
||||
|
||||
@@ -1,16 +1,16 @@
|
||||
package carpet.helpers;
|
||||
|
||||
import net.minecraft.entity.EntityType;
|
||||
import net.minecraft.util.collection.Pool;
|
||||
import net.minecraft.world.biome.SpawnSettings;
|
||||
import net.minecraft.util.random.WeightedRandomList;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.level.biome.MobSpawnSettings;
|
||||
|
||||
public class CustomSpawnLists
|
||||
{
|
||||
public static final Pool<SpawnSettings.SpawnEntry> PYRAMID_SPAWNS = Pool.of(new SpawnSettings.SpawnEntry(EntityType.HUSK, 1, 1, 1));
|
||||
public static final Pool<SpawnSettings.SpawnEntry> SHULKER_SPAWNS = Pool.of(new SpawnSettings.SpawnEntry(EntityType.SHULKER, 10, 4, 4));
|
||||
public static final Pool<SpawnSettings.SpawnEntry> BASTION_SPAWNS = Pool.of(
|
||||
new SpawnSettings.SpawnEntry(EntityType.PIGLIN_BRUTE, 5, 1, 2),
|
||||
new SpawnSettings.SpawnEntry(EntityType.PIGLIN, 10, 2, 4),
|
||||
new SpawnSettings.SpawnEntry(EntityType.HOGLIN, 2, 1, 2)
|
||||
public static final WeightedRandomList<MobSpawnSettings.SpawnerData> PYRAMID_SPAWNS = WeightedRandomList.create(new MobSpawnSettings.SpawnerData(EntityType.HUSK, 1, 1, 1));
|
||||
public static final WeightedRandomList<MobSpawnSettings.SpawnerData> SHULKER_SPAWNS = WeightedRandomList.create(new MobSpawnSettings.SpawnerData(EntityType.SHULKER, 10, 4, 4));
|
||||
public static final WeightedRandomList<MobSpawnSettings.SpawnerData> BASTION_SPAWNS = WeightedRandomList.create(
|
||||
new MobSpawnSettings.SpawnerData(EntityType.PIGLIN_BRUTE, 5, 1, 2),
|
||||
new MobSpawnSettings.SpawnerData(EntityType.PIGLIN, 10, 2, 4),
|
||||
new MobSpawnSettings.SpawnerData(EntityType.HOGLIN, 2, 1, 2)
|
||||
);
|
||||
}
|
||||
@@ -1,38 +1,37 @@
|
||||
package carpet.helpers;
|
||||
|
||||
import carpet.fakes.ServerPlayerEntityInterface;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.command.argument.EntityAnchorArgumentType;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.decoration.ItemFrameEntity;
|
||||
import net.minecraft.entity.passive.HorseBaseEntity;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.entity.vehicle.BoatEntity;
|
||||
import net.minecraft.entity.vehicle.MinecartEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.packet.s2c.play.UpdateSelectedSlotS2CPacket;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.network.packet.c2s.play.PlayerActionC2SPacket;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec2f;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.TreeMap;
|
||||
import net.minecraft.commands.arguments.EntityAnchorArgument;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.network.protocol.game.ClientboundSetCarriedItemPacket;
|
||||
import net.minecraft.network.protocol.game.ServerboundPlayerActionPacket;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.animal.horse.AbstractHorse;
|
||||
import net.minecraft.world.entity.decoration.ItemFrame;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.entity.vehicle.Boat;
|
||||
import net.minecraft.world.entity.vehicle.Minecart;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec2;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class EntityPlayerActionPack
|
||||
{
|
||||
private final ServerPlayerEntity player;
|
||||
private final ServerPlayer player;
|
||||
|
||||
private final Map<ActionType, Action> actions = new TreeMap<>();
|
||||
|
||||
@@ -48,7 +47,7 @@ public class EntityPlayerActionPack
|
||||
|
||||
private int itemUseCooldown;
|
||||
|
||||
public EntityPlayerActionPack(ServerPlayerEntity playerIn)
|
||||
public EntityPlayerActionPack(ServerPlayer playerIn)
|
||||
{
|
||||
player = playerIn;
|
||||
stopAll();
|
||||
@@ -84,7 +83,7 @@ public class EntityPlayerActionPack
|
||||
public EntityPlayerActionPack setSneaking(boolean doSneak)
|
||||
{
|
||||
sneaking = doSneak;
|
||||
player.setSneaking(doSneak);
|
||||
player.setShiftKeyDown(doSneak);
|
||||
if (sprinting && sneaking)
|
||||
setSprinting(false);
|
||||
return this;
|
||||
@@ -116,36 +115,36 @@ public class EntityPlayerActionPack
|
||||
case SOUTH: return look(0, 0);
|
||||
case EAST: return look(-90, 0);
|
||||
case WEST: return look(90, 0);
|
||||
case UP: return look(player.getYaw(), -90);
|
||||
case DOWN: return look(player.getYaw(), 90);
|
||||
case UP: return look(player.getYRot(), -90);
|
||||
case DOWN: return look(player.getYRot(), 90);
|
||||
}
|
||||
return this;
|
||||
}
|
||||
public EntityPlayerActionPack look(Vec2f rotation)
|
||||
public EntityPlayerActionPack look(Vec2 rotation)
|
||||
{
|
||||
return look(rotation.x, rotation.y);
|
||||
}
|
||||
|
||||
public EntityPlayerActionPack look(float yaw, float pitch)
|
||||
{
|
||||
player.setYaw(yaw % 360); //setYaw
|
||||
player.setPitch(MathHelper.clamp(pitch, -90, 90)); // setPitch
|
||||
player.setYRot(yaw % 360); //setYaw
|
||||
player.setXRot(Mth.clamp(pitch, -90, 90)); // setPitch
|
||||
// maybe player.setPositionAndAngles(player.x, player.y, player.z, yaw, MathHelper.clamp(pitch,-90.0F, 90.0F));
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPlayerActionPack lookAt(Vec3d position)
|
||||
public EntityPlayerActionPack lookAt(Vec3 position)
|
||||
{
|
||||
player.lookAt(EntityAnchorArgumentType.EntityAnchor.EYES, position);
|
||||
player.lookAt(EntityAnchorArgument.Anchor.EYES, position);
|
||||
return this;
|
||||
}
|
||||
|
||||
public EntityPlayerActionPack turn(float yaw, float pitch)
|
||||
{
|
||||
return look(player.getYaw() + yaw, player.getPitch() + pitch);
|
||||
return look(player.getYRot() + yaw, player.getXRot() + pitch);
|
||||
}
|
||||
|
||||
public EntityPlayerActionPack turn(Vec2f rotation)
|
||||
public EntityPlayerActionPack turn(Vec2 rotation)
|
||||
{
|
||||
return turn(rotation.x, rotation.y);
|
||||
}
|
||||
@@ -173,12 +172,12 @@ public class EntityPlayerActionPack
|
||||
List<Entity> entities;
|
||||
if (onlyRideables)
|
||||
{
|
||||
entities = player.world.getOtherEntities(player, player.getBoundingBox().expand(3.0D, 1.0D, 3.0D),
|
||||
e -> e instanceof MinecartEntity || e instanceof BoatEntity || e instanceof HorseBaseEntity);
|
||||
entities = player.level.getEntities(player, player.getBoundingBox().inflate(3.0D, 1.0D, 3.0D),
|
||||
e -> e instanceof Minecart || e instanceof Boat || e instanceof AbstractHorse);
|
||||
}
|
||||
else
|
||||
{
|
||||
entities = player.world.getOtherEntities(player, player.getBoundingBox().expand(3.0D, 1.0D, 3.0D));
|
||||
entities = player.level.getEntities(player, player.getBoundingBox().inflate(3.0D, 1.0D, 3.0D));
|
||||
}
|
||||
if (entities.size()==0)
|
||||
return this;
|
||||
@@ -189,7 +188,7 @@ public class EntityPlayerActionPack
|
||||
{
|
||||
if (e == player || (currentVehicle == e))
|
||||
continue;
|
||||
double dd = player.squaredDistanceTo(e);
|
||||
double dd = player.distanceToSqr(e);
|
||||
if (dd<distance)
|
||||
{
|
||||
distance = dd;
|
||||
@@ -197,8 +196,8 @@ public class EntityPlayerActionPack
|
||||
}
|
||||
}
|
||||
if (closest == null) return this;
|
||||
if (closest instanceof HorseBaseEntity && onlyRideables)
|
||||
((HorseBaseEntity) closest).interactMob(player, Hand.MAIN_HAND);
|
||||
if (closest instanceof AbstractHorse && onlyRideables)
|
||||
((AbstractHorse) closest).mobInteract(player, InteractionHand.MAIN_HAND);
|
||||
else
|
||||
player.startRiding(closest,true);
|
||||
return this;
|
||||
@@ -238,49 +237,49 @@ public class EntityPlayerActionPack
|
||||
}
|
||||
if (forward != 0.0F)
|
||||
{
|
||||
player.forwardSpeed = forward*(sneaking?0.3F:1.0F);
|
||||
player.zza = forward*(sneaking?0.3F:1.0F);
|
||||
}
|
||||
if (strafing != 0.0F)
|
||||
{
|
||||
player.sidewaysSpeed = strafing*(sneaking?0.3F:1.0F);
|
||||
player.xxa = strafing*(sneaking?0.3F:1.0F);
|
||||
}
|
||||
}
|
||||
|
||||
static HitResult getTarget(ServerPlayerEntity player)
|
||||
static HitResult getTarget(ServerPlayer player)
|
||||
{
|
||||
double reach = player.interactionManager.isCreative() ? 5 : 4.5f;
|
||||
double reach = player.gameMode.isCreative() ? 5 : 4.5f;
|
||||
return Tracer.rayTrace(player, 1, reach, false);
|
||||
}
|
||||
|
||||
private void dropItemFromSlot(int slot, boolean dropAll)
|
||||
{
|
||||
PlayerInventory inv = player.getInventory(); // getInventory;
|
||||
if (!inv.getStack(slot).isEmpty())
|
||||
player.dropItem(inv.removeStack(slot,
|
||||
dropAll ? inv.getStack(slot).getCount() : 1
|
||||
Inventory inv = player.getInventory(); // getInventory;
|
||||
if (!inv.getItem(slot).isEmpty())
|
||||
player.drop(inv.removeItem(slot,
|
||||
dropAll ? inv.getItem(slot).getCount() : 1
|
||||
), false, true); // scatter, keep owner
|
||||
}
|
||||
|
||||
public void drop(int selectedSlot, boolean dropAll)
|
||||
{
|
||||
PlayerInventory inv = player.getInventory(); // getInventory;
|
||||
Inventory inv = player.getInventory(); // getInventory;
|
||||
if (selectedSlot == -2) // all
|
||||
{
|
||||
for (int i = inv.size(); i >= 0; i--)
|
||||
for (int i = inv.getContainerSize(); i >= 0; i--)
|
||||
dropItemFromSlot(i, dropAll);
|
||||
}
|
||||
else // one slot
|
||||
{
|
||||
if (selectedSlot == -1)
|
||||
selectedSlot = inv.selectedSlot;
|
||||
selectedSlot = inv.selected;
|
||||
dropItemFromSlot(selectedSlot, dropAll);
|
||||
}
|
||||
}
|
||||
|
||||
public void setSlot(int slot)
|
||||
{
|
||||
player.getInventory().selectedSlot = slot-1;
|
||||
player.networkHandler.sendPacket(new UpdateSelectedSlotS2CPacket(slot-1));
|
||||
player.getInventory().selected = slot-1;
|
||||
player.connection.send(new ClientboundSetCarriedItemPacket(slot-1));
|
||||
}
|
||||
|
||||
public enum ActionType
|
||||
@@ -288,7 +287,7 @@ public class EntityPlayerActionPack
|
||||
USE(true)
|
||||
{
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action)
|
||||
boolean execute(ServerPlayer player, Action action)
|
||||
{
|
||||
EntityPlayerActionPack ap = ((ServerPlayerEntityInterface) player).getActionPack();
|
||||
if (ap.itemUseCooldown > 0)
|
||||
@@ -301,23 +300,23 @@ public class EntityPlayerActionPack
|
||||
return true;
|
||||
}
|
||||
HitResult hit = getTarget(player);
|
||||
for (Hand hand : Hand.values())
|
||||
for (InteractionHand hand : InteractionHand.values())
|
||||
{
|
||||
switch (hit.getType())
|
||||
{
|
||||
case BLOCK:
|
||||
{
|
||||
player.updateLastActionTime();
|
||||
ServerWorld world = player.getWorld();
|
||||
player.resetLastActionTime();
|
||||
ServerLevel world = player.getLevel();
|
||||
BlockHitResult blockHit = (BlockHitResult) hit;
|
||||
BlockPos pos = blockHit.getBlockPos();
|
||||
Direction side = blockHit.getSide();
|
||||
if (pos.getY() < player.getWorld().getTopY() - (side == Direction.UP ? 1 : 0) && world.canPlayerModifyAt(player, pos))
|
||||
Direction side = blockHit.getDirection();
|
||||
if (pos.getY() < player.getLevel().getMaxBuildHeight() - (side == Direction.UP ? 1 : 0) && world.mayInteract(player, pos))
|
||||
{
|
||||
ActionResult result = player.interactionManager.interactBlock(player, world, player.getStackInHand(hand), hand, blockHit);
|
||||
if (result.isAccepted())
|
||||
InteractionResult result = player.gameMode.useItemOn(player, world, player.getItemInHand(hand), hand, blockHit);
|
||||
if (result.consumesAction())
|
||||
{
|
||||
if (result.shouldSwingHand()) player.swingHand(hand);
|
||||
if (result.shouldSwing()) player.swing(hand);
|
||||
ap.itemUseCooldown = 3;
|
||||
return true;
|
||||
}
|
||||
@@ -326,19 +325,19 @@ public class EntityPlayerActionPack
|
||||
}
|
||||
case ENTITY:
|
||||
{
|
||||
player.updateLastActionTime();
|
||||
player.resetLastActionTime();
|
||||
EntityHitResult entityHit = (EntityHitResult) hit;
|
||||
Entity entity = entityHit.getEntity();
|
||||
boolean handWasEmpty = player.getStackInHand(hand).isEmpty();
|
||||
boolean itemFrameEmpty = (entity instanceof ItemFrameEntity) && ((ItemFrameEntity) entity).getHeldItemStack().isEmpty();
|
||||
Vec3d relativeHitPos = entityHit.getPos().subtract(entity.getX(), entity.getY(), entity.getZ());
|
||||
if (entity.interactAt(player, relativeHitPos, hand).isAccepted())
|
||||
boolean handWasEmpty = player.getItemInHand(hand).isEmpty();
|
||||
boolean itemFrameEmpty = (entity instanceof ItemFrame) && ((ItemFrame) entity).getItem().isEmpty();
|
||||
Vec3 relativeHitPos = entityHit.getLocation().subtract(entity.getX(), entity.getY(), entity.getZ());
|
||||
if (entity.interactAt(player, relativeHitPos, hand).consumesAction())
|
||||
{
|
||||
ap.itemUseCooldown = 3;
|
||||
return true;
|
||||
}
|
||||
// fix for SS itemframe always returns CONSUME even if no action is performed
|
||||
if (player.interact(entity, hand).isAccepted() && !(handWasEmpty && itemFrameEmpty))
|
||||
if (player.interactOn(entity, hand).consumesAction() && !(handWasEmpty && itemFrameEmpty))
|
||||
{
|
||||
ap.itemUseCooldown = 3;
|
||||
return true;
|
||||
@@ -346,8 +345,8 @@ public class EntityPlayerActionPack
|
||||
break;
|
||||
}
|
||||
}
|
||||
ItemStack handItem = player.getStackInHand(hand);
|
||||
if (player.interactionManager.interactItem(player, player.getWorld(), handItem, hand).isAccepted())
|
||||
ItemStack handItem = player.getItemInHand(hand);
|
||||
if (player.gameMode.useItem(player, player.getLevel(), handItem, hand).consumesAction())
|
||||
{
|
||||
ap.itemUseCooldown = 3;
|
||||
return true;
|
||||
@@ -357,16 +356,16 @@ public class EntityPlayerActionPack
|
||||
}
|
||||
|
||||
@Override
|
||||
void inactiveTick(ServerPlayerEntity player, Action action)
|
||||
void inactiveTick(ServerPlayer player, Action action)
|
||||
{
|
||||
EntityPlayerActionPack ap = ((ServerPlayerEntityInterface) player).getActionPack();
|
||||
ap.itemUseCooldown = 0;
|
||||
player.stopUsingItem();
|
||||
player.releaseUsingItem();
|
||||
}
|
||||
},
|
||||
ATTACK(true) {
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action) {
|
||||
boolean execute(ServerPlayer player, Action action) {
|
||||
HitResult hit = getTarget(player);
|
||||
switch (hit.getType()) {
|
||||
case ENTITY: {
|
||||
@@ -374,10 +373,10 @@ public class EntityPlayerActionPack
|
||||
if (!action.isContinuous)
|
||||
{
|
||||
player.attack(entityHit.getEntity());
|
||||
player.swingHand(Hand.MAIN_HAND);
|
||||
player.swing(InteractionHand.MAIN_HAND);
|
||||
}
|
||||
player.resetLastAttackedTicks();
|
||||
player.updateLastActionTime();
|
||||
player.resetAttackStrengthTicker();
|
||||
player.resetLastActionTime();
|
||||
return true;
|
||||
}
|
||||
case BLOCK: {
|
||||
@@ -389,18 +388,18 @@ public class EntityPlayerActionPack
|
||||
}
|
||||
BlockHitResult blockHit = (BlockHitResult) hit;
|
||||
BlockPos pos = blockHit.getBlockPos();
|
||||
Direction side = blockHit.getSide();
|
||||
if (player.isBlockBreakingRestricted(player.world, pos, player.interactionManager.getGameMode())) return false;
|
||||
if (ap.currentBlock != null && player.world.getBlockState(ap.currentBlock).isAir())
|
||||
Direction side = blockHit.getDirection();
|
||||
if (player.blockActionRestricted(player.level, pos, player.gameMode.getGameModeForPlayer())) return false;
|
||||
if (ap.currentBlock != null && player.level.getBlockState(ap.currentBlock).isAir())
|
||||
{
|
||||
ap.currentBlock = null;
|
||||
return false;
|
||||
}
|
||||
BlockState state = player.world.getBlockState(pos);
|
||||
BlockState state = player.level.getBlockState(pos);
|
||||
boolean blockBroken = false;
|
||||
if (player.interactionManager.getGameMode().isCreative())
|
||||
if (player.gameMode.getGameModeForPlayer().isCreative())
|
||||
{
|
||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.getWorld().getTopY());
|
||||
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, side, player.getLevel().getMaxBuildHeight());
|
||||
ap.blockHitDelay = 5;
|
||||
blockBroken = true;
|
||||
}
|
||||
@@ -408,15 +407,15 @@ public class EntityPlayerActionPack
|
||||
{
|
||||
if (ap.currentBlock != null)
|
||||
{
|
||||
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, side, player.getWorld().getTopY());
|
||||
player.gameMode.handleBlockBreakAction(ap.currentBlock, ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK, side, player.getLevel().getMaxBuildHeight());
|
||||
}
|
||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.START_DESTROY_BLOCK, side, player.getWorld().getTopY());
|
||||
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.START_DESTROY_BLOCK, side, player.getLevel().getMaxBuildHeight());
|
||||
boolean notAir = !state.isAir();
|
||||
if (notAir && ap.curBlockDamageMP == 0)
|
||||
{
|
||||
state.onBlockBreakStart(player.world, pos, player);
|
||||
state.attack(player.level, pos, player);
|
||||
}
|
||||
if (notAir && state.calcBlockBreakingDelta(player, player.world, pos) >= 1)
|
||||
if (notAir && state.getDestroyProgress(player, player.level, pos) >= 1)
|
||||
{
|
||||
ap.currentBlock = null;
|
||||
//instamine??
|
||||
@@ -430,19 +429,19 @@ public class EntityPlayerActionPack
|
||||
}
|
||||
else
|
||||
{
|
||||
ap.curBlockDamageMP += state.calcBlockBreakingDelta(player, player.world, pos);
|
||||
ap.curBlockDamageMP += state.getDestroyProgress(player, player.level, pos);
|
||||
if (ap.curBlockDamageMP >= 1)
|
||||
{
|
||||
player.interactionManager.processBlockBreakingAction(pos, PlayerActionC2SPacket.Action.STOP_DESTROY_BLOCK, side, player.getWorld().getTopY());
|
||||
player.gameMode.handleBlockBreakAction(pos, ServerboundPlayerActionPacket.Action.STOP_DESTROY_BLOCK, side, player.getLevel().getMaxBuildHeight());
|
||||
ap.currentBlock = null;
|
||||
ap.blockHitDelay = 5;
|
||||
blockBroken = true;
|
||||
}
|
||||
player.world.setBlockBreakingInfo(-1, pos, (int) (ap.curBlockDamageMP * 10));
|
||||
player.level.destroyBlockProgress(-1, pos, (int) (ap.curBlockDamageMP * 10));
|
||||
|
||||
}
|
||||
player.updateLastActionTime();
|
||||
player.swingHand(Hand.MAIN_HAND);
|
||||
player.resetLastActionTime();
|
||||
player.swing(InteractionHand.MAIN_HAND);
|
||||
return blockBroken;
|
||||
}
|
||||
}
|
||||
@@ -450,23 +449,23 @@ public class EntityPlayerActionPack
|
||||
}
|
||||
|
||||
@Override
|
||||
void inactiveTick(ServerPlayerEntity player, Action action)
|
||||
void inactiveTick(ServerPlayer player, Action action)
|
||||
{
|
||||
EntityPlayerActionPack ap = ((ServerPlayerEntityInterface) player).getActionPack();
|
||||
if (ap.currentBlock == null) return;
|
||||
player.world.setBlockBreakingInfo(-1, ap.currentBlock, -1);
|
||||
player.interactionManager.processBlockBreakingAction(ap.currentBlock, PlayerActionC2SPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.getWorld().getTopY());
|
||||
player.level.destroyBlockProgress(-1, ap.currentBlock, -1);
|
||||
player.gameMode.handleBlockBreakAction(ap.currentBlock, ServerboundPlayerActionPacket.Action.ABORT_DESTROY_BLOCK, Direction.DOWN, player.getLevel().getMaxBuildHeight());
|
||||
ap.currentBlock = null;
|
||||
}
|
||||
},
|
||||
JUMP(true)
|
||||
{
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action)
|
||||
boolean execute(ServerPlayer player, Action action)
|
||||
{
|
||||
if (action.limit == 1)
|
||||
{
|
||||
if (player.isOnGround()) player.jump(); // onGround
|
||||
if (player.isOnGround()) player.jumpFromGround(); // onGround
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -476,7 +475,7 @@ public class EntityPlayerActionPack
|
||||
}
|
||||
|
||||
@Override
|
||||
void inactiveTick(ServerPlayerEntity player, Action action)
|
||||
void inactiveTick(ServerPlayer player, Action action)
|
||||
{
|
||||
player.setJumping(false);
|
||||
}
|
||||
@@ -484,32 +483,32 @@ public class EntityPlayerActionPack
|
||||
DROP_ITEM(true)
|
||||
{
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action)
|
||||
boolean execute(ServerPlayer player, Action action)
|
||||
{
|
||||
player.updateLastActionTime();
|
||||
player.dropSelectedItem(false); // dropSelectedItem
|
||||
player.resetLastActionTime();
|
||||
player.drop(false); // dropSelectedItem
|
||||
return false;
|
||||
}
|
||||
},
|
||||
DROP_STACK(true)
|
||||
{
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action)
|
||||
boolean execute(ServerPlayer player, Action action)
|
||||
{
|
||||
player.updateLastActionTime();
|
||||
player.dropSelectedItem(true); // dropSelectedItem
|
||||
player.resetLastActionTime();
|
||||
player.drop(true); // dropSelectedItem
|
||||
return false;
|
||||
}
|
||||
},
|
||||
SWAP_HANDS(true)
|
||||
{
|
||||
@Override
|
||||
boolean execute(ServerPlayerEntity player, Action action)
|
||||
boolean execute(ServerPlayer player, Action action)
|
||||
{
|
||||
player.updateLastActionTime();
|
||||
ItemStack itemStack_1 = player.getStackInHand(Hand.OFF_HAND);
|
||||
player.setStackInHand(Hand.OFF_HAND, player.getStackInHand(Hand.MAIN_HAND));
|
||||
player.setStackInHand(Hand.MAIN_HAND, itemStack_1);
|
||||
player.resetLastActionTime();
|
||||
ItemStack itemStack_1 = player.getItemInHand(InteractionHand.OFF_HAND);
|
||||
player.setItemInHand(InteractionHand.OFF_HAND, player.getItemInHand(InteractionHand.MAIN_HAND));
|
||||
player.setItemInHand(InteractionHand.MAIN_HAND, itemStack_1);
|
||||
return false;
|
||||
}
|
||||
};
|
||||
@@ -521,10 +520,10 @@ public class EntityPlayerActionPack
|
||||
this.preventSpectator = preventSpectator;
|
||||
}
|
||||
|
||||
void start(ServerPlayerEntity player, Action action) {}
|
||||
abstract boolean execute(ServerPlayerEntity player, Action action);
|
||||
void inactiveTick(ServerPlayerEntity player, Action action) {}
|
||||
void stop(ServerPlayerEntity player, Action action)
|
||||
void start(ServerPlayer player, Action action) {}
|
||||
abstract boolean execute(ServerPlayer player, Action action);
|
||||
void inactiveTick(ServerPlayer player, Action action) {}
|
||||
void stop(ServerPlayer player, Action action)
|
||||
{
|
||||
inactiveTick(player, action);
|
||||
}
|
||||
|
||||
@@ -4,80 +4,81 @@ import carpet.CarpetSettings;
|
||||
import carpet.fakes.ChunkGeneratorInterface;
|
||||
import carpet.fakes.PlacedFeatureInterface;
|
||||
import carpet.fakes.StructureFeatureInterface;
|
||||
import com.google.common.collect.ImmutableCollection;
|
||||
import com.google.common.collect.ImmutableMultimap;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.structure.StructureStart;
|
||||
import net.minecraft.structure.pool.StructurePool;
|
||||
import net.minecraft.structure.pool.StructurePoolElement;
|
||||
import net.minecraft.structure.processor.StructureProcessorLists;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.ChunkPos;
|
||||
import net.minecraft.util.math.intprovider.ConstantIntProvider;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.util.registry.RegistryKey;
|
||||
import net.minecraft.world.StructurePresence;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.biome.Biome;
|
||||
import net.minecraft.world.biome.BiomeKeys;
|
||||
import net.minecraft.world.biome.BuiltinBiomes;
|
||||
import net.minecraft.world.gen.StructureAccessor;
|
||||
import net.minecraft.world.gen.chunk.StructuresConfig;
|
||||
import net.minecraft.world.gen.feature.ConfiguredStructureFeatures;
|
||||
import net.minecraft.world.gen.feature.PlacedFeature;
|
||||
import net.minecraft.world.gen.feature.size.TwoLayersFeatureSize;
|
||||
import net.minecraft.world.gen.foliage.BlobFoliagePlacer;
|
||||
import net.minecraft.world.gen.foliage.LargeOakFoliagePlacer;
|
||||
import net.minecraft.world.gen.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.gen.chunk.StructureConfig;
|
||||
import net.minecraft.world.gen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.gen.feature.ConfiguredStructureFeature;
|
||||
import net.minecraft.world.gen.feature.Feature;
|
||||
import net.minecraft.world.gen.feature.FeatureConfig;
|
||||
import net.minecraft.world.gen.feature.SimpleRandomFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.StructureFeature;
|
||||
import net.minecraft.world.gen.feature.StructurePoolFeatureConfig;
|
||||
import net.minecraft.world.gen.feature.TreeFeatureConfig;
|
||||
import net.minecraft.world.gen.stateprovider.BlockStateProvider;
|
||||
import net.minecraft.world.gen.treedecorator.BeehiveTreeDecorator;
|
||||
import net.minecraft.world.gen.trunk.LargeOakTrunkPlacer;
|
||||
import net.minecraft.world.gen.trunk.StraightTrunkPlacer;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
import java.util.OptionalInt;
|
||||
import java.util.function.Supplier;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.data.worldgen.ProcessorLists;
|
||||
import net.minecraft.data.worldgen.StructureFeatures;
|
||||
import net.minecraft.resources.ResourceKey;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.util.valueproviders.ConstantInt;
|
||||
import net.minecraft.world.level.ChunkPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.StructureFeatureManager;
|
||||
import net.minecraft.world.level.biome.Biome;
|
||||
import net.minecraft.world.level.biome.Biomes;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.chunk.ChunkGenerator;
|
||||
import net.minecraft.world.level.levelgen.StructureSettings;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredFeature;
|
||||
import net.minecraft.world.level.levelgen.feature.ConfiguredStructureFeature;
|
||||
import net.minecraft.world.level.levelgen.feature.Feature;
|
||||
import net.minecraft.world.level.levelgen.feature.StructureFeature;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.FeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.JigsawConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.SimpleRandomFeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.StructureFeatureConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
|
||||
import net.minecraft.world.level.levelgen.feature.featuresize.TwoLayersFeatureSize;
|
||||
import net.minecraft.world.level.levelgen.feature.foliageplacers.BlobFoliagePlacer;
|
||||
import net.minecraft.world.level.levelgen.feature.foliageplacers.FancyFoliagePlacer;
|
||||
import net.minecraft.world.level.levelgen.feature.stateproviders.BlockStateProvider;
|
||||
import net.minecraft.world.level.levelgen.feature.structures.StructurePoolElement;
|
||||
import net.minecraft.world.level.levelgen.feature.structures.StructureTemplatePool;
|
||||
import net.minecraft.world.level.levelgen.feature.treedecorators.BeehiveDecorator;
|
||||
import net.minecraft.world.level.levelgen.feature.trunkplacers.FancyTrunkPlacer;
|
||||
import net.minecraft.world.level.levelgen.feature.trunkplacers.StraightTrunkPlacer;
|
||||
import net.minecraft.world.level.levelgen.placement.PlacedFeature;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureCheckResult;
|
||||
import net.minecraft.world.level.levelgen.structure.StructureStart;
|
||||
|
||||
public class FeatureGenerator
|
||||
{
|
||||
public static final Object boo = new Object();
|
||||
synchronized public static Boolean plop(String featureName, ServerWorld world, BlockPos pos)
|
||||
synchronized public static Boolean plop(String featureName, ServerLevel world, BlockPos pos)
|
||||
{
|
||||
Thing custom = featureMap.get(featureName);
|
||||
if (custom != null)
|
||||
{
|
||||
return custom.plop(world, pos);
|
||||
}
|
||||
Identifier id = new Identifier(featureName);
|
||||
ConfiguredStructureFeature<?, ?> structureFeature = world.getRegistryManager().get(Registry.CONFIGURED_STRUCTURE_FEATURE_KEY).get(id);
|
||||
ResourceLocation id = new ResourceLocation(featureName);
|
||||
ConfiguredStructureFeature<?, ?> structureFeature = world.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).get(id);
|
||||
if (structureFeature != null)
|
||||
{
|
||||
return ((StructureFeatureInterface)structureFeature.feature).plopAnywhere(
|
||||
world, pos, world.getChunkManager().getChunkGenerator(),
|
||||
false, world.getRegistryManager().get(Registry.BIOME_KEY).get(BiomeKeys.PLAINS), structureFeature.config);
|
||||
world, pos, world.getChunkSource().getGenerator(),
|
||||
false, world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).get(Biomes.PLAINS), structureFeature.config);
|
||||
|
||||
}
|
||||
|
||||
ConfiguredFeature<?, ?> configuredFeature = world.getRegistryManager().get(Registry.CONFIGURED_FEATURE_KEY).get(id);
|
||||
ConfiguredFeature<?, ?> configuredFeature = world.registryAccess().registryOrThrow(Registry.CONFIGURED_FEATURE_REGISTRY).get(id);
|
||||
if (configuredFeature != null)
|
||||
{
|
||||
CarpetSettings.skipGenerationChecks.set(true);
|
||||
try
|
||||
{
|
||||
return configuredFeature.generate(world, world.getChunkManager().getChunkGenerator(), world.random, pos);
|
||||
return configuredFeature.place(world, world.getChunkSource().getGenerator(), world.random, pos);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -90,8 +91,8 @@ public class FeatureGenerator
|
||||
ConfiguredStructureFeature<?,?> configuredStandard = getDefaultFeature(structure, world, pos, true);
|
||||
if (configuredStandard != null)
|
||||
return ((StructureFeatureInterface)configuredStandard.feature).plopAnywhere(
|
||||
world, pos, world.getChunkManager().getChunkGenerator(),
|
||||
false, world.getRegistryManager().get(Registry.BIOME_KEY).get(BiomeKeys.PLAINS), configuredStandard.config);
|
||||
world, pos, world.getChunkSource().getGenerator(),
|
||||
false, world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).get(Biomes.PLAINS), configuredStandard.config);
|
||||
|
||||
}
|
||||
Feature<?> feature = Registry.FEATURE.get(id);
|
||||
@@ -103,7 +104,7 @@ public class FeatureGenerator
|
||||
CarpetSettings.skipGenerationChecks.set(true);
|
||||
try
|
||||
{
|
||||
return configuredStandard.generate(world, world.getChunkManager().getChunkGenerator(), world.random, pos);
|
||||
return configuredStandard.place(world, world.getChunkSource().getGenerator(), world.random, pos);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -114,27 +115,27 @@ public class FeatureGenerator
|
||||
return null;
|
||||
}
|
||||
|
||||
public static ConfiguredStructureFeature<?, ?> resolveConfiguredStructure(String name, ServerWorld world, BlockPos pos)
|
||||
public static ConfiguredStructureFeature<?, ?> resolveConfiguredStructure(String name, ServerLevel world, BlockPos pos)
|
||||
{
|
||||
Identifier id = new Identifier(name);
|
||||
ConfiguredStructureFeature<?, ?> configuredStructureFeature = world.getRegistryManager().get(Registry.CONFIGURED_STRUCTURE_FEATURE_KEY).get(id);
|
||||
ResourceLocation id = new ResourceLocation(name);
|
||||
ConfiguredStructureFeature<?, ?> configuredStructureFeature = world.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).get(id);
|
||||
if (configuredStructureFeature != null) return configuredStructureFeature;
|
||||
StructureFeature<?> structureFeature = Registry.STRUCTURE_FEATURE.get(id);
|
||||
if (structureFeature == null) return null;
|
||||
return getDefaultFeature(structureFeature, world, pos, true);
|
||||
}
|
||||
|
||||
synchronized public static Boolean plopGrid(ConfiguredStructureFeature<?, ?> structureFeature, ServerWorld world, BlockPos pos)
|
||||
synchronized public static Boolean plopGrid(ConfiguredStructureFeature<?, ?> structureFeature, ServerLevel world, BlockPos pos)
|
||||
{
|
||||
return ((StructureFeatureInterface)structureFeature.feature).plopAnywhere(
|
||||
world, pos, world.getChunkManager().getChunkGenerator(),
|
||||
true, BuiltinBiomes.PLAINS, structureFeature.config);
|
||||
world, pos, world.getChunkSource().getGenerator(),
|
||||
true, net.minecraft.data.worldgen.biome.Biomes.PLAINS, structureFeature.config);
|
||||
}
|
||||
|
||||
@FunctionalInterface
|
||||
private interface Thing
|
||||
{
|
||||
Boolean plop(ServerWorld world, BlockPos pos);
|
||||
Boolean plop(ServerLevel world, BlockPos pos);
|
||||
}
|
||||
private static Thing simplePlop(ConfiguredFeature feature)
|
||||
{
|
||||
@@ -142,7 +143,7 @@ public class FeatureGenerator
|
||||
CarpetSettings.skipGenerationChecks.set(true);
|
||||
try
|
||||
{
|
||||
return feature.generate(w, w.getChunkManager().getChunkGenerator(), w.random, p);
|
||||
return feature.place(w, w.getChunkSource().getGenerator(), w.random, p);
|
||||
}
|
||||
finally
|
||||
{
|
||||
@@ -151,45 +152,45 @@ public class FeatureGenerator
|
||||
};
|
||||
}
|
||||
|
||||
private static Thing simpleTree(TreeFeatureConfig config)
|
||||
private static Thing simpleTree(TreeConfiguration config)
|
||||
{
|
||||
//config.ignoreFluidCheck();
|
||||
return simplePlop(Feature.TREE.configure(config));
|
||||
return simplePlop(Feature.TREE.configured(config));
|
||||
}
|
||||
|
||||
private static Thing spawnCustomStructure(StructureFeature structure, FeatureConfig conf, RegistryKey<Biome> biome)
|
||||
private static Thing spawnCustomStructure(StructureFeature structure, FeatureConfiguration conf, ResourceKey<Biome> biome)
|
||||
{
|
||||
return setupCustomStructure(structure, conf, biome, false);
|
||||
}
|
||||
private static Thing setupCustomStructure(StructureFeature structure, FeatureConfig conf, RegistryKey<Biome> biome, boolean wireOnly)
|
||||
private static Thing setupCustomStructure(StructureFeature structure, FeatureConfiguration conf, ResourceKey<Biome> biome, boolean wireOnly)
|
||||
{
|
||||
return (w, p) -> ((StructureFeatureInterface)structure).plopAnywhere(w, p, w.getChunkManager().getChunkGenerator(), wireOnly, w.getRegistryManager().get(Registry.BIOME_KEY).get(biome), conf);
|
||||
return (w, p) -> ((StructureFeatureInterface)structure).plopAnywhere(w, p, w.getChunkSource().getGenerator(), wireOnly, w.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).get(biome), conf);
|
||||
}
|
||||
|
||||
public static Boolean spawn(String name, ServerWorld world, BlockPos pos)
|
||||
public static Boolean spawn(String name, ServerLevel world, BlockPos pos)
|
||||
{
|
||||
if (featureMap.containsKey(name))
|
||||
return featureMap.get(name).plop(world, pos);
|
||||
return null;
|
||||
}
|
||||
|
||||
private static ConfiguredStructureFeature<?, ?> getDefaultFeature(StructureFeature<?> structure, ServerWorld world, BlockPos pos, boolean tryHard)
|
||||
private static ConfiguredStructureFeature<?, ?> getDefaultFeature(StructureFeature<?> structure, ServerLevel world, BlockPos pos, boolean tryHard)
|
||||
{
|
||||
var definedStructures = world.getChunkManager().getChunkGenerator().getStructuresConfig().getConfiguredStructureFeature(structure);
|
||||
var optinalBiome = world.getRegistryManager().get(Registry.BIOME_KEY).getKey(world.getBiome(pos));
|
||||
var definedStructures = world.getChunkSource().getGenerator().getSettings().structures(structure);
|
||||
var optinalBiome = world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getResourceKey(world.getBiome(pos));
|
||||
if (optinalBiome.isPresent())
|
||||
for (var configureStructure: definedStructures.inverse().get(optinalBiome.get()))
|
||||
if (configureStructure.feature == structure)
|
||||
return configureStructure;
|
||||
if (!tryHard) return null;
|
||||
return world.getRegistryManager().get(Registry.CONFIGURED_STRUCTURE_FEATURE_KEY).getEntries().stream().
|
||||
return world.registryAccess().registryOrThrow(Registry.CONFIGURED_STRUCTURE_FEATURE_REGISTRY).entrySet().stream().
|
||||
filter(cS -> cS.getValue().feature == structure).
|
||||
findFirst().map(Map.Entry::getValue).orElse(null);
|
||||
}
|
||||
|
||||
private static ConfiguredFeature<?, ?> getDefaultFeature(Feature<?> feature, ServerWorld world, BlockPos pos, boolean tryHard)
|
||||
private static ConfiguredFeature<?, ?> getDefaultFeature(Feature<?> feature, ServerLevel world, BlockPos pos, boolean tryHard)
|
||||
{
|
||||
List<List<Supplier<PlacedFeature>>> configuredStepFeatures = world.getBiome(pos).getGenerationSettings().getFeatures();
|
||||
List<List<Supplier<PlacedFeature>>> configuredStepFeatures = world.getBiome(pos).getGenerationSettings().features();
|
||||
for (List<Supplier<PlacedFeature>> step: configuredStepFeatures)
|
||||
for (Supplier<PlacedFeature> provider: step)
|
||||
{
|
||||
@@ -198,38 +199,38 @@ public class FeatureGenerator
|
||||
return configuredFeature;
|
||||
}
|
||||
if (!tryHard) return null;
|
||||
return world.getRegistryManager().get(Registry.CONFIGURED_FEATURE_KEY).getEntries().stream().
|
||||
return world.registryAccess().registryOrThrow(Registry.CONFIGURED_FEATURE_REGISTRY).entrySet().stream().
|
||||
filter(cS -> cS.getValue().feature == feature).
|
||||
findFirst().map(Map.Entry::getValue).orElse(null);
|
||||
}
|
||||
|
||||
public static <T extends FeatureConfig> StructureStart shouldStructureStartAt(ServerWorld world, BlockPos pos, StructureFeature<T> structure, boolean computeBox)
|
||||
public static <T extends FeatureConfiguration> StructureStart shouldStructureStartAt(ServerLevel world, BlockPos pos, StructureFeature<T> structure, boolean computeBox)
|
||||
{
|
||||
if (structure == StructureFeature.STRONGHOLD)
|
||||
return shouldStrongholdStartAt(world, pos, computeBox);
|
||||
long seed = world.getSeed();
|
||||
ChunkGenerator generator = world.getChunkManager().getChunkGenerator();
|
||||
StructuresConfig settings = generator.getStructuresConfig();
|
||||
StructureConfig structureConfig = settings.getForType(structure);
|
||||
var structures = settings.getConfiguredStructureFeature(structure);
|
||||
ChunkGenerator generator = world.getChunkSource().getGenerator();
|
||||
StructureSettings settings = generator.getSettings();
|
||||
StructureFeatureConfiguration structureConfig = settings.getConfig(structure);
|
||||
var structures = settings.structures(structure);
|
||||
if (structureConfig == null || structures.isEmpty()) {
|
||||
return null;
|
||||
}
|
||||
ChunkPos chunkPos = new ChunkPos(pos);
|
||||
Biome biome = world.getBiome(pos);
|
||||
var biomeRegistry = world.getRegistryManager().get(Registry.BIOME_KEY);
|
||||
var biomeRegistry = world.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY);
|
||||
if (structures.values().stream().noneMatch(biomeKey -> biomeRegistry.get(biomeKey) == biome))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
ChunkPos chunkPos1 = structure.getStartChunk(structureConfig, seed, chunkPos.x, chunkPos.z);
|
||||
ChunkPos chunkPos1 = structure.getPotentialFeatureChunk(structureConfig, seed, chunkPos.x, chunkPos.z);
|
||||
if (!chunkPos1.equals(chunkPos))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
StructureAccessor structureManager = world.getStructureAccessor();
|
||||
StructurePresence isThere = structureManager.getStructurePresence(chunkPos, structure, false);
|
||||
if (isThere == StructurePresence.START_NOT_PRESENT)
|
||||
StructureFeatureManager structureManager = world.structureFeatureManager();
|
||||
StructureCheckResult isThere = structureManager.checkStructurePresence(chunkPos, structure, false);
|
||||
if (isThere == StructureCheckResult.START_NOT_PRESENT)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
@@ -238,100 +239,100 @@ public class FeatureGenerator
|
||||
//StructureStart<?> start = structureManager.getStructureStart(ChunkSectionPos.from(chunk), structure, chunk);
|
||||
//if (start != null && start.hasChildren())
|
||||
//{
|
||||
if (!computeBox) return StructureStart.DEFAULT;
|
||||
if (!computeBox) return StructureStart.INVALID_START;
|
||||
ConfiguredStructureFeature<?, ?> configuredFeature = getDefaultFeature(structure, world, pos, false);
|
||||
if (configuredFeature == null || configuredFeature.config == null) return null;
|
||||
var biomeConfig = structures.get(configuredFeature);
|
||||
StructureStart<?> filledStructure = configuredFeature.tryPlaceStart(world.getRegistryManager(), generator, generator.getBiomeSource(),
|
||||
world.getStructureManager(), seed, chunkPos, 0, structureConfig, world, (b) -> biomeRegistry.getKey(b).filter(biomeConfig::contains).isPresent());
|
||||
if (filledStructure != null && filledStructure.hasChildren())
|
||||
StructureStart<?> filledStructure = configuredFeature.generate(world.registryAccess(), generator, generator.getBiomeSource(),
|
||||
world.getStructureManager(), seed, chunkPos, 0, structureConfig, world, (b) -> biomeRegistry.getResourceKey(b).filter(biomeConfig::contains).isPresent());
|
||||
if (filledStructure != null && filledStructure.isValid())
|
||||
return filledStructure;
|
||||
return null;
|
||||
}
|
||||
|
||||
public static StructureStart<?> shouldStrongholdStartAt(ServerWorld world, BlockPos pos, boolean computeBox)
|
||||
public static StructureStart<?> shouldStrongholdStartAt(ServerLevel world, BlockPos pos, boolean computeBox)
|
||||
{
|
||||
ChunkGenerator generator = world.getChunkManager().getChunkGenerator();
|
||||
if (world.getRegistryKey() != World.OVERWORLD || !generator.isStrongholdStartingChunk(new ChunkPos(pos))) return null;
|
||||
if (!computeBox) return StructureStart.DEFAULT;
|
||||
StructuresConfig settings = generator.getStructuresConfig();
|
||||
StructureConfig structureConfig = settings.getForType(StructureFeature.STRONGHOLD);
|
||||
ChunkGenerator generator = world.getChunkSource().getGenerator();
|
||||
if (world.dimension() != Level.OVERWORLD || !generator.hasStronghold(new ChunkPos(pos))) return null;
|
||||
if (!computeBox) return StructureStart.INVALID_START;
|
||||
StructureSettings settings = generator.getSettings();
|
||||
StructureFeatureConfiguration structureConfig = settings.getConfig(StructureFeature.STRONGHOLD);
|
||||
if (structureConfig != null) {
|
||||
StructureStart<?> filledStructure = ConfiguredStructureFeatures.STRONGHOLD.tryPlaceStart(world.getRegistryManager(), generator, generator.getBiomeSource(),
|
||||
StructureStart<?> filledStructure = StructureFeatures.STRONGHOLD.generate(world.registryAccess(), generator, generator.getBiomeSource(),
|
||||
world.getStructureManager(), world.getSeed(), new ChunkPos(pos), 0,
|
||||
structureConfig, world, ((ChunkGeneratorInterface)generator)::canPlaceStrongholdInBiomeCM
|
||||
);
|
||||
if (filledStructure != null && filledStructure.hasChildren())
|
||||
if (filledStructure != null && filledStructure.isValid())
|
||||
return filledStructure;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private static TreeFeatureConfig.Builder createTree(Block block, Block block2, int i, int j, int k, int l) {
|
||||
return new TreeFeatureConfig.Builder(BlockStateProvider.of(block), new StraightTrunkPlacer(i, j, k), BlockStateProvider.of(block2), new BlobFoliagePlacer(ConstantIntProvider.create(l), ConstantIntProvider.create(0), 3), new TwoLayersFeatureSize(1, 0, 1));
|
||||
private static TreeConfiguration.TreeConfigurationBuilder createTree(Block block, Block block2, int i, int j, int k, int l) {
|
||||
return new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(block), new StraightTrunkPlacer(i, j, k), BlockStateProvider.simple(block2), new BlobFoliagePlacer(ConstantInt.of(l), ConstantInt.of(0), 3), new TwoLayersFeatureSize(1, 0, 1));
|
||||
}
|
||||
|
||||
public static final Map<String, Thing> featureMap = new HashMap<String, Thing>() {{
|
||||
|
||||
put("oak_bees", simpleTree( createTree(Blocks.OAK_LOG, Blocks.OAK_LEAVES, 4, 2, 0, 2).ignoreVines().decorators(List.of(new BeehiveTreeDecorator(1.00F))).build()));
|
||||
put("fancy_oak_bees", simpleTree( (new TreeFeatureConfig.Builder(BlockStateProvider.of(Blocks.OAK_LOG), new LargeOakTrunkPlacer(3, 11, 0), BlockStateProvider.of(Blocks.OAK_LEAVES), new LargeOakFoliagePlacer(ConstantIntProvider.create(2), ConstantIntProvider.create(4), 4), new TwoLayersFeatureSize(0, 0, 0, OptionalInt.of(4)))).ignoreVines().decorators(List.of(new BeehiveTreeDecorator(1.00F))).build()));
|
||||
put("birch_bees", simpleTree( createTree(Blocks.BIRCH_LOG, Blocks.BIRCH_LEAVES, 5, 2, 0, 2).ignoreVines().decorators(List.of(new BeehiveTreeDecorator(1.00F))).build()));
|
||||
put("oak_bees", simpleTree( createTree(Blocks.OAK_LOG, Blocks.OAK_LEAVES, 4, 2, 0, 2).ignoreVines().decorators(List.of(new BeehiveDecorator(1.00F))).build()));
|
||||
put("fancy_oak_bees", simpleTree( (new TreeConfiguration.TreeConfigurationBuilder(BlockStateProvider.simple(Blocks.OAK_LOG), new FancyTrunkPlacer(3, 11, 0), BlockStateProvider.simple(Blocks.OAK_LEAVES), new FancyFoliagePlacer(ConstantInt.of(2), ConstantInt.of(4), 4), new TwoLayersFeatureSize(0, 0, 0, OptionalInt.of(4)))).ignoreVines().decorators(List.of(new BeehiveDecorator(1.00F))).build()));
|
||||
put("birch_bees", simpleTree( createTree(Blocks.BIRCH_LOG, Blocks.BIRCH_LEAVES, 5, 2, 0, 2).ignoreVines().decorators(List.of(new BeehiveDecorator(1.00F))).build()));
|
||||
|
||||
put("coral_tree", simplePlop(Feature.CORAL_TREE.configure(FeatureConfig.DEFAULT)));
|
||||
put("coral_claw", simplePlop(Feature.CORAL_CLAW.configure(FeatureConfig.DEFAULT)));
|
||||
put("coral_mushroom", simplePlop(Feature.CORAL_MUSHROOM.configure(FeatureConfig.DEFAULT)));
|
||||
put("coral", simplePlop(Feature.SIMPLE_RANDOM_SELECTOR.configure(new SimpleRandomFeatureConfig(List.of(
|
||||
() -> Feature.CORAL_TREE.configure(FeatureConfig.DEFAULT).withPlacement(),
|
||||
() -> Feature.CORAL_CLAW.configure(FeatureConfig.DEFAULT).withPlacement(),
|
||||
() -> Feature.CORAL_MUSHROOM.configure(FeatureConfig.DEFAULT).withPlacement()
|
||||
put("coral_tree", simplePlop(Feature.CORAL_TREE.configured(FeatureConfiguration.NONE)));
|
||||
put("coral_claw", simplePlop(Feature.CORAL_CLAW.configured(FeatureConfiguration.NONE)));
|
||||
put("coral_mushroom", simplePlop(Feature.CORAL_MUSHROOM.configured(FeatureConfiguration.NONE)));
|
||||
put("coral", simplePlop(Feature.SIMPLE_RANDOM_SELECTOR.configured(new SimpleRandomFeatureConfiguration(List.of(
|
||||
() -> Feature.CORAL_TREE.configured(FeatureConfiguration.NONE).placed(),
|
||||
() -> Feature.CORAL_CLAW.configured(FeatureConfiguration.NONE).placed(),
|
||||
() -> Feature.CORAL_MUSHROOM.configured(FeatureConfiguration.NONE).placed()
|
||||
)))));
|
||||
put("bastion_remnant_units", spawnCustomStructure(
|
||||
StructureFeature.BASTION_REMNANT,
|
||||
new StructurePoolFeatureConfig(() -> new StructurePool(
|
||||
new Identifier("bastion/starts"),
|
||||
new Identifier("empty"),
|
||||
new JigsawConfiguration(() -> new StructureTemplatePool(
|
||||
new ResourceLocation("bastion/starts"),
|
||||
new ResourceLocation("empty"),
|
||||
List.of(
|
||||
Pair.of(StructurePoolElement.ofProcessedSingle("bastion/units/air_base", StructureProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
||||
Pair.of(StructurePoolElement.single("bastion/units/air_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
||||
),
|
||||
StructurePool.Projection.RIGID
|
||||
StructureTemplatePool.Projection.RIGID
|
||||
), 6),
|
||||
BiomeKeys.NETHER_WASTES
|
||||
Biomes.NETHER_WASTES
|
||||
));
|
||||
put("bastion_remnant_hoglin_stable", spawnCustomStructure(
|
||||
StructureFeature.BASTION_REMNANT,
|
||||
new StructurePoolFeatureConfig(() -> new StructurePool(
|
||||
new Identifier("bastion/starts"),
|
||||
new Identifier("empty"),
|
||||
new JigsawConfiguration(() -> new StructureTemplatePool(
|
||||
new ResourceLocation("bastion/starts"),
|
||||
new ResourceLocation("empty"),
|
||||
List.of(
|
||||
Pair.of(StructurePoolElement.ofProcessedSingle("bastion/hoglin_stable/air_base", StructureProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
||||
Pair.of(StructurePoolElement.single("bastion/hoglin_stable/air_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
||||
),
|
||||
StructurePool.Projection.RIGID
|
||||
StructureTemplatePool.Projection.RIGID
|
||||
), 6),
|
||||
BiomeKeys.NETHER_WASTES
|
||||
Biomes.NETHER_WASTES
|
||||
));
|
||||
put("bastion_remnant_treasure", spawnCustomStructure(
|
||||
StructureFeature.BASTION_REMNANT,
|
||||
new StructurePoolFeatureConfig(() -> new StructurePool(
|
||||
new Identifier("bastion/starts"),
|
||||
new Identifier("empty"),
|
||||
new JigsawConfiguration(() -> new StructureTemplatePool(
|
||||
new ResourceLocation("bastion/starts"),
|
||||
new ResourceLocation("empty"),
|
||||
List.of(
|
||||
Pair.of(StructurePoolElement.ofProcessedSingle("bastion/treasure/big_air_full", StructureProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
||||
Pair.of(StructurePoolElement.single("bastion/treasure/big_air_full", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
||||
),
|
||||
StructurePool.Projection.RIGID
|
||||
StructureTemplatePool.Projection.RIGID
|
||||
), 6),
|
||||
BiomeKeys.NETHER_WASTES
|
||||
Biomes.NETHER_WASTES
|
||||
));
|
||||
put("bastion_remnant_bridge", spawnCustomStructure(
|
||||
StructureFeature.BASTION_REMNANT,
|
||||
new StructurePoolFeatureConfig(() -> new StructurePool(
|
||||
new Identifier("bastion/starts"),
|
||||
new Identifier("empty"),
|
||||
new JigsawConfiguration(() -> new StructureTemplatePool(
|
||||
new ResourceLocation("bastion/starts"),
|
||||
new ResourceLocation("empty"),
|
||||
List.of(
|
||||
Pair.of(StructurePoolElement.ofProcessedSingle("bastion/bridge/starting_pieces/entrance_base", StructureProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
||||
Pair.of(StructurePoolElement.single("bastion/bridge/starting_pieces/entrance_base", ProcessorLists.BASTION_GENERIC_DEGRADATION), 1)
|
||||
),
|
||||
StructurePool.Projection.RIGID
|
||||
StructureTemplatePool.Projection.RIGID
|
||||
), 6),
|
||||
BiomeKeys.NETHER_WASTES
|
||||
Biomes.NETHER_WASTES
|
||||
));
|
||||
}};
|
||||
|
||||
|
||||
@@ -7,30 +7,29 @@ import carpet.utils.WoolTool;
|
||||
import carpet.utils.Messenger;
|
||||
import it.unimi.dsi.fastutil.objects.Object2LongLinkedOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2LongMap;
|
||||
import net.minecraft.block.AbstractBannerBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.MapColor;
|
||||
import net.minecraft.block.Stainable;
|
||||
import net.minecraft.item.BlockItem;
|
||||
import net.minecraft.item.DyeItem;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.recipe.Ingredient;
|
||||
import net.minecraft.recipe.Recipe;
|
||||
import net.minecraft.recipe.RecipeType;
|
||||
import net.minecraft.text.Style;
|
||||
import net.minecraft.text.TextColor;
|
||||
import net.minecraft.util.DyeColor;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.text.BaseText;
|
||||
import net.minecraft.text.TranslatableText;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.network.chat.BaseComponent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
import net.minecraft.network.chat.TextColor;
|
||||
import net.minecraft.network.chat.TranslatableComponent;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.util.Formatting;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.registry.Registry;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import net.minecraft.world.item.BlockItem;
|
||||
import net.minecraft.world.item.DyeColor;
|
||||
import net.minecraft.world.item.DyeItem;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.minecraft.world.item.crafting.Recipe;
|
||||
import net.minecraft.world.item.crafting.RecipeType;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.AbstractBannerBlock;
|
||||
import net.minecraft.world.level.block.BeaconBeamBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.material.MaterialColor;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
@@ -58,7 +57,7 @@ public class HopperCounter
|
||||
* The default display colour of each item, which makes them look nicer when printing the counter contents to the chat
|
||||
*/
|
||||
|
||||
public static final TextColor WHITE = TextColor.fromFormatting(Formatting.WHITE);
|
||||
public static final TextColor WHITE = TextColor.fromLegacyFormat(ChatFormatting.WHITE);
|
||||
|
||||
static
|
||||
{
|
||||
@@ -100,7 +99,7 @@ public class HopperCounter
|
||||
{
|
||||
startTick = -1;
|
||||
this.color = color;
|
||||
this.prettyColour = WoolTool.Material2DyeName.getOrDefault(color.getMapColor(),"w ") + color.getName();
|
||||
this.prettyColour = WoolTool.Material2DyeName.getOrDefault(color.getMaterialColor(),"w ") + color.getName();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -112,7 +111,7 @@ public class HopperCounter
|
||||
{
|
||||
if (startTick < 0)
|
||||
{
|
||||
startTick = server.getWorld(World.OVERWORLD).getTime(); //OW
|
||||
startTick = server.getLevel(Level.OVERWORLD).getGameTime(); //OW
|
||||
startMillis = System.currentTimeMillis();
|
||||
}
|
||||
Item item = stack.getItem();
|
||||
@@ -126,7 +125,7 @@ public class HopperCounter
|
||||
public void reset(MinecraftServer server)
|
||||
{
|
||||
counter.clear();
|
||||
startTick = server.getWorld(World.OVERWORLD).getTime(); //OW
|
||||
startTick = server.getLevel(Level.OVERWORLD).getGameTime(); //OW
|
||||
startMillis = System.currentTimeMillis();
|
||||
// pubSubProvider.publish();
|
||||
}
|
||||
@@ -147,13 +146,13 @@ public class HopperCounter
|
||||
/**
|
||||
* Prints all the counters to chat, nicely formatted, and you can choose whether to diplay in in game time or IRL time
|
||||
*/
|
||||
public static List<BaseText> formatAll(MinecraftServer server, boolean realtime)
|
||||
public static List<BaseComponent> formatAll(MinecraftServer server, boolean realtime)
|
||||
{
|
||||
List<BaseText> text = new ArrayList<>();
|
||||
List<BaseComponent> text = new ArrayList<>();
|
||||
|
||||
for (HopperCounter counter : COUNTERS.values())
|
||||
{
|
||||
List<BaseText> temp = counter.format(server, realtime, false);
|
||||
List<BaseComponent> temp = counter.format(server, realtime, false);
|
||||
if (temp.size() > 1)
|
||||
{
|
||||
if (!text.isEmpty()) text.add(Messenger.s(""));
|
||||
@@ -171,9 +170,9 @@ public class HopperCounter
|
||||
* Prints a single counter's contents and timings to chat, with the option to keep it short (so no item breakdown,
|
||||
* only rates). Again, realtime displays IRL time as opposed to in game time.
|
||||
*/
|
||||
public List<BaseText> format(MinecraftServer server, boolean realTime, boolean brief)
|
||||
public List<BaseComponent> format(MinecraftServer server, boolean realTime, boolean brief)
|
||||
{
|
||||
long ticks = Math.max(realTime ? (System.currentTimeMillis() - startMillis) / 50 : server.getWorld(World.OVERWORLD).getTime() - startTick, 1); //OW
|
||||
long ticks = Math.max(realTime ? (System.currentTimeMillis() - startMillis) / 50 : server.getLevel(Level.OVERWORLD).getGameTime() - startTick, 1); //OW
|
||||
if (startTick < 0 || ticks == 0)
|
||||
{
|
||||
if (brief)
|
||||
@@ -201,7 +200,7 @@ public class HopperCounter
|
||||
String.format("wb %.1f ", ticks / (20.0 * 60.0)), "w min"
|
||||
));
|
||||
}
|
||||
List<BaseText> items = new ArrayList<>();
|
||||
List<BaseComponent> items = new ArrayList<>();
|
||||
items.add(Messenger.c("w Items for ", prettyColour,
|
||||
"w (",String.format("wb %.2f", ticks*1.0/(20*60)), "w min"+(realTime?" - real time":"")+"), ",
|
||||
"w total: ", "wb "+total, "w , (",String.format("wb %.1f",total*1.0*(20*60*60)/ticks),"w /h):",
|
||||
@@ -210,7 +209,7 @@ public class HopperCounter
|
||||
items.addAll(counter.object2LongEntrySet().stream().sorted((e, f) -> Long.compare(f.getLongValue(), e.getLongValue())).map(e ->
|
||||
{
|
||||
Item item = e.getKey();
|
||||
BaseText itemName = new TranslatableText(item.getTranslationKey());
|
||||
BaseComponent itemName = new TranslatableComponent(item.getDescriptionId());
|
||||
Style itemStyle = itemName.getStyle();
|
||||
TextColor color = guessColor(item);
|
||||
itemName.setStyle((color != null) ? itemStyle.withColor(color) : itemStyle.withItalic(true));
|
||||
@@ -229,7 +228,7 @@ public class HopperCounter
|
||||
*/
|
||||
public static int appropriateColor(int color)
|
||||
{
|
||||
if (color == 0) return MapColor.WHITE.color;
|
||||
if (color == 0) return MaterialColor.SNOW.col;
|
||||
int r = (color >> 16 & 255);
|
||||
int g = (color >> 8 & 255);
|
||||
int b = (color & 255);
|
||||
@@ -334,23 +333,23 @@ public class HopperCounter
|
||||
*/
|
||||
public static TextColor fromItem(Item item)
|
||||
{
|
||||
if (DEFAULTS.containsKey(item)) return TextColor.fromRgb(appropriateColor(DEFAULTS.get(item).getDefaultMapColor().color));
|
||||
if (item instanceof DyeItem) return TextColor.fromRgb(appropriateColor(((DyeItem) item).getColor().getMapColor().color));
|
||||
if (DEFAULTS.containsKey(item)) return TextColor.fromRgb(appropriateColor(DEFAULTS.get(item).defaultMaterialColor().col));
|
||||
if (item instanceof DyeItem) return TextColor.fromRgb(appropriateColor(((DyeItem) item).getDyeColor().getMaterialColor().col));
|
||||
Block block = null;
|
||||
Identifier id = Registry.ITEM.getId(item);
|
||||
ResourceLocation id = Registry.ITEM.getKey(item);
|
||||
if (item instanceof BlockItem)
|
||||
{
|
||||
block = ((BlockItem) item).getBlock();
|
||||
}
|
||||
else if (Registry.BLOCK.getOrEmpty(id).isPresent())
|
||||
else if (Registry.BLOCK.getOptional(id).isPresent())
|
||||
{
|
||||
block = Registry.BLOCK.get(id);
|
||||
}
|
||||
if (block != null)
|
||||
{
|
||||
if (block instanceof AbstractBannerBlock) return TextColor.fromRgb(appropriateColor(((AbstractBannerBlock) block).getColor().getMapColor().color));
|
||||
if (block instanceof Stainable) return TextColor.fromRgb(appropriateColor( ((Stainable) block).getColor().getMapColor().color));
|
||||
return TextColor.fromRgb(appropriateColor( block.getDefaultMapColor().color));
|
||||
if (block instanceof AbstractBannerBlock) return TextColor.fromRgb(appropriateColor(((AbstractBannerBlock) block).getColor().getMaterialColor().col));
|
||||
if (block instanceof BeaconBeamBlock) return TextColor.fromRgb(appropriateColor( ((BeaconBeamBlock) block).getColor().getMaterialColor().col));
|
||||
return TextColor.fromRgb(appropriateColor( block.defaultMaterialColor().col));
|
||||
}
|
||||
return null;
|
||||
}
|
||||
@@ -364,7 +363,7 @@ public class HopperCounter
|
||||
TextColor direct = fromItem(item);
|
||||
if (direct != null) return direct;
|
||||
if (CarpetServer.minecraft_server == null) return WHITE;
|
||||
Identifier id = Registry.ITEM.getId(item);
|
||||
ResourceLocation id = Registry.ITEM.getKey(item);
|
||||
for (RecipeType<?> type: Registry.RECIPE_TYPE)
|
||||
{
|
||||
for (Recipe<?> r: ((RecipeManagerInterface) CarpetServer.minecraft_server.getRecipeManager()).getAllMatching(type, id))
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package carpet.helpers;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class InventoryHelper
|
||||
{
|
||||
@@ -23,12 +23,12 @@ public class InventoryHelper
|
||||
public static boolean cleanUpShulkerBoxTag(ItemStack stack)
|
||||
{
|
||||
boolean changed = false;
|
||||
NbtCompound tag = stack.getNbt();
|
||||
CompoundTag tag = stack.getTag();
|
||||
|
||||
if (tag == null || !tag.contains("BlockEntityTag", TAG_COMPOUND))
|
||||
return false;
|
||||
|
||||
NbtCompound bet = tag.getCompound("BlockEntityTag");
|
||||
CompoundTag bet = tag.getCompound("BlockEntityTag");
|
||||
if (bet.contains("Items", TAG_LIST) && bet.getList("Items", TAG_COMPOUND).isEmpty())
|
||||
{
|
||||
bet.remove("Items");
|
||||
@@ -42,7 +42,7 @@ public class InventoryHelper
|
||||
}
|
||||
if (tag.isEmpty())
|
||||
{
|
||||
stack.setNbt(null);
|
||||
stack.setTag(null);
|
||||
changed = true;
|
||||
}
|
||||
return changed;
|
||||
@@ -50,12 +50,12 @@ public class InventoryHelper
|
||||
|
||||
public static boolean shulkerBoxHasItems(ItemStack stack)
|
||||
{
|
||||
NbtCompound tag = stack.getNbt();
|
||||
CompoundTag tag = stack.getTag();
|
||||
|
||||
if (tag == null || !tag.contains("BlockEntityTag", TAG_COMPOUND))
|
||||
return false;
|
||||
|
||||
NbtCompound bet = tag.getCompound("BlockEntityTag");
|
||||
CompoundTag bet = tag.getCompound("BlockEntityTag");
|
||||
return bet.contains("Items", TAG_LIST) && !bet.getList("Items", TAG_COMPOUND).isEmpty();
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,32 @@ import java.text.NumberFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.LivingEntity;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
import net.minecraft.world.entity.item.PrimedTnt;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.ProtectionEnchantment;
|
||||
import net.minecraft.world.level.Explosion;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.level.chunk.ChunkAccess;
|
||||
import net.minecraft.world.level.material.FluidState;
|
||||
import net.minecraft.world.level.material.Material;
|
||||
import net.minecraft.world.level.storage.loot.LootContext;
|
||||
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import carpet.logging.logHelpers.ExplosionLogHelper;
|
||||
import carpet.mixins.ExplosionAccessor;
|
||||
import carpet.CarpetSettings;
|
||||
@@ -15,52 +40,25 @@ import it.unimi.dsi.fastutil.objects.Object2DoubleOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
|
||||
import it.unimi.dsi.fastutil.objects.ObjectOpenHashSet;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.Material;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.ItemEntity;
|
||||
import net.minecraft.entity.TntEntity;
|
||||
import net.minecraft.fluid.FluidState;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.world.explosion.Explosion;
|
||||
import net.minecraft.loot.context.LootContext;
|
||||
import net.minecraft.loot.context.LootContextParameters;
|
||||
import org.apache.commons.lang3.tuple.MutablePair;
|
||||
import org.apache.commons.lang3.tuple.Pair;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.enchantment.ProtectionEnchantment;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.Chunk;
|
||||
|
||||
import static carpet.script.CarpetEventServer.Event.EXPLOSION_OUTCOME;
|
||||
|
||||
public class OptimizedExplosion
|
||||
{
|
||||
private static List<Entity> entitylist;
|
||||
private static Vec3d vec3dmem;
|
||||
private static Vec3 vec3dmem;
|
||||
private static long tickmem;
|
||||
// For disabling the explosion particles and sound
|
||||
public static int explosionSound = 0;
|
||||
|
||||
// masa's optimizations
|
||||
private static Object2DoubleOpenHashMap<Pair<Vec3d, Box>> densityCache = new Object2DoubleOpenHashMap<>();
|
||||
private static MutablePair<Vec3d, Box> pairMutable = new MutablePair<>();
|
||||
private static Object2DoubleOpenHashMap<Pair<Vec3, AABB>> densityCache = new Object2DoubleOpenHashMap<>();
|
||||
private static MutablePair<Vec3, AABB> pairMutable = new MutablePair<>();
|
||||
private static Object2ObjectOpenHashMap<BlockPos, BlockState> stateCache = new Object2ObjectOpenHashMap<>();
|
||||
private static Object2ObjectOpenHashMap<BlockPos, FluidState> fluidCache = new Object2ObjectOpenHashMap<>();
|
||||
private static BlockPos.Mutable posMutable = new BlockPos.Mutable(0, 0, 0);
|
||||
private static BlockPos.MutableBlockPos posMutable = new BlockPos.MutableBlockPos(0, 0, 0);
|
||||
private static ObjectOpenHashSet<BlockPos> affectedBlockPositionsSet = new ObjectOpenHashSet<>();
|
||||
private static boolean firstRay;
|
||||
private static boolean rayCalcDone;
|
||||
@@ -74,7 +72,7 @@ public class OptimizedExplosion
|
||||
ExplosionAccessor eAccess = (ExplosionAccessor) e;
|
||||
|
||||
entityList.clear();
|
||||
boolean eventNeeded = EXPLOSION_OUTCOME.isNeeded() && !eAccess.getWorld().isClient();
|
||||
boolean eventNeeded = EXPLOSION_OUTCOME.isNeeded() && !eAccess.getLevel().isClientSide();
|
||||
blastCalc(e);
|
||||
|
||||
if (!CarpetSettings.explosionNoBlockDamage) {
|
||||
@@ -89,29 +87,29 @@ public class OptimizedExplosion
|
||||
stateCache.clear();
|
||||
fluidCache.clear();
|
||||
|
||||
e.getAffectedBlocks().addAll(affectedBlockPositionsSet);
|
||||
e.getToBlow().addAll(affectedBlockPositionsSet);
|
||||
affectedBlockPositionsSet.clear();
|
||||
}
|
||||
|
||||
float f3 = eAccess.getPower() * 2.0F;
|
||||
int k1 = MathHelper.floor(eAccess.getX() - (double) f3 - 1.0D);
|
||||
int l1 = MathHelper.floor(eAccess.getX() + (double) f3 + 1.0D);
|
||||
int i2 = MathHelper.floor(eAccess.getY() - (double) f3 - 1.0D);
|
||||
int i1 = MathHelper.floor(eAccess.getY() + (double) f3 + 1.0D);
|
||||
int j2 = MathHelper.floor(eAccess.getZ() - (double) f3 - 1.0D);
|
||||
int j1 = MathHelper.floor(eAccess.getZ() + (double) f3 + 1.0D);
|
||||
Vec3d vec3d = new Vec3d(eAccess.getX(), eAccess.getY(), eAccess.getZ());
|
||||
float f3 = eAccess.getRadius() * 2.0F;
|
||||
int k1 = Mth.floor(eAccess.getX() - (double) f3 - 1.0D);
|
||||
int l1 = Mth.floor(eAccess.getX() + (double) f3 + 1.0D);
|
||||
int i2 = Mth.floor(eAccess.getY() - (double) f3 - 1.0D);
|
||||
int i1 = Mth.floor(eAccess.getY() + (double) f3 + 1.0D);
|
||||
int j2 = Mth.floor(eAccess.getZ() - (double) f3 - 1.0D);
|
||||
int j1 = Mth.floor(eAccess.getZ() + (double) f3 + 1.0D);
|
||||
Vec3 vec3d = new Vec3(eAccess.getX(), eAccess.getY(), eAccess.getZ());
|
||||
|
||||
if (vec3dmem == null || !vec3dmem.equals(vec3d) || tickmem != eAccess.getWorld().getTime()) {
|
||||
if (vec3dmem == null || !vec3dmem.equals(vec3d) || tickmem != eAccess.getLevel().getGameTime()) {
|
||||
vec3dmem = vec3d;
|
||||
tickmem = eAccess.getWorld().getTime();
|
||||
entitylist = eAccess.getWorld().getOtherEntities(null, new Box(k1, i2, j2, l1, i1, j1));
|
||||
tickmem = eAccess.getLevel().getGameTime();
|
||||
entitylist = eAccess.getLevel().getEntities(null, new AABB(k1, i2, j2, l1, i1, j1));
|
||||
explosionSound = 0;
|
||||
}
|
||||
|
||||
explosionSound++;
|
||||
|
||||
Entity explodingEntity = eAccess.getEntity();
|
||||
Entity explodingEntity = eAccess.getSource();
|
||||
for (int k2 = 0; k2 < entitylist.size(); ++k2) {
|
||||
Entity entity = entitylist.get(k2);
|
||||
|
||||
@@ -123,23 +121,23 @@ public class OptimizedExplosion
|
||||
continue;
|
||||
}
|
||||
|
||||
if (entity instanceof TntEntity && explodingEntity != null &&
|
||||
if (entity instanceof PrimedTnt && explodingEntity != null &&
|
||||
entity.getX() == explodingEntity.getX() &&
|
||||
entity.getY() == explodingEntity.getY() &&
|
||||
entity.getZ() == explodingEntity.getZ()) {
|
||||
if (eLogger != null) {
|
||||
eLogger.onEntityImpacted(entity, new Vec3d(0,-0.9923437498509884d, 0));
|
||||
eLogger.onEntityImpacted(entity, new Vec3(0,-0.9923437498509884d, 0));
|
||||
}
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!entity.isImmuneToExplosion()) {
|
||||
double d12 = Math.sqrt(entity.squaredDistanceTo(eAccess.getX(), eAccess.getY(), eAccess.getZ())) / (double) f3;
|
||||
if (!entity.ignoreExplosion()) {
|
||||
double d12 = Math.sqrt(entity.distanceToSqr(eAccess.getX(), eAccess.getY(), eAccess.getZ())) / (double) f3;
|
||||
|
||||
if (d12 <= 1.0D) {
|
||||
double d5 = entity.getX() - eAccess.getX();
|
||||
// Change in 1.16 snapshots to fix a bug with TNT jumping
|
||||
double d7 = (entity instanceof TntEntity ? entity.getY() : entity.getEyeY()) - eAccess.getY();
|
||||
double d7 = (entity instanceof PrimedTnt ? entity.getY() : entity.getEyeY()) - eAccess.getY();
|
||||
double d9 = entity.getZ() - eAccess.getZ();
|
||||
double d13 = (double) Math.sqrt(d5 * d5 + d7 * d7 + d9 * d9);
|
||||
|
||||
@@ -155,8 +153,8 @@ public class OptimizedExplosion
|
||||
|
||||
if (density == Double.MAX_VALUE)
|
||||
{
|
||||
Pair<Vec3d, Box> pair = Pair.of(vec3d, entity.getBoundingBox());
|
||||
density = Explosion.getExposure(vec3d, entity);
|
||||
Pair<Vec3, AABB> pair = Pair.of(vec3d, entity.getBoundingBox());
|
||||
density = Explosion.getSeenPercent(vec3d, entity);
|
||||
densityCache.put(pair, density);
|
||||
}
|
||||
|
||||
@@ -166,25 +164,25 @@ public class OptimizedExplosion
|
||||
}
|
||||
|
||||
double d10 = (1.0D - d12) * density;
|
||||
entity.damage(e.getDamageSource(),
|
||||
entity.hurt(e.getDamageSource(),
|
||||
(float) ((int) ((d10 * d10 + d10) / 2.0D * 7.0D * (double) f3 + 1.0D)));
|
||||
double d11 = d10;
|
||||
|
||||
if (entity instanceof LivingEntity) {
|
||||
d11 = ProtectionEnchantment.transformExplosionKnockback((LivingEntity) entity, d10);
|
||||
d11 = ProtectionEnchantment.getExplosionKnockbackAfterDampener((LivingEntity) entity, d10);
|
||||
}
|
||||
|
||||
if (eLogger != null) {
|
||||
eLogger.onEntityImpacted(entity, new Vec3d(d5 * d11, d7 * d11, d9 * d11));
|
||||
eLogger.onEntityImpacted(entity, new Vec3(d5 * d11, d7 * d11, d9 * d11));
|
||||
}
|
||||
|
||||
entity.setVelocity(entity.getVelocity().add(d5 * d11, d7 * d11, d9 * d11));
|
||||
entity.setDeltaMovement(entity.getDeltaMovement().add(d5 * d11, d7 * d11, d9 * d11));
|
||||
|
||||
if (entity instanceof PlayerEntity player) {
|
||||
if (entity instanceof Player player) {
|
||||
|
||||
if (!player.isSpectator()
|
||||
&& (!player.isCreative() || !player.getAbilities().flying)) { //getAbilities
|
||||
e.getAffectedPlayers().put(player, new Vec3d(d5 * d10, d7 * d10, d9 * d10));
|
||||
e.getHitPlayers().put(player, new Vec3(d5 * d10, d7 * d10, d9 * d10));
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -198,27 +196,27 @@ public class OptimizedExplosion
|
||||
public static void doExplosionB(Explosion e, boolean spawnParticles)
|
||||
{
|
||||
ExplosionAccessor eAccess = (ExplosionAccessor) e;
|
||||
World world = eAccess.getWorld();
|
||||
Level world = eAccess.getLevel();
|
||||
double posX = eAccess.getX();
|
||||
double posY = eAccess.getY();
|
||||
double posZ = eAccess.getZ();
|
||||
|
||||
// If it is needed, calls scarpet event
|
||||
if (EXPLOSION_OUTCOME.isNeeded() && !world.isClient()) {
|
||||
EXPLOSION_OUTCOME.onExplosion((ServerWorld) world, eAccess.getEntity(), e::getCausingEntity, eAccess.getX(), eAccess.getY(), eAccess.getZ(), eAccess.getPower(), eAccess.isCreateFire(), e.getAffectedBlocks(), entityList, eAccess.getDestructionType());
|
||||
if (EXPLOSION_OUTCOME.isNeeded() && !world.isClientSide()) {
|
||||
EXPLOSION_OUTCOME.onExplosion((ServerLevel) world, eAccess.getSource(), e::getSourceMob, eAccess.getX(), eAccess.getY(), eAccess.getZ(), eAccess.getRadius(), eAccess.isFire(), e.getToBlow(), entityList, eAccess.getBlockInteraction());
|
||||
}
|
||||
|
||||
boolean damagesTerrain = eAccess.getDestructionType() != Explosion.DestructionType.NONE;
|
||||
boolean damagesTerrain = eAccess.getBlockInteraction() != Explosion.BlockInteraction.NONE;
|
||||
|
||||
// explosionSound incremented till disabling the explosion particles and sound
|
||||
if (explosionSound < 100 || explosionSound % 100 == 0)
|
||||
{
|
||||
world.playSound(null, posX, posY, posZ, SoundEvents.ENTITY_GENERIC_EXPLODE, SoundCategory.BLOCKS, 4.0F,
|
||||
world.playSound(null, posX, posY, posZ, SoundEvents.GENERIC_EXPLODE, SoundSource.BLOCKS, 4.0F,
|
||||
(1.0F + (world.random.nextFloat() - world.random.nextFloat()) * 0.2F) * 0.7F);
|
||||
|
||||
if (spawnParticles)
|
||||
{
|
||||
if (eAccess.getPower() >= 2.0F && damagesTerrain)
|
||||
if (eAccess.getRadius() >= 2.0F && damagesTerrain)
|
||||
{
|
||||
world.addParticle(ParticleTypes.EXPLOSION_EMITTER, posX, posY, posZ, 1.0D, 0.0D, 0.0D);
|
||||
}
|
||||
@@ -232,56 +230,56 @@ public class OptimizedExplosion
|
||||
if (damagesTerrain)
|
||||
{
|
||||
ObjectArrayList<Pair<ItemStack, BlockPos>> objectArrayList = new ObjectArrayList();
|
||||
Collections.shuffle(e.getAffectedBlocks(), world.random);
|
||||
Collections.shuffle(e.getToBlow(), world.random);
|
||||
|
||||
for (BlockPos blockpos : e.getAffectedBlocks())
|
||||
for (BlockPos blockpos : e.getToBlow())
|
||||
{
|
||||
BlockState state = world.getBlockState(blockpos);
|
||||
Block block = state.getBlock();
|
||||
|
||||
if (state.getMaterial() != Material.AIR)
|
||||
{
|
||||
if (block.shouldDropItemsOnExplosion(e) && world instanceof ServerWorld)
|
||||
if (block.dropFromExplosion(e) && world instanceof ServerLevel)
|
||||
{
|
||||
BlockEntity blockEntity = state.hasBlockEntity() ? world.getBlockEntity(blockpos) : null; //hasBlockEntity()
|
||||
|
||||
LootContext.Builder lootBuilder = (new LootContext.Builder((ServerWorld)eAccess.getWorld()))
|
||||
.random(eAccess.getWorld().random)
|
||||
.parameter(LootContextParameters.ORIGIN, Vec3d.ofCenter(blockpos))
|
||||
.parameter(LootContextParameters.TOOL, ItemStack.EMPTY)
|
||||
.optionalParameter(LootContextParameters.BLOCK_ENTITY, blockEntity)
|
||||
.optionalParameter(LootContextParameters.THIS_ENTITY, eAccess.getEntity());
|
||||
LootContext.Builder lootBuilder = (new LootContext.Builder((ServerLevel)eAccess.getLevel()))
|
||||
.withRandom(eAccess.getLevel().random)
|
||||
.withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(blockpos))
|
||||
.withParameter(LootContextParams.TOOL, ItemStack.EMPTY)
|
||||
.withOptionalParameter(LootContextParams.BLOCK_ENTITY, blockEntity)
|
||||
.withOptionalParameter(LootContextParams.THIS_ENTITY, eAccess.getSource());
|
||||
|
||||
if (eAccess.getDestructionType() == Explosion.DestructionType.DESTROY)
|
||||
lootBuilder.parameter(LootContextParameters.EXPLOSION_RADIUS, eAccess.getPower());
|
||||
if (eAccess.getBlockInteraction() == Explosion.BlockInteraction.DESTROY)
|
||||
lootBuilder.withParameter(LootContextParams.EXPLOSION_RADIUS, eAccess.getRadius());
|
||||
|
||||
state.getDroppedStacks(lootBuilder).forEach((itemStackx) -> {
|
||||
method_24023(objectArrayList, itemStackx, blockpos.toImmutable());
|
||||
state.getDrops(lootBuilder).forEach((itemStackx) -> {
|
||||
method_24023(objectArrayList, itemStackx, blockpos.immutable());
|
||||
});
|
||||
}
|
||||
|
||||
world.setBlockState(blockpos, Blocks.AIR.getDefaultState(), 3);
|
||||
block.onDestroyedByExplosion(world, blockpos, e);
|
||||
world.setBlock(blockpos, Blocks.AIR.defaultBlockState(), 3);
|
||||
block.wasExploded(world, blockpos, e);
|
||||
}
|
||||
}
|
||||
objectArrayList.forEach(p -> Block.dropStack(world, p.getRight(), p.getLeft()));
|
||||
objectArrayList.forEach(p -> Block.popResource(world, p.getRight(), p.getLeft()));
|
||||
|
||||
}
|
||||
|
||||
if (eAccess.isCreateFire())
|
||||
if (eAccess.isFire())
|
||||
{
|
||||
for (BlockPos blockpos1 : e.getAffectedBlocks())
|
||||
for (BlockPos blockpos1 : e.getToBlow())
|
||||
{
|
||||
// Use the same Chunk reference because the positions are in the same xz-column
|
||||
Chunk chunk = world.getChunk(blockpos1.getX() >> 4, blockpos1.getZ() >> 4);
|
||||
ChunkAccess chunk = world.getChunk(blockpos1.getX() >> 4, blockpos1.getZ() >> 4);
|
||||
|
||||
BlockPos down = blockpos1.down(1);
|
||||
BlockPos down = blockpos1.below(1);
|
||||
if (eAccess.getRandom().nextInt(3) == 0 &&
|
||||
chunk.getBlockState(blockpos1).getMaterial() == Material.AIR &&
|
||||
chunk.getBlockState(down).isOpaqueFullCube(world, down)
|
||||
chunk.getBlockState(down).isSolidRender(world, down)
|
||||
)
|
||||
{
|
||||
world.setBlockState(blockpos1, Blocks.FIRE.getDefaultState());
|
||||
world.setBlockAndUpdate(blockpos1, Blocks.FIRE.defaultBlockState());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -295,7 +293,7 @@ public class OptimizedExplosion
|
||||
for(int j = 0; j < i; ++j) {
|
||||
Pair<ItemStack, BlockPos> pair = (Pair)objectArrayList.get(j);
|
||||
ItemStack itemStack2 = pair.getLeft();
|
||||
if (ItemEntity.canMerge(itemStack2, itemStack)) {
|
||||
if (ItemEntity.areMergable(itemStack2, itemStack)) {
|
||||
ItemStack itemStack3 = ItemEntity.merge(itemStack2, itemStack, 16);
|
||||
objectArrayList.set(j, Pair.of(itemStack3, pair.getRight()));
|
||||
if (itemStack.isEmpty()) {
|
||||
@@ -328,29 +326,29 @@ public class OptimizedExplosion
|
||||
d0 = d0 / d3;
|
||||
d1 = d1 / d3;
|
||||
d2 = d2 / d3;
|
||||
float rand = eAccess.getWorld().random.nextFloat();
|
||||
float rand = eAccess.getLevel().random.nextFloat();
|
||||
if (CarpetSettings.tntRandomRange >= 0) {
|
||||
rand = (float) CarpetSettings.tntRandomRange;
|
||||
}
|
||||
float f = eAccess.getPower() * (0.7F + rand * 0.6F);
|
||||
float f = eAccess.getRadius() * (0.7F + rand * 0.6F);
|
||||
double d4 = eAccess.getX();
|
||||
double d6 = eAccess.getY();
|
||||
double d8 = eAccess.getZ();
|
||||
|
||||
for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
|
||||
BlockPos blockpos = new BlockPos(d4, d6, d8);
|
||||
BlockState state = eAccess.getWorld().getBlockState(blockpos);
|
||||
FluidState fluidState = eAccess.getWorld().getFluidState(blockpos);
|
||||
BlockState state = eAccess.getLevel().getBlockState(blockpos);
|
||||
FluidState fluidState = eAccess.getLevel().getFluidState(blockpos);
|
||||
|
||||
if (state.getMaterial() != Material.AIR) {
|
||||
float f2 = Math.max(state.getBlock().getBlastResistance(), fluidState.getBlastResistance());
|
||||
if (eAccess.getEntity() != null)
|
||||
f2 = eAccess.getEntity().getEffectiveExplosionResistance(e, eAccess.getWorld(), blockpos, state, fluidState, f2);
|
||||
float f2 = Math.max(state.getBlock().getExplosionResistance(), fluidState.getExplosionResistance());
|
||||
if (eAccess.getSource() != null)
|
||||
f2 = eAccess.getSource().getBlockExplosionResistance(e, eAccess.getLevel(), blockpos, state, fluidState, f2);
|
||||
f -= (f2 + 0.3F) * 0.3F;
|
||||
}
|
||||
|
||||
if (f > 0.0F && (eAccess.getEntity() == null ||
|
||||
eAccess.getEntity().canExplosionDestroyBlock(e, eAccess.getWorld(), blockpos, state, f)))
|
||||
if (f > 0.0F && (eAccess.getSource() == null ||
|
||||
eAccess.getSource().shouldBlockExplode(e, eAccess.getLevel(), blockpos, state, f)))
|
||||
{
|
||||
affectedBlockPositionsSet.add(blockpos);
|
||||
}
|
||||
@@ -446,9 +444,9 @@ public class OptimizedExplosion
|
||||
double xInc = (xRel / len) * 0.3;
|
||||
double yInc = (yRel / len) * 0.3;
|
||||
double zInc = (zRel / len) * 0.3;
|
||||
float rand = eAccess.getWorld().random.nextFloat();
|
||||
float rand = eAccess.getLevel().random.nextFloat();
|
||||
float sizeRand = (CarpetSettings.tntRandomRange >= 0 ? (float) CarpetSettings.tntRandomRange : rand);
|
||||
float size = eAccess.getPower() * (0.7F + sizeRand * 0.6F);
|
||||
float size = eAccess.getRadius() * (0.7F + sizeRand * 0.6F);
|
||||
double posX = eAccess.getX();
|
||||
double posY = eAccess.getY();
|
||||
double posZ = eAccess.getZ();
|
||||
@@ -464,20 +462,20 @@ public class OptimizedExplosion
|
||||
|
||||
if (state == null)
|
||||
{
|
||||
posImmutable = posMutable.toImmutable();
|
||||
state = eAccess.getWorld().getBlockState(posImmutable);
|
||||
posImmutable = posMutable.immutable();
|
||||
state = eAccess.getLevel().getBlockState(posImmutable);
|
||||
stateCache.put(posImmutable, state);
|
||||
fluid = eAccess.getWorld().getFluidState(posImmutable);
|
||||
fluid = eAccess.getLevel().getFluidState(posImmutable);
|
||||
fluidCache.put(posImmutable, fluid);
|
||||
}
|
||||
|
||||
if (state.getMaterial() != Material.AIR)
|
||||
{
|
||||
float resistance = Math.max(state.getBlock().getBlastResistance(), fluid.getBlastResistance());
|
||||
float resistance = Math.max(state.getBlock().getExplosionResistance(), fluid.getExplosionResistance());
|
||||
|
||||
if (eAccess.getEntity() != null)
|
||||
if (eAccess.getSource() != null)
|
||||
{
|
||||
resistance = eAccess.getEntity().getEffectiveExplosionResistance(e, eAccess.getWorld(), posMutable, state, fluid, resistance);
|
||||
resistance = eAccess.getSource().getBlockExplosionResistance(e, eAccess.getLevel(), posMutable, state, fluid, resistance);
|
||||
}
|
||||
|
||||
size -= (resistance + 0.3F) * 0.3F;
|
||||
@@ -485,8 +483,8 @@ public class OptimizedExplosion
|
||||
|
||||
if (size > 0.0F)
|
||||
{
|
||||
if ((eAccess.getEntity() == null || eAccess.getEntity().canExplosionDestroyBlock(e, eAccess.getWorld(), posMutable, state, size)))
|
||||
affectedBlockPositionsSet.add(posImmutable != null ? posImmutable : posMutable.toImmutable());
|
||||
if ((eAccess.getSource() == null || eAccess.getSource().shouldBlockExplode(e, eAccess.getLevel(), posMutable, state, size)))
|
||||
affectedBlockPositionsSet.add(posImmutable != null ? posImmutable : posMutable.immutable());
|
||||
}
|
||||
else if (firstRay)
|
||||
{
|
||||
@@ -510,7 +508,7 @@ public class OptimizedExplosion
|
||||
|
||||
private static void blastCalc(Explosion e){
|
||||
ExplosionAccessor eAccess = (ExplosionAccessor) e;
|
||||
if(blastChanceLocation == null || blastChanceLocation.getSquaredDistance(eAccess.getX(), eAccess.getY(), eAccess.getZ(), false) > 200) return;
|
||||
if(blastChanceLocation == null || blastChanceLocation.distSqr(eAccess.getX(), eAccess.getY(), eAccess.getZ(), false) > 200) return;
|
||||
chances.clear();
|
||||
for (int j = 0; j < 16; ++j) {
|
||||
for (int k = 0; k < 16; ++k) {
|
||||
@@ -523,7 +521,7 @@ public class OptimizedExplosion
|
||||
d0 = d0 / d3;
|
||||
d1 = d1 / d3;
|
||||
d2 = d2 / d3;
|
||||
float f = eAccess.getPower() * (0.7F + 0.6F);
|
||||
float f = eAccess.getRadius() * (0.7F + 0.6F);
|
||||
double d4 = eAccess.getX();
|
||||
double d6 = eAccess.getY();
|
||||
double d8 = eAccess.getZ();
|
||||
@@ -531,18 +529,18 @@ public class OptimizedExplosion
|
||||
|
||||
for (float f1 = 0.3F; f > 0.0F; f -= 0.22500001F) {
|
||||
BlockPos blockpos = new BlockPos(d4, d6, d8);
|
||||
BlockState state = eAccess.getWorld().getBlockState(blockpos);
|
||||
FluidState fluidState = eAccess.getWorld().getFluidState(blockpos);
|
||||
BlockState state = eAccess.getLevel().getBlockState(blockpos);
|
||||
FluidState fluidState = eAccess.getLevel().getFluidState(blockpos);
|
||||
|
||||
if (state.getMaterial() != Material.AIR) {
|
||||
float f2 = Math.max(state.getBlock().getBlastResistance(), fluidState.getBlastResistance());
|
||||
if (eAccess.getEntity() != null)
|
||||
f2 = eAccess.getEntity().getEffectiveExplosionResistance(e, eAccess.getWorld(), blockpos, state, fluidState, f2);
|
||||
float f2 = Math.max(state.getBlock().getExplosionResistance(), fluidState.getExplosionResistance());
|
||||
if (eAccess.getSource() != null)
|
||||
f2 = eAccess.getSource().getBlockExplosionResistance(e, eAccess.getLevel(), blockpos, state, fluidState, f2);
|
||||
f -= (f2 + 0.3F) * 0.3F;
|
||||
}
|
||||
|
||||
if (f > 0.0F && (eAccess.getEntity() == null ||
|
||||
eAccess.getEntity().canExplosionDestroyBlock(e, eAccess.getWorld(), blockpos, state, f))) {
|
||||
if (f > 0.0F && (eAccess.getSource() == null ||
|
||||
eAccess.getSource().shouldBlockExplode(e, eAccess.getLevel(), blockpos, state, f))) {
|
||||
if(!found && blockpos.equals(blastChanceLocation)){
|
||||
chances.add(f);
|
||||
found = true;
|
||||
@@ -563,7 +561,7 @@ public class OptimizedExplosion
|
||||
|
||||
private static void showTNTblastChance(Explosion e){
|
||||
ExplosionAccessor eAccess = (ExplosionAccessor) e;
|
||||
double randMax = 0.6F * eAccess.getPower();
|
||||
double randMax = 0.6F * eAccess.getRadius();
|
||||
double total = 0;
|
||||
boolean fullyBlownUp = false;
|
||||
boolean first = true;
|
||||
@@ -587,7 +585,7 @@ public class OptimizedExplosion
|
||||
NumberFormat nf = NumberFormat.getNumberInstance();
|
||||
nf.setRoundingMode (RoundingMode.DOWN);
|
||||
nf.setMaximumFractionDigits(2);
|
||||
for(PlayerEntity player : eAccess.getWorld().getPlayers()){
|
||||
for(Player player : eAccess.getLevel().players()){
|
||||
Messenger.m(player,"w Pop: ",
|
||||
"c " + nf.format(chance) + " ",
|
||||
"^w Chance for the block to be destroyed by the blast: " + chance,
|
||||
@@ -601,9 +599,9 @@ public class OptimizedExplosion
|
||||
"^w TNT blast rays going through the block",
|
||||
"?" + rays,
|
||||
"w Size: ",
|
||||
String.format("c %.1f ", eAccess.getPower()),
|
||||
String.format("c %.1f ", eAccess.getRadius()),
|
||||
"^w TNT blast size",
|
||||
"?" + eAccess.getPower(),
|
||||
"?" + eAccess.getRadius(),
|
||||
"w @: ",
|
||||
String.format("c [%.1f %.1f %.1f] ", eAccess.getX(), eAccess.getY(), eAccess.getZ()),
|
||||
"^w TNT blast location X:" + eAccess.getX() + " Y:" + eAccess.getY() + " Z:" + eAccess.getZ(),
|
||||
|
||||
@@ -2,61 +2,60 @@ package carpet.helpers;
|
||||
|
||||
import com.mojang.brigadier.StringReader;
|
||||
import com.mojang.brigadier.exceptions.CommandSyntaxException;
|
||||
import net.minecraft.command.argument.ParticleEffectArgumentType;
|
||||
import net.minecraft.particle.ParticleEffect;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import net.minecraft.commands.arguments.ParticleArgument;
|
||||
import net.minecraft.core.particles.ParticleOptions;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class ParticleDisplay
|
||||
{
|
||||
private static Map<String, ParticleEffect> particleCache = new HashMap<>();
|
||||
private static Map<String, ParticleOptions> particleCache = new HashMap<>();
|
||||
|
||||
private static ParticleEffect parseParticle(String name)
|
||||
private static ParticleOptions parseParticle(String name)
|
||||
{
|
||||
try
|
||||
{
|
||||
return ParticleEffectArgumentType.readParameters(new StringReader(name));
|
||||
return ParticleArgument.readParticle(new StringReader(name));
|
||||
}
|
||||
catch (CommandSyntaxException e)
|
||||
{
|
||||
throw new RuntimeException("No such particle: "+name);
|
||||
}
|
||||
}
|
||||
public static ParticleEffect getEffect(String name)
|
||||
public static ParticleOptions getEffect(String name)
|
||||
{
|
||||
if (name == null) return null;
|
||||
ParticleEffect res = particleCache.get(name);
|
||||
ParticleOptions res = particleCache.get(name);
|
||||
if (res != null) return res;
|
||||
particleCache.put(name, parseParticle(name));
|
||||
return particleCache.get(name);
|
||||
}
|
||||
|
||||
public static void drawParticleLine(ServerPlayerEntity player, Vec3d from, Vec3d to, String main, String accent, int count, double spread)
|
||||
public static void drawParticleLine(ServerPlayer player, Vec3 from, Vec3 to, String main, String accent, int count, double spread)
|
||||
{
|
||||
ParticleEffect accentParticle = getEffect(accent);
|
||||
ParticleEffect mainParticle = getEffect(main);
|
||||
ParticleOptions accentParticle = getEffect(accent);
|
||||
ParticleOptions mainParticle = getEffect(main);
|
||||
|
||||
if (accentParticle != null) ((ServerWorld)player.world).spawnParticles(
|
||||
if (accentParticle != null) ((ServerLevel)player.level).sendParticles(
|
||||
player,
|
||||
accentParticle,
|
||||
true,
|
||||
to.x, to.y, to.z, count,
|
||||
spread, spread, spread, 0.0);
|
||||
|
||||
double lineLengthSq = from.squaredDistanceTo(to);
|
||||
double lineLengthSq = from.distanceToSqr(to);
|
||||
if (lineLengthSq == 0) return;
|
||||
|
||||
Vec3d incvec = to.subtract(from).normalize();// multiply(50/sqrt(lineLengthSq));
|
||||
Vec3 incvec = to.subtract(from).normalize();// multiply(50/sqrt(lineLengthSq));
|
||||
int pcount = 0;
|
||||
for (Vec3d delta = new Vec3d(0.0,0.0,0.0);
|
||||
delta.lengthSquared()<lineLengthSq;
|
||||
delta = delta.add(incvec.multiply(player.world.random.nextFloat())))
|
||||
for (Vec3 delta = new Vec3(0.0,0.0,0.0);
|
||||
delta.lengthSqr()<lineLengthSq;
|
||||
delta = delta.add(incvec.scale(player.level.random.nextFloat())))
|
||||
{
|
||||
((ServerWorld)player.world).spawnParticles(
|
||||
((ServerLevel)player.level).sendParticles(
|
||||
player,
|
||||
mainParticle,
|
||||
true,
|
||||
|
||||
@@ -6,14 +6,13 @@ import java.util.ArrayList;
|
||||
import java.util.Map;
|
||||
import java.util.HashMap;
|
||||
import java.util.concurrent.ThreadLocalRandom;
|
||||
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.Blocks;
|
||||
import net.minecraft.world.level.block.RedStoneWireBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import carpet.fakes.RedstoneWireBlockInterface;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.RedstoneWireBlock;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class RedstoneWireTurbo
|
||||
{
|
||||
@@ -79,7 +78,7 @@ public class RedstoneWireTurbo
|
||||
|
||||
|
||||
/* Reference to RedstoneWireBlock object, which uses this accelerator */
|
||||
private final RedstoneWireBlock wire;
|
||||
private final RedStoneWireBlock wire;
|
||||
|
||||
|
||||
/*
|
||||
@@ -115,7 +114,7 @@ public class RedstoneWireTurbo
|
||||
private List<UpdateNode> updateQueue2 = new ArrayList<>();
|
||||
|
||||
|
||||
public RedstoneWireTurbo(RedstoneWireBlock wire) {
|
||||
public RedstoneWireTurbo(RedStoneWireBlock wire) {
|
||||
this.wire = wire;
|
||||
}
|
||||
|
||||
@@ -294,7 +293,7 @@ public class RedstoneWireTurbo
|
||||
/*
|
||||
* For a newly created UpdateNode object, determine what type of block it is.
|
||||
*/
|
||||
private void identifyNode(final World worldIn, final UpdateNode upd1) {
|
||||
private void identifyNode(final Level worldIn, final UpdateNode upd1) {
|
||||
final BlockPos pos = upd1.self;
|
||||
final BlockState oldState = worldIn.getBlockState(pos);
|
||||
upd1.currentState = oldState;
|
||||
@@ -321,9 +320,9 @@ public class RedstoneWireTurbo
|
||||
// others are processed internally by the breadth first search
|
||||
// algorithm. To preserve this game behavior, this check must
|
||||
// be replicated here.
|
||||
if (!oldState.canPlaceAt(worldIn, pos)) {
|
||||
if (!oldState.canSurvive(worldIn, pos)) {
|
||||
// Pop off the redstone dust
|
||||
Block.dropStacks(oldState, worldIn, pos);
|
||||
Block.dropResources(oldState, worldIn, pos);
|
||||
worldIn.removeBlock(pos, false);
|
||||
|
||||
// Mark this position as not being redstone wire
|
||||
@@ -417,7 +416,7 @@ public class RedstoneWireTurbo
|
||||
/*
|
||||
* Process a node whose neighboring redstone wire has experienced value changes.
|
||||
*/
|
||||
private void updateNode(final World worldIn, final UpdateNode upd1, final int layer) {
|
||||
private void updateNode(final Level worldIn, final UpdateNode upd1, final int layer) {
|
||||
final BlockPos pos = upd1.self;
|
||||
|
||||
// Mark this redstone wire as having been visited so that it can be used
|
||||
@@ -462,7 +461,7 @@ public class RedstoneWireTurbo
|
||||
* what nodes in the redstone wire graph have been visited, the neighbors
|
||||
* are reordered left-to-right relative to the direction of information flow.
|
||||
*/
|
||||
private void findNeighbors(final World worldIn, final UpdateNode upd1) {
|
||||
private void findNeighbors(final Level worldIn, final UpdateNode upd1) {
|
||||
final BlockPos pos = upd1.self;
|
||||
|
||||
// Get the list of neighbor coordinates
|
||||
@@ -553,7 +552,7 @@ public class RedstoneWireTurbo
|
||||
* For any redstone wire block in layer N, inform neighbors to recompute their states
|
||||
* in layers N+1 and N+2;
|
||||
*/
|
||||
private void propagateChanges(final World worldIn, final UpdateNode upd1, final int layer) {
|
||||
private void propagateChanges(final Level worldIn, final UpdateNode upd1, final int layer) {
|
||||
if (upd1.neighbor_nodes == null) {
|
||||
// If this node has not been expanded yet, find its neigbors
|
||||
findNeighbors(worldIn, upd1);
|
||||
@@ -627,7 +626,7 @@ public class RedstoneWireTurbo
|
||||
* that is a function of distance from the initial call to
|
||||
* this.neighborChanged.
|
||||
*/
|
||||
private void breadthFirstWalk(final World worldIn) {
|
||||
private void breadthFirstWalk(final Level worldIn) {
|
||||
shiftQueue();
|
||||
currentWalkLayer = 1;
|
||||
|
||||
@@ -663,7 +662,7 @@ public class RedstoneWireTurbo
|
||||
// already keeping track of all of the neighbor positions
|
||||
// that need to be updated. All on its own, handling neighbors
|
||||
// this way reduces block updates by 1/3 (24 instead of 36).
|
||||
worldIn.updateNeighbor(upd.self, wire, upd.parent);
|
||||
worldIn.neighborChanged(upd.self, wire, upd.parent);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -701,7 +700,7 @@ public class RedstoneWireTurbo
|
||||
* order to continue processing both the first and second wire in the order of distance from the initial
|
||||
* trigger.
|
||||
*/
|
||||
private BlockState scheduleReentrantNeighborChanged(final World worldIn, final BlockPos pos, final BlockState newState, final BlockPos source)
|
||||
private BlockState scheduleReentrantNeighborChanged(final Level worldIn, final BlockPos pos, final BlockState newState, final BlockPos source)
|
||||
{
|
||||
if (source != null) {
|
||||
// If the cause of the redstone wire update is known, we can use that to help determine
|
||||
@@ -762,7 +761,7 @@ public class RedstoneWireTurbo
|
||||
* few other methods in RedstoneWireBlock. This sets off the breadth-first
|
||||
* walk through all redstone dust connected to the initial position triggered.
|
||||
*/
|
||||
public BlockState updateSurroundingRedstone(final World worldIn, final BlockPos pos, final BlockState state, final BlockPos source)
|
||||
public BlockState updateSurroundingRedstone(final Level worldIn, final BlockPos pos, final BlockState state, final BlockPos source)
|
||||
{
|
||||
// Check this block's neighbors and see if its power level needs to change
|
||||
// Use the calculateCurrentChanges method in RedstoneWireBlock since we have no
|
||||
@@ -832,10 +831,10 @@ public class RedstoneWireTurbo
|
||||
* the UpdateNode's neighbor array to find the redstone states of neighbors
|
||||
* that might power it.
|
||||
*/
|
||||
private BlockState calculateCurrentChanges(final World worldIn, final UpdateNode upd)
|
||||
private BlockState calculateCurrentChanges(final Level worldIn, final UpdateNode upd)
|
||||
{
|
||||
BlockState state = upd.currentState;
|
||||
final int i = state.get(RedstoneWireBlock.POWER);
|
||||
final int i = state.getValue(RedStoneWireBlock.POWER);
|
||||
int j = 0;
|
||||
j = getMaxCurrentStrength(upd, j);
|
||||
int l = 0;
|
||||
@@ -846,7 +845,7 @@ public class RedstoneWireTurbo
|
||||
// elsewhere in Minecraft into this accelerator. So sadly, we must
|
||||
// suffer the performance hit of this very expensive call. If there
|
||||
// is consistency to what this call returns, we may be able to cache it.
|
||||
final int k = worldIn.getReceivedRedstonePower(upd.self);
|
||||
final int k = worldIn.getBestNeighborSignal(upd.self);
|
||||
((RedstoneWireBlockInterface)wire).setWiresGivePower(true);
|
||||
|
||||
// The variable 'k' holds the maximum redstone power value of any adjacent blocks.
|
||||
@@ -865,7 +864,7 @@ public class RedstoneWireTurbo
|
||||
// position directly above the node being calculated is always
|
||||
// at index 1.
|
||||
UpdateNode center_up = upd.neighbor_nodes[1];
|
||||
boolean center_up_is_cube = center_up.currentState.isSolidBlock(worldIn, center_up.self); //isSimpleFUllBLock
|
||||
boolean center_up_is_cube = center_up.currentState.isRedstoneConductor(worldIn, center_up.self); //isSimpleFUllBLock
|
||||
|
||||
for (int m=0; m<4; m++) {
|
||||
// Get the neighbor array index of each of the four cardinal
|
||||
@@ -879,7 +878,7 @@ public class RedstoneWireTurbo
|
||||
|
||||
// Also check the positions above and below the cardinal
|
||||
// neighbors
|
||||
boolean neighbor_is_cube = neighbor.currentState.isSolidBlock(worldIn, neighbor.self); //isSimpleFUllBLock
|
||||
boolean neighbor_is_cube = neighbor.currentState.isRedstoneConductor(worldIn, neighbor.self); //isSimpleFUllBLock
|
||||
if (!neighbor_is_cube) {
|
||||
UpdateNode neighbor_down = upd.neighbor_nodes[rs_neighbors_dn[m]];
|
||||
l = getMaxCurrentStrength(neighbor_down, l);
|
||||
@@ -905,11 +904,11 @@ public class RedstoneWireTurbo
|
||||
// and set it in the world.
|
||||
// Possible optimization: Don't commit state changes to the world until they
|
||||
// need to be known by some nearby non-redstone-wire block.
|
||||
state = state.with(RedstoneWireBlock.POWER, j);
|
||||
state = state.setValue(RedStoneWireBlock.POWER, j);
|
||||
// [gnembon] added state check cause other things in the tick may have popped it up already
|
||||
// https://github.com/gnembon/fabric-carpet/issues/117
|
||||
if (worldIn.getBlockState(upd.self).getBlock() == Blocks.REDSTONE_WIRE)
|
||||
worldIn.setBlockState(upd.self, state, 2);
|
||||
worldIn.setBlock(upd.self, state, 2);
|
||||
}
|
||||
|
||||
return state;
|
||||
@@ -921,7 +920,7 @@ public class RedstoneWireTurbo
|
||||
*/
|
||||
private static int getMaxCurrentStrength(final UpdateNode upd, final int strength) {
|
||||
if (upd.type != UpdateNode.Type.REDSTONE) return strength;
|
||||
final int i = upd.currentState.get(RedstoneWireBlock.POWER);
|
||||
final int i = upd.currentState.getValue(RedStoneWireBlock.POWER);
|
||||
return i > strength ? i : strength;
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
package carpet.helpers;
|
||||
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.core.BlockPos;
|
||||
|
||||
public class ThrowableSuppression extends RuntimeException{
|
||||
|
||||
|
||||
@@ -3,14 +3,13 @@ package carpet.helpers;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.BiConsumer;
|
||||
|
||||
import net.minecraft.commands.CommandSourceStack;
|
||||
import net.minecraft.commands.Commands;
|
||||
import net.minecraft.network.chat.BaseComponent;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import carpet.CarpetServer;
|
||||
import carpet.network.ServerNetworkHandler;
|
||||
import carpet.utils.Messenger;
|
||||
import net.minecraft.server.command.CommandManager;
|
||||
import net.minecraft.server.command.ServerCommandSource;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.text.BaseText;
|
||||
|
||||
public class TickSpeed
|
||||
{
|
||||
@@ -20,9 +19,9 @@ public class TickSpeed
|
||||
public static long time_bias = 0;
|
||||
public static long time_warp_start_time = 0;
|
||||
public static long time_warp_scheduled_ticks = 0;
|
||||
public static ServerPlayerEntity time_advancerer = null;
|
||||
public static ServerPlayer time_advancerer = null;
|
||||
public static String tick_warp_callback = null;
|
||||
public static ServerCommandSource tick_warp_sender = null;
|
||||
public static CommandSourceStack tick_warp_sender = null;
|
||||
public static int player_active_timeout = 0;
|
||||
public static boolean process_entities = true;
|
||||
private static boolean deepFreeze = false;
|
||||
@@ -102,7 +101,7 @@ public class TickSpeed
|
||||
ServerNetworkHandler.updateTickPlayerActiveTimeoutToConnectedPlayers();
|
||||
}
|
||||
|
||||
public static BaseText tickrate_advance(ServerPlayerEntity player, int advance, String callback, ServerCommandSource source)
|
||||
public static BaseComponent tickrate_advance(ServerPlayer player, int advance, String callback, CommandSourceStack source)
|
||||
{
|
||||
if (0 == advance)
|
||||
{
|
||||
@@ -119,7 +118,7 @@ public class TickSpeed
|
||||
if (time_bias > 0)
|
||||
{
|
||||
String who = "Another player";
|
||||
if (time_advancerer != null) who = time_advancerer.getEntityName();
|
||||
if (time_advancerer != null) who = time_advancerer.getScoreboardName();
|
||||
return Messenger.c("l "+who+" is already advancing time at the moment. Try later or ask them");
|
||||
}
|
||||
time_advancerer = player;
|
||||
@@ -147,10 +146,10 @@ public class TickSpeed
|
||||
time_warp_start_time = 0;
|
||||
if (tick_warp_callback != null)
|
||||
{
|
||||
CommandManager icommandmanager = tick_warp_sender.getServer().getCommandManager();
|
||||
Commands icommandmanager = tick_warp_sender.getServer().getCommands();
|
||||
try
|
||||
{
|
||||
icommandmanager.execute(tick_warp_sender, tick_warp_callback);
|
||||
icommandmanager.performCommand(tick_warp_sender, tick_warp_callback);
|
||||
}
|
||||
catch (Throwable var23)
|
||||
{
|
||||
|
||||
@@ -1,16 +1,15 @@
|
||||
package carpet.helpers;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.util.hit.HitResult;
|
||||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.RaycastContext;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.Optional;
|
||||
import java.util.function.Predicate;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.level.ClipContext;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.phys.AABB;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.minecraft.world.phys.EntityHitResult;
|
||||
import net.minecraft.world.phys.HitResult;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
|
||||
public class Tracer
|
||||
{
|
||||
@@ -20,7 +19,7 @@ public class Tracer
|
||||
double maxSqDist = reach * reach;
|
||||
if (blockHit != null)
|
||||
{
|
||||
maxSqDist = blockHit.getPos().squaredDistanceTo(source.getCameraPosVec(partialTicks));
|
||||
maxSqDist = blockHit.getLocation().distanceToSqr(source.getEyePosition(partialTicks));
|
||||
}
|
||||
EntityHitResult entityHit = rayTraceEntities(source, partialTicks, reach, maxSqDist);
|
||||
return entityHit == null ? blockHit : entityHit;
|
||||
@@ -28,31 +27,31 @@ public class Tracer
|
||||
|
||||
public static BlockHitResult rayTraceBlocks(Entity source, float partialTicks, double reach, boolean fluids)
|
||||
{
|
||||
Vec3d pos = source.getCameraPosVec(partialTicks);
|
||||
Vec3d rotation = source.getRotationVec(partialTicks);
|
||||
Vec3d reachEnd = pos.add(rotation.x * reach, rotation.y * reach, rotation.z * reach);
|
||||
return source.world.raycast(new RaycastContext(pos, reachEnd, RaycastContext.ShapeType.OUTLINE, fluids ?
|
||||
RaycastContext.FluidHandling.ANY : RaycastContext.FluidHandling.NONE, source));
|
||||
Vec3 pos = source.getEyePosition(partialTicks);
|
||||
Vec3 rotation = source.getViewVector(partialTicks);
|
||||
Vec3 reachEnd = pos.add(rotation.x * reach, rotation.y * reach, rotation.z * reach);
|
||||
return source.level.clip(new ClipContext(pos, reachEnd, ClipContext.Block.OUTLINE, fluids ?
|
||||
ClipContext.Fluid.ANY : ClipContext.Fluid.NONE, source));
|
||||
}
|
||||
|
||||
public static EntityHitResult rayTraceEntities(Entity source, float partialTicks, double reach, double maxSqDist)
|
||||
{
|
||||
Vec3d pos = source.getCameraPosVec(partialTicks);
|
||||
Vec3d reachVec = source.getRotationVec(partialTicks).multiply(reach);
|
||||
Box box = source.getBoundingBox().stretch(reachVec).expand(1);
|
||||
return rayTraceEntities(source, pos, pos.add(reachVec), box, e -> !e.isSpectator() && e.collides(), maxSqDist);
|
||||
Vec3 pos = source.getEyePosition(partialTicks);
|
||||
Vec3 reachVec = source.getViewVector(partialTicks).scale(reach);
|
||||
AABB box = source.getBoundingBox().expandTowards(reachVec).inflate(1);
|
||||
return rayTraceEntities(source, pos, pos.add(reachVec), box, e -> !e.isSpectator() && e.isPickable(), maxSqDist);
|
||||
}
|
||||
|
||||
public static EntityHitResult rayTraceEntities(Entity source, Vec3d start, Vec3d end, Box box, Predicate<Entity> predicate, double maxSqDistance)
|
||||
public static EntityHitResult rayTraceEntities(Entity source, Vec3 start, Vec3 end, AABB box, Predicate<Entity> predicate, double maxSqDistance)
|
||||
{
|
||||
World world = source.world;
|
||||
Level world = source.level;
|
||||
double targetDistance = maxSqDistance;
|
||||
Entity target = null;
|
||||
Vec3d targetHitPos = null;
|
||||
for (Entity current : world.getOtherEntities(source, box, predicate))
|
||||
Vec3 targetHitPos = null;
|
||||
for (Entity current : world.getEntities(source, box, predicate))
|
||||
{
|
||||
Box currentBox = current.getBoundingBox().expand(current.getTargetingMargin());
|
||||
Optional<Vec3d> currentHit = currentBox.raycast(start, end);
|
||||
AABB currentBox = current.getBoundingBox().inflate(current.getPickRadius());
|
||||
Optional<Vec3> currentHit = currentBox.clip(start, end);
|
||||
if (currentBox.contains(start))
|
||||
{
|
||||
if (targetDistance >= 0)
|
||||
@@ -64,8 +63,8 @@ public class Tracer
|
||||
}
|
||||
else if (currentHit.isPresent())
|
||||
{
|
||||
Vec3d currentHitPos = currentHit.get();
|
||||
double currentDistance = start.squaredDistanceTo(currentHitPos);
|
||||
Vec3 currentHitPos = currentHit.get();
|
||||
double currentDistance = start.distanceToSqr(currentHitPos);
|
||||
if (currentDistance < targetDistance || targetDistance == 0)
|
||||
{
|
||||
if (current.getRootVehicle() == source.getRootVehicle())
|
||||
|
||||
Reference in new issue
Block a user