Clean up deprications

This commit is contained in:
Sollace 2024-10-03 18:10:03 +01:00
parent b72be6e403
commit 84b672ffbb
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
59 changed files with 264 additions and 394 deletions

View file

@ -3,13 +3,18 @@ package com.minelittlepony.unicopia.ability.magic;
import java.util.function.IntConsumer;
import java.util.function.IntSupplier;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.math.MathHelper;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
/**
* Object with levelling capabilities.
*/
public interface Levelled {
Codec<LevelStore> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codec.INT.fieldOf("max").forGetter(LevelStore::getMax),
Codec.INT.fieldOf("value").forGetter(LevelStore::get)
).apply(instance, Levelled::of));
LevelStore ZERO = of(0, 1);
static LevelStore of(IntSupplier getter, IntConsumer setter, IntSupplier max) {
@ -35,12 +40,6 @@ public interface Levelled {
return of(store.get(), store.getMax());
}
static LevelStore fromNbt(NbtCompound compound) {
int max = Math.max(1, compound.getInt("max"));
int value = MathHelper.clamp(compound.getInt("value"), 0, max);
return of(value, max);
}
static LevelStore of(int level, int max) {
return new LevelStore() {
@Override
@ -85,12 +84,5 @@ public interface Levelled {
default void add(int levels) {
set(get() + levels);
}
default NbtCompound toNbt() {
NbtCompound compound = new NbtCompound();
compound.putInt("value", get());
compound.putInt("max", getMax());
return compound;
}
}
}

View file

@ -15,6 +15,7 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.particle.FollowingParticleEffect;
import com.minelittlepony.unicopia.particle.ParticleUtils;
import com.minelittlepony.unicopia.particle.UParticles;
import com.minelittlepony.unicopia.util.serialization.NbtSerialisable;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
@ -22,7 +23,6 @@ import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.effect.StatusEffects;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.math.MathHelper;
@ -147,7 +147,7 @@ public class ChangelingFeedingSpell extends AbstractSpell {
compound.putFloat("healthToDrain", healthToDrain);
compound.putInt("foodToDrain", foodToDrain);
compound.putFloat("damageThisTick", damageThisTick);
compound.put("targets", EntityReference.<LivingEntity>getSerializer().writeAll(targets, lookup));
compound.put("targets", NbtSerialisable.encode(EntityReference.<LivingEntity>listCodec(), targets, lookup));
}
@Override
@ -156,8 +156,6 @@ public class ChangelingFeedingSpell extends AbstractSpell {
healthToDrain = compound.getFloat("healthToDrain");
foodToDrain = compound.getInt("foodToDrain");
damageThisTick = compound.getFloat("damageThisTick");
targets = compound.contains("targets", NbtElement.LIST_TYPE)
? EntityReference.<LivingEntity>getSerializer().readAll(compound.getList("targets", NbtElement.COMPOUND_TYPE), lookup).toList()
: List.of();
targets = NbtSerialisable.decode(EntityReference.<LivingEntity>listCodec(), compound.get("targets"), lookup).orElse(List.of());
}
}

View file

@ -25,9 +25,6 @@ import net.minecraft.util.Util;
* Interface for a magic spells
*/
public interface Spell extends NbtSerialisable, Affine {
@Deprecated
Serializer<NbtCompound, Spell> SERIALIZER = Serializer.of(Spell::readNbt, Spell::writeNbt);
/**
* Returns the full type that describes this spell.
*/

View file

@ -135,14 +135,14 @@ public class HydrophobicSpell extends AbstractSpell {
@Override
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound, lookup);
compound.put("storedFluidPositions", NbtSerialisable.encode(Entry.SET_CODEC, storedFluidPositions));
compound.put("storedFluidPositions", NbtSerialisable.encode(Entry.SET_CODEC, storedFluidPositions, lookup));
}
@Override
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound, lookup);
storedFluidPositions.clear();
NbtSerialisable.decode(Entry.SET_CODEC, compound.getList("storedFluidPositions", NbtElement.COMPOUND_TYPE)).ifPresent(storedFluidPositions::addAll);
NbtSerialisable.decode(Entry.SET_CODEC, compound.get("storedFluidPositions"), lookup).ifPresent(storedFluidPositions::addAll);
}
/**
* Calculates the maximum radius of the shield. aka The area of effect.

View file

@ -198,8 +198,8 @@ public class MindSwapSpell extends MimicSpell implements ProjectileDelegate.Enti
compound.put("counterpart", counterpart.toNBT(lookup));
compound.putBoolean("initialized", initialized);
myStoredInventory.ifPresent(mine -> compound.put("myStoredInventory", NbtSerialisable.encode(Inventory.CODEC, mine)));
theirStoredInventory.ifPresent(theirs -> compound.put("theirStoredInventory", NbtSerialisable.encode(Inventory.CODEC, theirs)));
myStoredInventory.ifPresent(mine -> compound.put("myStoredInventory", NbtSerialisable.encode(Inventory.CODEC, mine, lookup)));
theirStoredInventory.ifPresent(theirs -> compound.put("theirStoredInventory", NbtSerialisable.encode(Inventory.CODEC, theirs, lookup)));
}
@Override
@ -207,8 +207,8 @@ public class MindSwapSpell extends MimicSpell implements ProjectileDelegate.Enti
super.fromNBT(compound, lookup);
counterpart.fromNBT(compound.getCompound("counterpart"), lookup);
initialized = compound.getBoolean("initialized");
myStoredInventory = NbtSerialisable.decode(Inventory.CODEC, compound.getCompound("myStoredInventory"));
theirStoredInventory = NbtSerialisable.decode(Inventory.CODEC, compound.getCompound("theirStoredInventory"));
myStoredInventory = NbtSerialisable.decode(Inventory.CODEC, compound.getCompound("myStoredInventory"), lookup);
theirStoredInventory = NbtSerialisable.decode(Inventory.CODEC, compound.getCompound("theirStoredInventory"), lookup);
}
private static void swapPlayerData(ServerPlayerEntity a, ServerPlayerEntity b) {

View file

@ -63,13 +63,12 @@ public class CrystalDoorBlock extends DoorBlock implements BlockEntityProvider {
}
@Override
public boolean hasRandomTicks(BlockState state) {
protected boolean hasRandomTicks(BlockState state) {
return state.get(LOCKED);
}
@Deprecated
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
protected void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
super.randomTick(state, world, pos, random);
if (!isLocked(world, pos)) {
setOnGuard(state, world, pos, false);
@ -77,7 +76,7 @@ public class CrystalDoorBlock extends DoorBlock implements BlockEntityProvider {
}
@Override
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
protected void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
if (!state.get(LOCKED)) {
boolean powered = world.isReceivingRedstonePower(pos) || world.isReceivingRedstonePower(pos.offset(state.get(HALF) == DoubleBlockHalf.LOWER ? Direction.UP : Direction.DOWN));
if (!getDefaultState().isOf(sourceBlock) && powered != state.get(POWERED)) {

View file

@ -148,7 +148,7 @@ public class EdibleBlock extends HayBlock {
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return SHAPE_CACHE.apply(state);
}

View file

@ -71,13 +71,12 @@ public class FancyBedBlock extends BedBlock {
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return SHAPES.get(state.get(PART).ordinal()).apply(BedBlock.getOppositePartDirection(state));
}
@Deprecated
@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
protected void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (state.hasBlockEntity() && !state.isOf(newState.getBlock()) && state.get(PART) == BedPart.HEAD) {
world.getBlockEntity(pos, UBlockEntities.FANCY_BED).ifPresent(tile -> {
SheetPattern pattern = tile.getPattern();

View file

@ -2,6 +2,7 @@ package com.minelittlepony.unicopia.block;
import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.util.Untyped;
import com.mojang.serialization.MapCodec;
import net.minecraft.block.Block;
@ -22,10 +23,9 @@ public class FrostedObsidianBlock extends FrostedIceBlock {
super(settings);
}
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
public MapCodec<FrostedIceBlock> getCodec() {
return (MapCodec)CODEC;
return Untyped.cast(CODEC);
}
@Override

View file

@ -71,20 +71,19 @@ public class FruitBlock extends Block implements Buckable {
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return shape;
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
protected boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
BlockPos attachedPos = pos.offset(attachmentFace.getOpposite());
BlockState attachedState = world.getBlockState(attachedPos);
return canAttachTo(attachedState);
}
@Deprecated
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (!state.canPlaceAt(world, pos)) {
return Blocks.AIR.getDefaultState();
}
@ -92,15 +91,14 @@ public class FruitBlock extends Block implements Buckable {
}
@Override
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
protected void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (!state.canPlaceAt(world, pos)) {
world.breakBlock(pos, true);
}
}
@Deprecated
@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
protected void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
super.onStateReplaced(state, world, pos, newState, moved);
if (!newState.isOf(state.getBlock())) {
BlockState leaves = world.getBlockState(pos.up());

View file

@ -73,7 +73,7 @@ public class GrowableBlock extends SpreadableBlock {
}
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
protected void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (!canSurvive(state, world, pos)) {
world.setBlockState(pos, dead.get().getDefaultState());
return;

View file

@ -6,7 +6,10 @@ import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.function.Function;
import java.util.stream.Collectors;
import org.jetbrains.annotations.Nullable;
@ -16,15 +19,15 @@ import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.particle.ParticleUtils;
import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.minelittlepony.unicopia.util.PosHelper;
import com.minelittlepony.unicopia.util.serialization.NbtSerialisable;
import com.minelittlepony.unicopia.util.serialization.NbtSerialisable.Serializer;
import net.minecraft.block.Block;
import net.minecraft.block.BlockEntityProvider;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.ConnectingBlock;
import net.minecraft.block.ShapeContext;
import net.minecraft.block.entity.BlockEntity;
@ -32,7 +35,6 @@ import net.minecraft.block.entity.BlockEntityTicker;
import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.registry.entry.RegistryEntry;
@ -164,9 +166,8 @@ public class HiveBlock extends ConnectingBlock implements BlockEntityProvider {
return ActionResult.PASS;
}
@Deprecated
@Override
public void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
protected void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify) {
world.scheduleBlockTick(pos, this, 15);
super.neighborUpdate(state, world, pos, sourceBlock, sourcePos, notify);
}
@ -211,25 +212,19 @@ public class HiveBlock extends ConnectingBlock implements BlockEntityProvider {
listener = new Listener(pos);
}
@SuppressWarnings("deprecation")
@Override
public void readNbt(NbtCompound nbt, WrapperLookup lookup) {
opening = nbt.getBoolean("opening");
closing = nbt.getBoolean("closing");
storedBlocks.clear();
if (nbt.contains("storedBlocks", NbtElement.LIST_TYPE)) {
Entry.SERIALIZER.readAll(nbt.getList("storedBlocks", NbtElement.COMPOUND_TYPE), lookup).forEach(entry -> {
storedBlocks.put(entry.pos(), entry);
});
}
NbtSerialisable.decode(Entry.MAP_CODEC, nbt.get("storedBlocks"), lookup).ifPresent(storedBlocks::putAll);
}
@SuppressWarnings("deprecation")
@Override
protected void writeNbt(NbtCompound nbt, WrapperLookup lookup) {
nbt.putBoolean("opening", opening);
nbt.putBoolean("closing", closing);
nbt.put("storedBlocks", Entry.SERIALIZER.writeAll(storedBlocks.values(), lookup));
nbt.put("storedBlocks", NbtSerialisable.encode(Entry.MAP_CODEC, storedBlocks, lookup));
}
static void tick(World world, BlockPos pos, BlockState state, TileData data) {
@ -263,7 +258,7 @@ public class HiveBlock extends ConnectingBlock implements BlockEntityProvider {
if (consumed.add(adjacent.toImmutable()) && !storedBlocks.containsKey(adjacent)) {
BlockEntity data = world.getBlockEntity(adjacent);
storedBlocks.put(adjacent.toImmutable(), new Entry(adjacent.toImmutable(), s, data instanceof TileData ? null : data));
storedBlocks.put(adjacent.toImmutable(), new Entry(adjacent.toImmutable(), s, data instanceof TileData ? Optional.empty() : Optional.ofNullable(data.createNbtWithId(world.getRegistryManager()))));
if (s.isOf(UBlocks.CHITIN)) {
world.breakBlock(adjacent, false);
@ -311,35 +306,21 @@ public class HiveBlock extends ConnectingBlock implements BlockEntityProvider {
markDirty();
}
record Entry (BlockPos pos, BlockState state, @Nullable BlockEntity data) {
@SuppressWarnings("deprecation")
public static final Serializer<NbtCompound, Entry> SERIALIZER = Serializer.of((compound, lookup) -> new Entry(
NbtSerialisable.decode(BlockPos.CODEC, compound.getCompound("pos")).orElse(BlockPos.ORIGIN),
NbtSerialisable.decode(BlockState.CODEC, compound.get("state")).orElse(Blocks.AIR.getDefaultState()),
compound.getCompound("data"),
lookup
), (entry, lookup) -> {
NbtCompound compound = new NbtCompound();
compound.put("pos", NbtSerialisable.encode(BlockPos.CODEC, entry.pos()));
compound.put("state", NbtSerialisable.encode(BlockState.CODEC, entry.state()));
if (entry.data() != null) {
compound.put("data", entry.data().createNbtWithId(lookup));
}
return compound;
});
record Entry (BlockPos pos, BlockState state, Optional<NbtCompound> data) {
public static final Codec<Entry> CODEC = RecordCodecBuilder.create(instance -> instance.group(
BlockPos.CODEC.fieldOf("pos").forGetter(Entry::pos),
BlockState.CODEC.fieldOf("state").forGetter(Entry::state),
NbtCompound.CODEC.optionalFieldOf("data").forGetter(Entry::data)
).apply(instance, Entry::new));
public static final Codec<Map<BlockPos, Entry>> MAP_CODEC = CODEC.listOf().xmap(
entries -> entries.stream().collect(Collectors.toMap(Entry::pos, Function.identity())),
entries -> entries.values().stream().toList()
);
Entry(BlockPos pos, BlockState state, NbtCompound nbt, WrapperLookup lookup) {
this(pos, state, BlockEntity.createFromNbt(pos, state, nbt, lookup));
}
@SuppressWarnings("deprecation")
public void restore(World world) {
if (world.isAir(pos)) {
world.setBlockState(pos, state);
if (data != null) {
data.setCachedState(state);
world.addBlockEntity(data);
}
data.map(nbt -> BlockEntity.createFromNbt(pos, state, nbt, world.getRegistryManager())).ifPresent(world::addBlockEntity);
}
}
}

View file

@ -54,16 +54,15 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven
}
@Override
public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (hand == Hand.OFF_HAND) {
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
}
return world.getBlockEntity(pos, UBlockEntities.ITEM_JAR).map(data -> data.interact(player, hand)).orElse(ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION);
}
@Deprecated
@Override
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
protected void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (!moved && !state.isOf(newState.getBlock())) {
world.getBlockEntity(pos, UBlockEntities.ITEM_JAR).ifPresent(data -> {
data.getContents().onDestroyed();
@ -73,21 +72,20 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven
}
@Override
public boolean hasComparatorOutput(BlockState state) {
protected boolean hasComparatorOutput(BlockState state) {
return true;
}
@Override
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
protected int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return world.getBlockEntity(pos, UBlockEntities.ITEM_JAR)
.map(TileData::getItems)
.map(data -> Math.min(16, data.stacks().size()))
.orElse(0);
}
@Deprecated
@Override
public boolean onSyncedBlockEvent(BlockState state, World world, BlockPos pos, int type, int data) {
protected boolean onSyncedBlockEvent(BlockState state, World world, BlockPos pos, int type, int data) {
super.onSyncedBlockEvent(state, world, pos, type, data);
BlockEntity blockEntity = world.getBlockEntity(pos);
return blockEntity != null && blockEntity.onSyncedBlockEvent(type, data);
@ -167,7 +165,7 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven
} else if (nbt.contains("entity", NbtElement.COMPOUND_TYPE)) {
contents = new EntityJarContents(this, nbt.getCompound("entity"));
} else if (nbt.contains("fluid", NbtElement.COMPOUND_TYPE)) {
contents = new FluidOnlyJarContents(this, nbt.getCompound("fluid"));
contents = new FluidOnlyJarContents(this, nbt.getCompound("fluid"), lookup);
} else if (nbt.contains("fakeFluid", NbtElement.COMPOUND_TYPE)) {
contents = new FakeFluidJarContents(this, nbt.getCompound("fakeFluid"));
}

View file

@ -59,13 +59,12 @@ public class JarBlock extends TransparentBlock implements Waterloggable {
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return SHAPE;
}
@Deprecated
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (state.get(WATERLOGGED)) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
@ -79,9 +78,8 @@ public class JarBlock extends TransparentBlock implements Waterloggable {
return getDefaultState().with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER);
}
@Deprecated
@Override
public FluidState getFluidState(BlockState state) {
protected FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
}

View file

@ -28,12 +28,12 @@ public class OrientedBlock extends FacingBlock {
}
@Override
public BlockState rotate(BlockState state, BlockRotation rotation) {
protected BlockState rotate(BlockState state, BlockRotation rotation) {
return state.with(FACING, rotation.rotate(state.get(FACING)));
}
@Override
public BlockState mirror(BlockState state, BlockMirror mirror) {
protected BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation(state.get(FACING)));
}

View file

@ -72,15 +72,13 @@ public class PieBlock extends Block implements Waterloggable {
return CODEC;
}
@Deprecated
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return SHAPES[state.get(BITES)];
}
@Deprecated
@Override
public ItemActionResult onUseWithItem(ItemStack itemStack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
protected ItemActionResult onUseWithItem(ItemStack itemStack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (world.isClient) {
@ -180,9 +178,8 @@ public class PieBlock extends Block implements Waterloggable {
}
}
@Deprecated
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (direction == Direction.DOWN && !state.canPlaceAt(world, pos)) {
return Blocks.AIR.getDefaultState();
}
@ -192,13 +189,11 @@ public class PieBlock extends Block implements Waterloggable {
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
}
@Deprecated
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
protected boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
return world.getBlockState(pos.down()).isSideSolidFullSquare(world, pos, Direction.UP);
}
@Deprecated
@Override
public BlockState getPlacementState(ItemPlacementContext ctx) {
return super.getDefaultState()
@ -206,9 +201,8 @@ public class PieBlock extends Block implements Waterloggable {
.with(STOMPED, ctx.getStack().isOf(UItems.APPLE_PIE_HOOF));
}
@Deprecated
@Override
public FluidState getFluidState(BlockState state) {
protected FluidState getFluidState(BlockState state) {
if (state.get(WATERLOGGED)) {
return Fluids.WATER.getStill(false);
}
@ -221,17 +215,17 @@ public class PieBlock extends Block implements Waterloggable {
}
@Override
public int getComparatorOutput(BlockState state, World world, BlockPos pos) {
protected int getComparatorOutput(BlockState state, World world, BlockPos pos) {
return (5 - state.get(BITES)) * 2;
}
@Override
public boolean hasComparatorOutput(BlockState state) {
protected boolean hasComparatorOutput(BlockState state) {
return true;
}
@Override
public boolean canPathfindThrough(BlockState state, NavigationType type) {
protected boolean canPathfindThrough(BlockState state, NavigationType type) {
return false;
}
}

View file

@ -58,7 +58,7 @@ public class PileBlock extends Block implements Waterloggable {
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
Vec3d offset = state.getModelOffset(world, pos);
return shapes[state.get(COUNT) - 1].offset(offset.x, offset.y, offset.z);
}
@ -81,20 +81,18 @@ public class PileBlock extends Block implements Waterloggable {
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
protected boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
pos = pos.down();
return world.getBlockState(pos).isSideSolid(world, pos, Direction.UP, SideShapeType.CENTER);
}
@Deprecated
@Override
public boolean canReplace(BlockState state, ItemPlacementContext context) {
protected boolean canReplace(BlockState state, ItemPlacementContext context) {
return (!context.shouldCancelInteraction() && context.getStack().isOf(asItem()) && state.get(COUNT) < MAX_COUNT) || super.canReplace(state, context);
}
@Deprecated
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (!state.canPlaceAt(world, pos)) {
return Blocks.AIR.getDefaultState();
}

View file

@ -60,7 +60,7 @@ public class PineappleCropBlock extends CropBlock {
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (direction == Direction.UP && !neighborState.isOf(this)) {
return state.with(AGE, Math.min(state.get(AGE), getMaxAge() - 1));
}
@ -68,7 +68,7 @@ public class PineappleCropBlock extends CropBlock {
}
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
protected void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (state.get(HALF) == BlockHalf.BOTTOM) {
super.randomTick(state, world, pos, random);

View file

@ -75,20 +75,19 @@ public class RockCropBlock extends CropBlock {
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return AGE_TO_SHAPE[state.get(getAgeProperty())];
}
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
protected void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (canGrow(world, random, pos, state)) {
super.randomTick(state, world, pos, random);
}
}
@Override
@Deprecated
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
protected void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
super.onStateReplaced(state, world, pos, newState, moved);
if (!moved && !(state.getBlock() == this && newState.getBlock() == this)) {
if (!world.isClient) {

View file

@ -99,7 +99,7 @@ public class SegmentedCropBlock extends CropBlock implements SegmentedBlock {
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
BlockPos tip = getTip(world, pos);
BlockPos root = getRoot(world, pos);
@ -119,7 +119,7 @@ public class SegmentedCropBlock extends CropBlock implements SegmentedBlock {
}
@Override
public boolean canPlantOnTop(BlockState state, BlockView view, BlockPos pos) {
protected boolean canPlantOnTop(BlockState state, BlockView view, BlockPos pos) {
return (state.getBlock() instanceof SegmentedCropBlock o && o.canSupportBlock(this, state, view, pos)) || super.canPlantOnTop(state, view, pos);
}
@ -134,7 +134,7 @@ public class SegmentedCropBlock extends CropBlock implements SegmentedBlock {
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (direction == Direction.UP && !isNext(neighborState)) {
return state.with(getAgeProperty(), Math.min(state.get(getAgeProperty()), getMaxAge() - 1));
}
@ -142,7 +142,7 @@ public class SegmentedCropBlock extends CropBlock implements SegmentedBlock {
}
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
protected void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
BlockPos tip = getTip(world, pos);
BlockPos root = getRoot(world, pos);

View file

@ -40,8 +40,7 @@ public class ShellsBlock extends Block implements Waterloggable {
}
@Override
@Deprecated
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return SHAPE;
}
@ -57,18 +56,16 @@ public class ShellsBlock extends Block implements Waterloggable {
return getDefaultState().with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER);
}
@Deprecated
@Override
public FluidState getFluidState(BlockState state) {
protected FluidState getFluidState(BlockState state) {
if (state.get(WATERLOGGED).booleanValue()) {
return Fluids.WATER.getStill(false);
}
return super.getFluidState(state);
}
@Deprecated
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (state.get(WATERLOGGED).booleanValue()) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
@ -76,7 +73,7 @@ public class ShellsBlock extends Block implements Waterloggable {
}
@Override
public boolean canPathfindThrough(BlockState state, NavigationType type) {
protected boolean canPathfindThrough(BlockState state, NavigationType type) {
return (type == NavigationType.WATER) == state.getFluidState().isIn(FluidTags.WATER);
}
}

View file

@ -73,7 +73,7 @@ public class SlimePustuleBlock extends Block {
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return switch (state.get(SHAPE)) {
case POD -> BULB_SHAPE;
case DRIP -> DRIP_SHAPE;
@ -108,9 +108,8 @@ public class SlimePustuleBlock extends Block {
}
}
@Deprecated
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
protected void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (state.get(SHAPE) == Shape.POD && random.nextInt(130) == 0) {
SlimeEntity slime = EntityType.SLIME.create(world);
slime.setSize(1, true);
@ -166,17 +165,15 @@ public class SlimePustuleBlock extends Block {
builder.add(SHAPE, POWERED);
}
@Deprecated
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
protected boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
pos = pos.up();
state = world.getBlockState(pos);
return state.isOf(this) || state.isSideSolid(world, pos, Direction.DOWN, SideShapeType.CENTER);
}
@Deprecated
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (!canPlaceAt(state, world, pos)) {
return Blocks.AIR.getDefaultState();
}
@ -204,8 +201,7 @@ public class SlimePustuleBlock extends Block {
}
@Override
@Deprecated
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
protected void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
super.onStateReplaced(state, world, pos, newState, moved);
if (state.isOf(this) && newState.isOf(this) && state.get(POWERED) != newState.get(POWERED)) {
world.updateNeighborsAlways(pos.up(), this);
@ -213,14 +209,12 @@ public class SlimePustuleBlock extends Block {
}
@Override
@Deprecated
public boolean emitsRedstonePower(BlockState state) {
protected boolean emitsRedstonePower(BlockState state) {
return state.get(POWERED);
}
@Override
@Deprecated
public int getWeakRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction direction) {
protected int getWeakRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction direction) {
if (direction == Direction.DOWN && emitsRedstonePower(state)) {
return 15;
}
@ -228,8 +222,7 @@ public class SlimePustuleBlock extends Block {
}
@Override
@Deprecated
public int getStrongRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction direction) {
protected int getStrongRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction direction) {
if (direction == Direction.DOWN && emitsRedstonePower(state)) {
return 15;
}

View file

@ -14,7 +14,7 @@ public class SpectralFireBlock extends SoulFireBlock {
}
@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
protected void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
if (!(entity instanceof ItemEntity)) {
super.onEntityCollision(state, world, pos, entity);
}

View file

@ -33,9 +33,8 @@ public class SpikesBlock extends OrientedBlock {
return CODEC;
}
@Deprecated
@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
protected void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
if (!(entity instanceof LivingEntity) || entity.getType() == EntityType.FOX || entity.getType() == EntityType.BEE) {
return;
}
@ -51,9 +50,8 @@ public class SpikesBlock extends OrientedBlock {
}
}
@Deprecated
@Override
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
protected void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) {
if (!world.isClient && !oldState.isOf(this)) {
for (Entity e : world.getOtherEntities(null, new Box(pos))) {
if (!(e instanceof LivingEntity) || e.getType() == EntityType.FOX || e.getType() == EntityType.BEE) {
@ -65,7 +63,7 @@ public class SpikesBlock extends OrientedBlock {
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
protected boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
Direction facing = state.get(FACING);
pos = pos.offset(facing.getOpposite());
state = world.getBlockState(pos);
@ -78,9 +76,8 @@ public class SpikesBlock extends OrientedBlock {
return getDefaultState().with(FACING, side);
}
@Deprecated
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (direction == state.get(FACING).getOpposite() && !canPlaceAt(state, world, pos)) {
if (!(neighborState.isOf(Blocks.STICKY_PISTON)
|| neighborState.isOf(Blocks.PISTON)
@ -94,7 +91,7 @@ public class SpikesBlock extends OrientedBlock {
}
@Override
public boolean canPathfindThrough(BlockState state, NavigationType type) {
protected boolean canPathfindThrough(BlockState state, NavigationType type) {
return false;
}
}

View file

@ -68,12 +68,12 @@ public class SproutBlock extends CropBlock implements TintedBlock {
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return AGE_TO_SHAPE[state.get(getAgeProperty())];
}
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
protected void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
super.randomTick(state, world, pos, random);
state = world.getBlockState(pos);
if (state.isOf(this)) {

View file

@ -28,7 +28,7 @@ public class StableDoorBlock extends DoorBlock {
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
DoubleBlockHalf half = state.get(HALF);
if (direction.getAxis() == Direction.Axis.Y && half == DoubleBlockHalf.LOWER == (direction == Direction.UP)) {

View file

@ -71,8 +71,7 @@ public class ThornBlock extends ConnectingBlock implements EarthPonyGrowAbility.
}
@Override
@Deprecated
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
protected void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (state.get(AGE) == MAX_AGE
&& random.nextInt(1200) == 0
&& world.isPlayerInRange(pos.getX(), pos.getY(), pos.getZ(), 3)) {
@ -81,7 +80,7 @@ public class ThornBlock extends ConnectingBlock implements EarthPonyGrowAbility.
}
@Override
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
protected void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (!state.canPlaceAt(world, pos)) {
world.breakBlock(pos, true);
}
@ -96,7 +95,7 @@ public class ThornBlock extends ConnectingBlock implements EarthPonyGrowAbility.
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (direction == state.get(FACING) && !state.canPlaceAt(world, pos)) {
world.scheduleBlockTick(pos, this, 1);
}
@ -104,7 +103,7 @@ public class ThornBlock extends ConnectingBlock implements EarthPonyGrowAbility.
}
@Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
protected boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
Direction facing = state.get(FACING);
BlockState neighborState = world.getBlockState(pos.offset(facing));
return (facing == Direction.DOWN && state.get(DISTANCE) == 0 && neighborState.isIn(BlockTags.DIRT))

View file

@ -55,14 +55,14 @@ public class ThornBudBlock extends Block implements EarthPonyGrowAbility.Growabl
}
@Override
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
protected void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (random.nextInt(50) == 0) {
grow(world, state, pos);
}
}
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (direction == state.get(FACING) && !(neighborState.isOf(this) || neighborState.isOf(branchState.getBlock()))) {
return Blocks.AIR.getDefaultState();
}

View file

@ -39,9 +39,8 @@ public class WeatherVaneBlock extends BlockWithEntity {
return CODEC;
}
@Deprecated
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return SHAPE;
}

View file

@ -48,7 +48,7 @@ public class CloudBedBlock extends FancyBedBlock implements CloudLike {
}
@Override
public final VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected final VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (!baseBlock.canInteract(baseState, world, pos, EquineContext.of(context))) {
return VoxelShapes.empty();
}
@ -56,14 +56,12 @@ public class CloudBedBlock extends FancyBedBlock implements CloudLike {
}
@Override
@Deprecated
public final VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
protected final VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
return super.getOutlineShape(state, world, pos, ShapeContext.absent());
}
@Override
@Deprecated
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return this.collidable ? state.getOutlineShape(world, pos, context) : VoxelShapes.empty();
}
@ -77,22 +75,20 @@ public class CloudBedBlock extends FancyBedBlock implements CloudLike {
}
@Override
public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!baseBlock.canInteract(baseState, world, pos, EquineContext.of(player))) {
return ItemActionResult.SKIP_DEFAULT_BLOCK_INTERACTION;
}
return super.onUseWithItem(stack, state, world, pos, player, hand, hit);
}
@Deprecated
@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
protected void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
baseState.onEntityCollision(world, pos, entity);
}
@Override
@Deprecated
public boolean canPathfindThrough(BlockState state, NavigationType type) {
protected boolean canPathfindThrough(BlockState state, NavigationType type) {
return baseState.canPathfindThrough(type);
}
}

View file

@ -50,13 +50,12 @@ public class CloudBlock extends Block implements CloudLike {
}
@Override
@Deprecated
public float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) {
protected float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) {
return 0.9F;
}
@Override
public boolean isTransparent(BlockState state, BlockView world, BlockPos pos) {
protected boolean isTransparent(BlockState state, BlockView world, BlockPos pos) {
return true;
}
@ -117,8 +116,7 @@ public class CloudBlock extends Block implements CloudLike {
}
@Override
@Deprecated
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
protected void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
if (entity instanceof PlayerEntity player && (player.getAbilities().flying || Pony.of(player).getPhysics().isFlying())) {
return;
@ -137,7 +135,7 @@ public class CloudBlock extends Block implements CloudLike {
}
@Override
public final VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected final VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
EquineContext equineContext = EquineContext.of(context);
if (!canInteract(state, world, pos, equineContext)) {
return VoxelShapes.empty();
@ -146,14 +144,12 @@ public class CloudBlock extends Block implements CloudLike {
}
@Override
@Deprecated
public final VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
protected final VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
return getOutlineShape(state, world, pos, ShapeContext.absent(), EquineContext.ABSENT);
}
@Override
@Deprecated
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return this.collidable ? state.getOutlineShape(world, pos, context) : VoxelShapes.empty();
}
@ -167,9 +163,8 @@ public class CloudBlock extends Block implements CloudLike {
return getPlacementState(context, equineContext);
}
@Deprecated
@Override
public final boolean canReplace(BlockState state, ItemPlacementContext context) {
protected final boolean canReplace(BlockState state, ItemPlacementContext context) {
EquineContext equineContext = EquineContext.of(context);
if (canInteract(state, context.getWorld(), context.getBlockPos(), equineContext)) {
return canReplace(state, context, equineContext);
@ -177,17 +172,15 @@ public class CloudBlock extends Block implements CloudLike {
return true;
}
@Deprecated
@Override
public boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) {
protected boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) {
VoxelShape shape = state.getCullingShape(EmptyBlockView.INSTANCE, BlockPos.ORIGIN);
VoxelShape shapeFrom = stateFrom.getCullingShape(EmptyBlockView.INSTANCE, BlockPos.ORIGIN);
return !shape.isEmpty() && !shapeFrom.isEmpty() && VoxelShapes.isSideCovered(shape, shapeFrom, direction);
}
@Override
@Deprecated
public boolean canPathfindThrough(BlockState state, NavigationType type) {
protected boolean canPathfindThrough(BlockState state, NavigationType type) {
System.out.println(InteractionManager.getInstance().getPathingEquineContext().collidesWithClouds());
return type != NavigationType.LAND || !InteractionManager.getInstance().getPathingEquineContext().collidesWithClouds();
}
@ -210,7 +203,7 @@ public class CloudBlock extends Block implements CloudLike {
}
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
protected void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (meltable) {
if (world.getLightLevel(LightType.BLOCK, pos) > 11) {
dropStacks(state, world, pos);

View file

@ -109,7 +109,7 @@ public class CloudChestBlock extends ChestBlock implements CloudLike {
}
@Override
public final VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected final VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (!baseBlock.canInteract(baseState, world, pos, EquineContext.of(context))) {
return VoxelShapes.empty();
}
@ -117,14 +117,12 @@ public class CloudChestBlock extends ChestBlock implements CloudLike {
}
@Override
@Deprecated
public final VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
protected final VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
return super.getOutlineShape(state, world, pos, ShapeContext.absent());
}
@Override
@Deprecated
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return this.collidable ? state.getOutlineShape(world, pos, context) : VoxelShapes.empty();
}
@ -138,22 +136,20 @@ public class CloudChestBlock extends ChestBlock implements CloudLike {
}
@Override
public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!baseBlock.canInteract(baseState, world, pos, EquineContext.of(player))) {
return ItemActionResult.SKIP_DEFAULT_BLOCK_INTERACTION;
}
return super.onUseWithItem(stack, state, world, pos, player, hand, hit);
}
@Deprecated
@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
protected void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
baseState.onEntityCollision(world, pos, entity);
}
@Override
@Deprecated
public boolean canPathfindThrough(BlockState state, NavigationType type) {
protected boolean canPathfindThrough(BlockState state, NavigationType type) {
return type != NavigationType.LAND || !InteractionManager.getInstance().getPathingEquineContext().collidesWithClouds();
}

View file

@ -47,7 +47,7 @@ public class CloudDoorBlock extends DoorBlock implements CloudLike {
}
@Override
public final VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected final VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (canPassThrough(state, world, pos, EquineContext.of(context))) {
return VoxelShapes.empty();
}
@ -59,14 +59,12 @@ public class CloudDoorBlock extends DoorBlock implements CloudLike {
}
@Override
@Deprecated
public final VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
protected final VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
return super.getOutlineShape(state, world, pos, ShapeContext.absent());
}
@Override
@Deprecated
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return this.collidable ? state.getOutlineShape(world, pos, context) : VoxelShapes.empty();
}
@ -80,16 +78,15 @@ public class CloudDoorBlock extends DoorBlock implements CloudLike {
}
@Override
public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (!baseBlock.canInteract(baseState, world, pos, EquineContext.of(player))) {
return ItemActionResult.SKIP_DEFAULT_BLOCK_INTERACTION;
}
return super.onUseWithItem(stack, state, world, pos, player, hand, hit);
}
@Deprecated
@Override
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
protected void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
baseState.onEntityCollision(world, pos, entity);
EquineContext context = EquineContext.of(entity);
@ -100,8 +97,7 @@ public class CloudDoorBlock extends DoorBlock implements CloudLike {
}
@Override
@Deprecated
public boolean canPathfindThrough(BlockState state, NavigationType type) {
protected boolean canPathfindThrough(BlockState state, NavigationType type) {
return !InteractionManager.getInstance().getPathingEquineContext().collidesWithClouds() || super.canPathfindThrough(state, type);
}
}

View file

@ -89,9 +89,8 @@ public class CloudPillarBlock extends CloudBlock {
.with(AXIS, axis);
}
@Deprecated
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (direction.getAxis() == state.get(AXIS)) {
return state.with(DIRECTION_PROPERTIES.get(direction), neighborState.isOf(this) && neighborState.get(AXIS) == state.get(AXIS));
}
@ -100,7 +99,7 @@ public class CloudPillarBlock extends CloudBlock {
}
@Override
public BlockState rotate(BlockState state, BlockRotation rotation) {
protected BlockState rotate(BlockState state, BlockRotation rotation) {
return PillarBlock.changeRotation(state, rotation);
}
}

View file

@ -48,7 +48,7 @@ public class CloudSlabBlock extends WaterloggableCloudBlock {
}
@Override
public boolean hasSidedTransparency(BlockState state) {
protected boolean hasSidedTransparency(BlockState state) {
return state.get(SlabBlock.TYPE) != SlabType.DOUBLE;
}
@ -59,7 +59,7 @@ public class CloudSlabBlock extends WaterloggableCloudBlock {
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, EquineContext equineContext) {
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context, EquineContext equineContext) {
return switch (state.get(SlabBlock.TYPE)) {
case DOUBLE -> VoxelShapes.fullCube();
case TOP -> TOP_SHAPE;
@ -84,7 +84,7 @@ public class CloudSlabBlock extends WaterloggableCloudBlock {
}
@Override
public boolean canReplace(BlockState state, ItemPlacementContext context, EquineContext equineContext) {
protected boolean canReplace(BlockState state, ItemPlacementContext context, EquineContext equineContext) {
SlabType slabType = state.get(SlabBlock.TYPE);
if (slabType == SlabType.DOUBLE || !context.getStack().isOf(asItem())) {
return false;

View file

@ -38,13 +38,12 @@ public class CloudStairsBlock extends StairsBlock implements CloudLike {
}
@Override
@Deprecated
public float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) {
protected float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) {
return baseBlock.getAmbientOcclusionLightLevel(state, world, pos);
}
@Override
public boolean isTransparent(BlockState state, BlockView world, BlockPos pos) {
protected boolean isTransparent(BlockState state, BlockView world, BlockPos pos) {
return baseBlock.isTransparent(state, world, pos);
}
@ -59,13 +58,12 @@ public class CloudStairsBlock extends StairsBlock implements CloudLike {
}
@Override
@Deprecated
public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
protected void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
baseBlock.onEntityCollision(state, world, pos, entity);
}
@Override
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
if (!baseBlock.canInteract(state, world, pos, EquineContext.of(context))) {
return VoxelShapes.empty();
}
@ -73,14 +71,12 @@ public class CloudStairsBlock extends StairsBlock implements CloudLike {
}
@Override
@Deprecated
public final VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
protected final VoxelShape getCullingShape(BlockState state, BlockView world, BlockPos pos) {
return super.getOutlineShape(state, world, pos, ShapeContext.absent());
}
@Override
@Deprecated
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
protected VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return this.collidable ? state.getOutlineShape(world, pos, context) : VoxelShapes.empty();
}
@ -94,21 +90,18 @@ public class CloudStairsBlock extends StairsBlock implements CloudLike {
return super.getPlacementState(context);
}
@Deprecated
@Override
public boolean canReplace(BlockState state, ItemPlacementContext context) {
protected boolean canReplace(BlockState state, ItemPlacementContext context) {
return baseBlock.canReplace(state, context);
}
@Deprecated
@Override
public boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) {
protected boolean isSideInvisible(BlockState state, BlockState stateFrom, Direction direction) {
return baseBlock.isSideInvisible(state, stateFrom, direction);
}
@Override
@Deprecated
public boolean canPathfindThrough(BlockState state, NavigationType type) {
protected boolean canPathfindThrough(BlockState state, NavigationType type) {
return baseBlock.canPathfindThrough(state, type);
}
}

View file

@ -99,12 +99,12 @@ public class CompactedCloudBlock extends CloudBlock {
}
@Override
public BlockState rotate(BlockState state, BlockRotation rotation) {
protected BlockState rotate(BlockState state, BlockRotation rotation) {
return transform(state, rotation::rotate);
}
@Override
public BlockState mirror(BlockState state, BlockMirror mirror) {
protected BlockState mirror(BlockState state, BlockMirror mirror) {
return transform(state, mirror::apply);
}

View file

@ -50,7 +50,7 @@ public class NaturalCloudBlock extends PoreousCloudBlock {
}
@Override
public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (stack.isIn(ItemTags.SHOVELS)) {
BooleanProperty property = CompactedCloudBlock.FACING_PROPERTIES.get(hit.getSide());
world.setBlockState(pos, compactedBlock.get().getDefaultState().with(property, false));

View file

@ -39,17 +39,17 @@ public class OrientedCloudBlock extends CloudBlock {
}
@Override
public BlockState rotate(BlockState state, BlockRotation rotation) {
protected BlockState rotate(BlockState state, BlockRotation rotation) {
return state.with(FACING, rotation.rotate(state.get(FACING)));
}
@Override
public BlockState mirror(BlockState state, BlockMirror mirror) {
protected BlockState mirror(BlockState state, BlockMirror mirror) {
return state.rotate(mirror.getRotation(state.get(FACING)));
}
@Override
public BlockState getPlacementState(ItemPlacementContext ctx, EquineContext equineContext) {
protected BlockState getPlacementState(ItemPlacementContext ctx, EquineContext equineContext) {
return getDefaultState().with(FACING, ctx.getSide().getOpposite());
}
}

View file

@ -46,7 +46,7 @@ public class PoreousCloudBlock extends CloudBlock implements Soakable {
}
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
protected void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if (state.getBlock() instanceof Soakable soakable && world.hasRain(pos) && world.isAir(pos.up())) {
@Nullable
BlockState soggyState = soakable.getStateWithMoisture(state, random.nextBetween(1, 5));

View file

@ -49,7 +49,7 @@ public class ShapingBenchBlock extends CloudBlock {
}
@Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
if (world.isClient) {
return ActionResult.SUCCESS;
}

View file

@ -65,8 +65,7 @@ public class SoggyCloudBlock extends CloudBlock implements Soakable {
}
@Override
@Deprecated
public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
return Soakable.tryCollectMoisture(stack, state, world, pos, player, hand, hit);
}
@ -77,7 +76,7 @@ public class SoggyCloudBlock extends CloudBlock implements Soakable {
}
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
protected void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
Soakable.tickMoisture(state, world, pos, random);
}
}

View file

@ -65,8 +65,7 @@ public class SoggyCloudSlabBlock extends CloudSlabBlock {
}
@Override
@Deprecated
public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
return Soakable.tryCollectMoisture(stack, state, world, pos, player, hand, hit);
}
@ -77,7 +76,7 @@ public class SoggyCloudSlabBlock extends CloudSlabBlock {
}
@Override
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
protected void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
Soakable.tickMoisture(state, world, pos, random);
}
}

View file

@ -65,9 +65,8 @@ public class WaterloggableCloudBlock extends PoreousCloudBlock implements Waterl
return super.getFluidState(state);
}
@Deprecated
@Override
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
protected BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) {
if (state.get(WATERLOGGED).booleanValue()) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
}
@ -75,7 +74,7 @@ public class WaterloggableCloudBlock extends PoreousCloudBlock implements Waterl
}
@Override
public boolean canPathfindThrough(BlockState state, NavigationType type) {
protected boolean canPathfindThrough(BlockState state, NavigationType type) {
return (type == NavigationType.WATER) == state.getFluidState().isIn(FluidTags.WATER);
}
}

View file

@ -22,8 +22,8 @@ public record FluidOnlyJarContents (
FluidVariant fluid
) implements FluidJarContents {
public FluidOnlyJarContents(TileData tile, NbtCompound compound) {
this(tile, compound.getLong("amount"), NbtSerialisable.decode(FluidVariant.CODEC, compound.getCompound("fluid")).orElse(FluidVariant.blank()));
public FluidOnlyJarContents(TileData tile, NbtCompound compound, WrapperLookup lookup) {
this(tile, compound.getLong("amount"), NbtSerialisable.decode(FluidVariant.CODEC, compound.getCompound("fluid"), lookup).orElse(FluidVariant.blank()));
}
@Override
@ -50,7 +50,7 @@ public record FluidOnlyJarContents (
@Override
public NbtCompound toNBT(NbtCompound compound, WrapperLookup lookup) {
compound.put("fluid", NbtSerialisable.encode(FluidVariant.CODEC, fluid));
compound.put("fluid", NbtSerialisable.encode(FluidVariant.CODEC, fluid, lookup));
compound.putLong("amount", amount);
return compound;
}

View file

@ -39,7 +39,7 @@ public record ItemsJarContents (
}
public ItemsJarContents(TileData tile, NbtCompound compound, WrapperLookup lookup) {
this(tile, new ArrayList<>(NbtSerialisable.decode(STACKS_CODEC, compound.get("items")).orElse(List.of())));
this(tile, new ArrayList<>(NbtSerialisable.decode(STACKS_CODEC, compound.get("items"), lookup).orElse(List.of())));
}
@Override
@ -197,7 +197,7 @@ public record ItemsJarContents (
@Override
public NbtCompound toNBT(NbtCompound compound, WrapperLookup lookup) {
compound.put("items", NbtSerialisable.encode(STACKS_CODEC, stacks));
compound.put("items", NbtSerialisable.encode(STACKS_CODEC, stacks, lookup));
return compound;
}

View file

@ -1,6 +1,7 @@
package com.minelittlepony.unicopia.entity;
import java.lang.ref.WeakReference;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
@ -11,15 +12,20 @@ import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.ability.magic.Levelled;
import com.minelittlepony.unicopia.network.track.TrackableObject;
import com.minelittlepony.unicopia.util.Untyped;
import com.minelittlepony.unicopia.util.serialization.CodecUtils;
import com.minelittlepony.unicopia.util.serialization.NbtSerialisable;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtOps;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Util;
import net.minecraft.util.Uuids;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
@ -33,16 +39,19 @@ import net.minecraft.world.World;
* @param <T> The type of the entity this reference points to.
*/
public class EntityReference<T extends Entity> implements NbtSerialisable, TrackableObject<EntityReference<T>> {
private static final Serializer<NbtCompound, ?> SERIALIZER = Serializer.of(EntityReference::new);
public static final Codec<EntityReference<?>> CODEC = EntityValues.CODEC.xmap(r -> new EntityReference<>(r), r -> r.reference);
public static final Codec<List<EntityReference<?>>> LIST_CODEC = CODEC.listOf();
@SuppressWarnings("unchecked")
public static <T extends Entity> Serializer<NbtCompound, EntityReference<T>> getSerializer() {
return (Serializer<NbtCompound, EntityReference<T>>)SERIALIZER;
public static <T extends Entity> Codec<List<EntityReference<T>>> codec() {
return Untyped.cast(CODEC);
}
public static <T extends Entity> Codec<List<EntityReference<T>>> listCodec() {
return Untyped.cast(LIST_CODEC);
}
@Nullable
private EntityValues<T> reference;
private WeakReference<T> directReference = new WeakReference<>(null);
private boolean dirty = true;
@ -57,6 +66,10 @@ public class EntityReference<T extends Entity> implements NbtSerialisable, Track
fromNBT(nbt, lookup);
}
private EntityReference(EntityValues<T> reference) {
this.reference = reference;
}
@SuppressWarnings("unchecked")
public void copyFrom(EntityReference<? extends T> other) {
this.reference = ((EntityReference<T>)other).reference;
@ -102,24 +115,33 @@ public class EntityReference<T extends Entity> implements NbtSerialisable, Track
@Nullable
public T get(World world) {
return getOrEmpty(world).orElse(null);
T t = directReference.get();
if (t == null) {
directReference = new WeakReference<>(t = reference.resolve(world).orElse(null));
}
return t;
}
public Optional<T> getOrEmpty(World world) {
return Optional.ofNullable(directReference.get())
.or(() -> reference == null ? Optional.empty() : reference.resolve(world))
.filter(this::set);
return Optional.ofNullable(get(world));
}
@Override
public void toNBT(NbtCompound tag, WrapperLookup lookup) {
getTarget().ifPresent(ref -> ref.toNBT(tag));
getTarget().ifPresent(ref -> EntityValues.CODEC.encode(ref, lookup.getOps(NbtOps.INSTANCE), tag));
}
@SuppressWarnings("unchecked")
@Override
public void fromNBT(NbtCompound tag, WrapperLookup lookup) {
this.reference = tag.contains("uuid") ? new EntityValues<>(tag) : null;
this.reference = (EntityValues<T>)NbtSerialisable.decode(EntityValues.CODEC, tag, lookup).orElse(null);
this.dirty = true;
if (reference != null) {
T value = directReference.get();
if (value != null) {
reference = new EntityValues<>(value);
}
}
}
@Override
@ -165,6 +187,16 @@ public class EntityReference<T extends Entity> implements NbtSerialisable, Track
boolean isDead,
Levelled.LevelStore level,
Levelled.LevelStore corruption) {
public static final Codec<EntityValues<?>> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Uuids.CODEC.fieldOf("uuid").forGetter(EntityValues::uuid),
CodecUtils.VECTOR.fieldOf("pos").forGetter(EntityValues::pos),
Codec.INT.fieldOf("clientId").forGetter(EntityValues::clientId),
Codec.BOOL.fieldOf("isPlayer").forGetter(EntityValues::isPlayer),
Codec.BOOL.fieldOf("isDead").forGetter(EntityValues::isDead),
Levelled.CODEC.fieldOf("level").forGetter(EntityValues::level),
Levelled.CODEC.fieldOf("corruption").forGetter(EntityValues::corruption)
).apply(instance, EntityValues::new));
public EntityValues(Entity entity) {
this(
entity.getUuid(),
@ -176,34 +208,17 @@ public class EntityReference<T extends Entity> implements NbtSerialisable, Track
);
}
public EntityValues(NbtCompound tag) {
this(
tag.getUuid("uuid"),
NbtSerialisable.readVector(tag.getList("pos", NbtElement.DOUBLE_TYPE)),
tag.getInt("clientId"),
tag.getBoolean("isPlayer"),
tag.getBoolean("isDead"),
Levelled.fromNbt(tag.getCompound("level")),
Levelled.fromNbt(tag.getCompound("corruption"))
);
}
@SuppressWarnings("unchecked")
public Optional<T> resolve(World world) {
if (world instanceof ServerWorld serverWorld) {
return Optional.ofNullable((T)serverWorld.getEntity(uuid));
}
return Optional.ofNullable((T)world.getEntityById(clientId()));
Entity target = world.getEntityById(clientId());
if (target == null || !target.getUuid().equals(uuid)) {
return Optional.empty();
}
public void toNBT(NbtCompound tag) {
tag.putUuid("uuid", uuid);
tag.put("pos", NbtSerialisable.writeVector(pos));
tag.putInt("clientId", clientId);
tag.putBoolean("isPlayer", isPlayer);
tag.putBoolean("isDead", isDead);
tag.put("level", level.toNbt());
tag.put("corruption", corruption.toNbt());
return Optional.of((T)target);
}
}
}

View file

@ -342,10 +342,10 @@ public class ButterflyEntity extends AmbientEntity {
nbt.putInt("ticksResting", ticksResting);
nbt.putInt("breedingCooldown", breedingCooldown);
hoveringPosition.ifPresent(pos -> {
nbt.put("hoveringPosition", NbtSerialisable.encode(BlockPos.CODEC, pos));
nbt.put("hoveringPosition", NbtSerialisable.encode(BlockPos.CODEC, pos, getRegistryManager()));
});
flowerPosition.ifPresent(pos -> {
nbt.put("flowerPosition", NbtSerialisable.encode(BlockPos.CODEC, pos));
nbt.put("flowerPosition", NbtSerialisable.encode(BlockPos.CODEC, pos, getRegistryManager()));
});
NbtCompound visited = new NbtCompound();
this.visited.forEach((pos, time) -> {
@ -359,8 +359,8 @@ public class ButterflyEntity extends AmbientEntity {
super.readCustomDataFromNbt(nbt);
ticksResting = nbt.getInt("ticksResting");
breedingCooldown = nbt.getInt("breedingCooldown");
hoveringPosition = NbtSerialisable.decode(BlockPos.CODEC, nbt.get("hoveringPosition"));
flowerPosition = NbtSerialisable.decode(BlockPos.CODEC, nbt.get("flowerPosition"));
hoveringPosition = NbtSerialisable.decode(BlockPos.CODEC, nbt.get("hoveringPosition"), getRegistryManager());
flowerPosition = NbtSerialisable.decode(BlockPos.CODEC, nbt.get("flowerPosition"), getRegistryManager());
NbtCompound visited = nbt.getCompound("visited");
this.visited.clear();
visited.getKeys().forEach(key -> {

View file

@ -19,6 +19,7 @@ import com.minelittlepony.unicopia.entity.MagicImmune;
import com.minelittlepony.unicopia.entity.Physics;
import com.minelittlepony.unicopia.network.track.Trackable;
import com.minelittlepony.unicopia.server.world.Ether;
import com.minelittlepony.unicopia.util.serialization.NbtSerialisable;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityDimensions;
@ -237,8 +238,8 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster<CastS
@Override
protected void writeCustomDataToNbt(NbtCompound tag) {
tag.put("level", level.toNbt());
tag.put("corruption", corruption.toNbt());
tag.put("level", NbtSerialisable.encode(Levelled.CODEC, level, getRegistryManager()));
tag.put("corruption", NbtSerialisable.encode(Levelled.CODEC, corruption, getRegistryManager()));
if (controllingEntityUuid != null) {
tag.putUuid("owningEntity", controllingEntityUuid);
@ -256,10 +257,10 @@ public class CastSpellEntity extends LightEmittingEntity implements Caster<CastS
@Override
protected void readCustomDataFromNbt(NbtCompound tag) {
var level = Levelled.fromNbt(tag.getCompound("level"));
var level = NbtSerialisable.decode(Levelled.CODEC, tag.get("level"), getRegistryManager()).orElse(Levelled.ZERO);
dataTracker.set(MAX_LEVEL, level.getMax());
dataTracker.set(LEVEL, level.get());
var corruption = Levelled.fromNbt(tag.getCompound("corruption"));
var corruption = NbtSerialisable.decode(Levelled.CODEC, tag.get("corruption"), getRegistryManager()).orElse(Levelled.ZERO);
dataTracker.set(MAX_CORRUPTION, corruption.getMax());
dataTracker.set(CORRUPTION, corruption.get());

View file

@ -165,7 +165,7 @@ public class FloatingArtefactEntity extends StationaryObjectEntity {
setState(State.valueOf(compound.getInt("State")));
setRotationSpeed(compound.getFloat("spin"), compound.getInt("spinDuration"));
ticksUntilRegen = compound.getInt("regen");
altar = NbtSerialisable.decode(Altar.CODEC, compound.get("altar"));
altar = NbtSerialisable.decode(Altar.CODEC, compound.get("altar"), getRegistryManager());
}
@Override
@ -173,13 +173,13 @@ public class FloatingArtefactEntity extends StationaryObjectEntity {
super.writeCustomDataToNbt(compound);
ItemStack stack = getStack();
if (!stack.isEmpty()) {
compound.put("Item", NbtSerialisable.encode(ItemStack.CODEC, stack));
compound.put("Item", NbtSerialisable.encode(ItemStack.CODEC, stack, getRegistryManager()));
}
compound.putInt("State", getState().ordinal());
compound.putFloat("spin", getRotationSpeed());
compound.putInt("spinDuration", boostDuration);
compound.putInt("regen", ticksUntilRegen);
altar.ifPresent(altar -> compound.put("altar", NbtSerialisable.encode(Altar.CODEC, altar)));
altar.ifPresent(altar -> compound.put("altar", NbtSerialisable.encode(Altar.CODEC, altar, getRegistryManager())));
}
@Override

View file

@ -392,8 +392,8 @@ public class SpellbookEntity extends MobEntity implements MagicImmune {
activeTicks = compound.getInt("activeTicks");
setAltered(compound.getBoolean("altered"));
setForcedState(compound.contains("locked") ? TriState.of(compound.getBoolean("locked")) : TriState.DEFAULT);
setSpellbookState(NbtSerialisable.decode(SpellbookState.CODEC, compound.getCompound("spellbookState")).orElse(new SpellbookState()));
altar = NbtSerialisable.decode(Altar.CODEC, compound.get("altar"));
setSpellbookState(NbtSerialisable.decode(SpellbookState.CODEC, compound.getCompound("spellbookState"), getRegistryManager()).orElse(new SpellbookState()));
altar = NbtSerialisable.decode(Altar.CODEC, compound.get("altar"), getRegistryManager());
}
@Override
@ -402,13 +402,13 @@ public class SpellbookEntity extends MobEntity implements MagicImmune {
compound.putInt("activeTicks", activeTicks);
compound.putBoolean("prevDaytime", prevDaytime);
compound.putBoolean("altered", isAltered());
compound.put("spellbookState", NbtSerialisable.encode(SpellbookState.CODEC, state));
compound.put("spellbookState", NbtSerialisable.encode(SpellbookState.CODEC, state, getRegistryManager()));
getForcedState().map(t -> {
compound.putBoolean("locked", t);
return null;
});
altar.ifPresent(altar -> {
compound.put("altar", NbtSerialisable.encode(Altar.CODEC, altar));
compound.put("altar", NbtSerialisable.encode(Altar.CODEC, altar, getRegistryManager()));
});
}

View file

@ -201,13 +201,13 @@ public class Acrobatics implements Tickable, NbtSerialisable {
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
compound.putInt("ticksHanging", ticksHanging);
getHangingPosition().ifPresent(pos -> {
compound.put("hangingPosition", NbtSerialisable.encode(BlockPos.CODEC, pos));
compound.put("hangingPosition", NbtSerialisable.encode(BlockPos.CODEC, pos, lookup));
});
}
@Override
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
ticksHanging = compound.getInt("ticksHanging");
hangingPos.set(NbtSerialisable.decode(BlockPos.CODEC, compound.get("hangingPosition")));
hangingPos.set(NbtSerialisable.decode(BlockPos.CODEC, compound.get("hangingPosition"), lookup));
}
}

View file

@ -21,6 +21,8 @@ import com.minelittlepony.unicopia.entity.EntityPhysics;
import com.minelittlepony.unicopia.entity.MagicImmune;
import com.minelittlepony.unicopia.entity.Physics;
import com.minelittlepony.unicopia.entity.mob.UEntities;
import com.minelittlepony.unicopia.util.serialization.NbtSerialisable;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.data.DataTracker;
@ -181,10 +183,10 @@ public class MagicBeamEntity extends MagicProjectileEntity implements Caster<Mag
getDataTracker().set(HYDROPHOBIC, compound.getBoolean("hydrophobic"));
physics.fromNBT(compound, getRegistryManager());
spells.getSlots().fromNBT(compound, getRegistryManager());
var level = Levelled.fromNbt(compound.getCompound("level"));
var level = NbtSerialisable.decode(Levelled.CODEC, compound.get("level"), getRegistryManager()).orElse(Levelled.ZERO);
dataTracker.set(MAX_LEVEL, level.getMax());
dataTracker.set(LEVEL, level.get());
var corruption = Levelled.fromNbt(compound.getCompound("corruption"));
var corruption = NbtSerialisable.decode(Levelled.CODEC, compound.get("corruption"), getRegistryManager()).orElse(Levelled.ZERO);
dataTracker.set(MAX_CORRUPTION, corruption.getMax());
dataTracker.set(CORRUPTION, corruption.get());
}
@ -192,8 +194,8 @@ public class MagicBeamEntity extends MagicProjectileEntity implements Caster<Mag
@Override
public void writeCustomDataToNbt(NbtCompound compound) {
super.writeCustomDataToNbt(compound);
compound.put("level", level.toNbt());
compound.put("corruption", corruption.toNbt());
compound.put("level", NbtSerialisable.encode(Levelled.CODEC, level, getRegistryManager()));
compound.put("corruption", NbtSerialisable.encode(Levelled.CODEC, corruption, getRegistryManager()));
compound.putBoolean("hydrophobic", getHydrophobic());
physics.toNBT(compound, getRegistryManager());
spells.getSlots().toNBT(compound, getRegistryManager());

View file

@ -16,7 +16,6 @@ import com.minelittlepony.unicopia.entity.EntityReference;
import com.minelittlepony.unicopia.server.world.chunk.PositionalDataMap;
import com.minelittlepony.unicopia.util.Tickable;
import com.minelittlepony.unicopia.util.serialization.NbtSerialisable;
import net.minecraft.nbt.*;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.Identifier;

View file

@ -44,7 +44,7 @@ public class UnicopiaWorldProperties extends PersistentState {
this(world);
defaultRace = Race.fromName(tag.getString("defaultRace"), Race.HUMAN);
tangentalSkyAngle = tag.getFloat("tangentalSkyAngle");
NbtSerialisable.decode(POS_CODEC, tag.getList("activeAltars", NbtElement.COMPOUND_TYPE)).ifPresent(activeAltarPositions::addAll);
NbtSerialisable.decode(POS_CODEC, tag.getList("activeAltars", NbtElement.COMPOUND_TYPE), world.getRegistryManager()).ifPresent(activeAltarPositions::addAll);
}
public Race getDefaultRace() {
@ -94,7 +94,7 @@ public class UnicopiaWorldProperties extends PersistentState {
public NbtCompound writeNbt(NbtCompound tag, WrapperLookup lookup) {
tag.putString("defaultRace", Race.REGISTRY.getId(defaultRace).toString());
tag.putFloat("tangentalSkyAngle", tangentalSkyAngle);
tag.put("activeAltars", NbtSerialisable.encode(POS_CODEC, activeAltarPositions));
tag.put("activeAltars", NbtSerialisable.encode(POS_CODEC, activeAltarPositions, lookup));
return tag;
}
}

View file

@ -0,0 +1,8 @@
package com.minelittlepony.unicopia.util;
public interface Untyped {
@SuppressWarnings("unchecked")
static <K, T extends K> T cast(K t) {
return (T)t;
}
}

View file

@ -5,7 +5,6 @@ import java.util.Optional;
import java.util.Set;
import java.util.function.Supplier;
import java.util.stream.Collectors;
import com.mojang.datafixers.util.Either;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Codec;

View file

@ -48,12 +48,12 @@ public class NbtMap<K, V> implements NbtSerialisable {
@Override
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
compound.put("data", NbtSerialisable.encode(codec, data));
compound.put("data", NbtSerialisable.encode(codec, data, lookup));
}
@Override
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
data.clear();
NbtSerialisable.decode(codec, compound.get("data")).ifPresent(data::putAll);
NbtSerialisable.decode(codec, compound.get("data"), lookup).ifPresent(data::putAll);
}
}

View file

@ -3,20 +3,15 @@ package com.minelittlepony.unicopia.util.serialization;
import java.util.*;
import java.util.function.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Codec;
import net.minecraft.nbt.*;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
public interface NbtSerialisable {
@Deprecated
Serializer<NbtElement, BlockPos> BLOCK_POS = Serializer.ofCodec(BlockPos.CODEC);
/**
* Called to save this to nbt to persist state on file or to transmit over the network
*
@ -45,18 +40,18 @@ public interface NbtSerialisable {
return list;
}
static <T> Optional<T> decode(Codec<T> codec, NbtElement nbt, WrapperLookup lookup) {
return codec.decode(lookup.getOps(NbtOps.INSTANCE), nbt).result().map(Pair::getFirst);
}
static <T> NbtElement encode(Codec<T> codec, T value, WrapperLookup lookup) {
return codec.encodeStart(lookup.getOps(NbtOps.INSTANCE), value).result().get();
}
static Vec3d readVector(NbtList list) {
return new Vec3d(list.getDouble(0), list.getDouble(1), list.getDouble(2));
}
static <T> Optional<T> decode(Codec<T> codec, NbtElement nbt) {
return codec.decode(NbtOps.INSTANCE, nbt).result().map(Pair::getFirst);
}
static <T> NbtElement encode(Codec<T> codec, T value) {
return codec.encodeStart(NbtOps.INSTANCE, value).result().get();
}
static NbtCompound subTag(String name, NbtCompound parent) {
NbtCompound child = new NbtCompound();
parent.put(name, child);
@ -96,59 +91,4 @@ public interface NbtSerialisable {
map.forEach((k, v) -> nbt.put(keyFunction.apply(k), valueFunction.apply(v)));
return nbt;
}
@Deprecated
interface Serializer<N extends NbtElement, T> {
T read(N compound, WrapperLookup lookup);
N write(T t, WrapperLookup lookup);
@SuppressWarnings("unchecked")
default Optional<T> readOptional(String name, NbtCompound compound, WrapperLookup lookup) {
return compound.contains(name, NbtElement.COMPOUND_TYPE)
? Optional.ofNullable(read((N)compound.get(name), lookup))
: Optional.empty();
}
default void writeOptional(String name, NbtCompound compound, Optional<T> t, WrapperLookup lookup) {
t.map(l -> write(l, lookup)).ifPresent(tag -> compound.put(name, tag));
}
default NbtList writeAll(Collection<? extends T> ts, WrapperLookup lookup) {
NbtList list = new NbtList();
ts.stream().map(l -> write(l, lookup)).forEach(list::add);
return list;
}
@SuppressWarnings("unchecked")
default Stream<T> readAll(NbtList list, WrapperLookup lookup) {
return list.stream().map(l -> read((N)l, lookup)).filter(Objects::nonNull);
}
static <T extends NbtSerialisable> Serializer<NbtCompound, T> of(Supplier<T> factory) {
return of((nbt, lookup) -> {
T value = factory.get();
value.fromNBT(nbt, lookup);
return value;
}, (value, lookup) -> value.toNBT(lookup));
}
static <T> Serializer<NbtElement, T> ofCodec(Codec<T> codec) {
return of((value, lookup) -> decode(codec, value).get(), (t, lookup) -> encode(codec, t));
}
static <N extends NbtElement, T> Serializer<N, T> of(BiFunction<N, WrapperLookup, T> read, BiFunction<T, WrapperLookup, N> write) {
return new Serializer<>() {
@Override
public T read(N compound, WrapperLookup lookup) {
return read.apply(compound, lookup);
}
@Override
public N write(T t, WrapperLookup lookup) {
return write.apply(t, lookup);
}
};
}
}
}