diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/Levelled.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/Levelled.java index 2ea5d1e4..2b2e1c13 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/Levelled.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/Levelled.java @@ -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 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; - } } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ChangelingFeedingSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ChangelingFeedingSpell.java index 256b83f2..3c7079e9 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ChangelingFeedingSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/ChangelingFeedingSpell.java @@ -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.getSerializer().writeAll(targets, lookup)); + compound.put("targets", NbtSerialisable.encode(EntityReference.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.getSerializer().readAll(compound.getList("targets", NbtElement.COMPOUND_TYPE), lookup).toList() - : List.of(); + targets = NbtSerialisable.decode(EntityReference.listCodec(), compound.get("targets"), lookup).orElse(List.of()); } } diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/Spell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/Spell.java index 34ea7dac..cb97fd56 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/Spell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/Spell.java @@ -25,9 +25,6 @@ import net.minecraft.util.Util; * Interface for a magic spells */ public interface Spell extends NbtSerialisable, Affine { - @Deprecated - Serializer SERIALIZER = Serializer.of(Spell::readNbt, Spell::writeNbt); - /** * Returns the full type that describes this spell. */ diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/HydrophobicSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/HydrophobicSpell.java index 3c0660b4..559ae527 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/HydrophobicSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/HydrophobicSpell.java @@ -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. diff --git a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/MindSwapSpell.java b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/MindSwapSpell.java index 2aace703..bea32dec 100644 --- a/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/MindSwapSpell.java +++ b/src/main/java/com/minelittlepony/unicopia/ability/magic/spell/effect/MindSwapSpell.java @@ -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) { diff --git a/src/main/java/com/minelittlepony/unicopia/block/CrystalDoorBlock.java b/src/main/java/com/minelittlepony/unicopia/block/CrystalDoorBlock.java index 383e73a4..54f078ce 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/CrystalDoorBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/CrystalDoorBlock.java @@ -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)) { diff --git a/src/main/java/com/minelittlepony/unicopia/block/EdibleBlock.java b/src/main/java/com/minelittlepony/unicopia/block/EdibleBlock.java index a6f02b56..e9a9351c 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/EdibleBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/EdibleBlock.java @@ -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); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/FancyBedBlock.java b/src/main/java/com/minelittlepony/unicopia/block/FancyBedBlock.java index 3084f960..d786ffb9 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/FancyBedBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/FancyBedBlock.java @@ -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(); diff --git a/src/main/java/com/minelittlepony/unicopia/block/FrostedObsidianBlock.java b/src/main/java/com/minelittlepony/unicopia/block/FrostedObsidianBlock.java index 74fe4eb4..6dd716ce 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/FrostedObsidianBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/FrostedObsidianBlock.java @@ -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 getCodec() { - return (MapCodec)CODEC; + return Untyped.cast(CODEC); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/block/FruitBlock.java b/src/main/java/com/minelittlepony/unicopia/block/FruitBlock.java index 144679f4..faec45eb 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/FruitBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/FruitBlock.java @@ -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()); diff --git a/src/main/java/com/minelittlepony/unicopia/block/GrowableBlock.java b/src/main/java/com/minelittlepony/unicopia/block/GrowableBlock.java index 8064dcad..1f9cbf08 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/GrowableBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/GrowableBlock.java @@ -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; diff --git a/src/main/java/com/minelittlepony/unicopia/block/HiveBlock.java b/src/main/java/com/minelittlepony/unicopia/block/HiveBlock.java index cc10b670..03996078 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/HiveBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/HiveBlock.java @@ -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 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 data) { + public static final Codec 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_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); } } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/ItemJarBlock.java b/src/main/java/com/minelittlepony/unicopia/block/ItemJarBlock.java index d16307cf..5db566f6 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/ItemJarBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/ItemJarBlock.java @@ -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")); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/JarBlock.java b/src/main/java/com/minelittlepony/unicopia/block/JarBlock.java index 90c0c119..aa1975e5 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/JarBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/JarBlock.java @@ -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); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/OrientedBlock.java b/src/main/java/com/minelittlepony/unicopia/block/OrientedBlock.java index ab29c137..ca8eadd2 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/OrientedBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/OrientedBlock.java @@ -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))); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/PieBlock.java b/src/main/java/com/minelittlepony/unicopia/block/PieBlock.java index 401d1f8f..b7daf0bf 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/PieBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/PieBlock.java @@ -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; } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/PileBlock.java b/src/main/java/com/minelittlepony/unicopia/block/PileBlock.java index 2137c48b..0ae73666 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/PileBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/PileBlock.java @@ -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(); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/PineappleCropBlock.java b/src/main/java/com/minelittlepony/unicopia/block/PineappleCropBlock.java index cdb11f48..04aa3429 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/PineappleCropBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/PineappleCropBlock.java @@ -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); diff --git a/src/main/java/com/minelittlepony/unicopia/block/RockCropBlock.java b/src/main/java/com/minelittlepony/unicopia/block/RockCropBlock.java index efe80127..604d8e3a 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/RockCropBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/RockCropBlock.java @@ -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) { diff --git a/src/main/java/com/minelittlepony/unicopia/block/SegmentedCropBlock.java b/src/main/java/com/minelittlepony/unicopia/block/SegmentedCropBlock.java index d1d98d72..685d0916 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/SegmentedCropBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/SegmentedCropBlock.java @@ -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); diff --git a/src/main/java/com/minelittlepony/unicopia/block/ShellsBlock.java b/src/main/java/com/minelittlepony/unicopia/block/ShellsBlock.java index b51da671..5e369fe6 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/ShellsBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/ShellsBlock.java @@ -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); } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/SlimePustuleBlock.java b/src/main/java/com/minelittlepony/unicopia/block/SlimePustuleBlock.java index 94f04f1f..2d5cf2f2 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/SlimePustuleBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/SlimePustuleBlock.java @@ -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; } diff --git a/src/main/java/com/minelittlepony/unicopia/block/SpectralFireBlock.java b/src/main/java/com/minelittlepony/unicopia/block/SpectralFireBlock.java index b9bbd104..311ccfd6 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/SpectralFireBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/SpectralFireBlock.java @@ -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); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/SpikesBlock.java b/src/main/java/com/minelittlepony/unicopia/block/SpikesBlock.java index af004548..820459c4 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/SpikesBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/SpikesBlock.java @@ -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; } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/SproutBlock.java b/src/main/java/com/minelittlepony/unicopia/block/SproutBlock.java index 20168e29..34cd687b 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/SproutBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/SproutBlock.java @@ -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)) { diff --git a/src/main/java/com/minelittlepony/unicopia/block/StableDoorBlock.java b/src/main/java/com/minelittlepony/unicopia/block/StableDoorBlock.java index 425cfd17..024d62cf 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/StableDoorBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/StableDoorBlock.java @@ -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)) { diff --git a/src/main/java/com/minelittlepony/unicopia/block/ThornBlock.java b/src/main/java/com/minelittlepony/unicopia/block/ThornBlock.java index f6fd0395..a93f23ad 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/ThornBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/ThornBlock.java @@ -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)) diff --git a/src/main/java/com/minelittlepony/unicopia/block/ThornBudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/ThornBudBlock.java index 86182c1c..414e5ebb 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/ThornBudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/ThornBudBlock.java @@ -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(); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/WeatherVaneBlock.java b/src/main/java/com/minelittlepony/unicopia/block/WeatherVaneBlock.java index dbd6034f..a18acd8f 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/WeatherVaneBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/WeatherVaneBlock.java @@ -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; } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBedBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBedBlock.java index e674cfe6..d1214bc0 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBedBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBedBlock.java @@ -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); } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBlock.java index db80cfcc..c060eabd 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudBlock.java @@ -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); diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudChestBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudChestBlock.java index 39e5d2c5..0669a772 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudChestBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudChestBlock.java @@ -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(); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudDoorBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudDoorBlock.java index 80923d5a..a17f7685 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudDoorBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudDoorBlock.java @@ -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); } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudPillarBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudPillarBlock.java index 2c646726..96ffb6ca 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudPillarBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudPillarBlock.java @@ -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); } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudSlabBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudSlabBlock.java index e29282f5..8eda80e8 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudSlabBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudSlabBlock.java @@ -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; diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudStairsBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudStairsBlock.java index 5201f703..8abf60ab 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudStairsBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CloudStairsBlock.java @@ -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); } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/CompactedCloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/CompactedCloudBlock.java index 5de3e532..ab5621c8 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/CompactedCloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/CompactedCloudBlock.java @@ -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); } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/NaturalCloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/NaturalCloudBlock.java index fe00ca9b..c8bea7bf 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/NaturalCloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/NaturalCloudBlock.java @@ -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)); diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/OrientedCloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/OrientedCloudBlock.java index 52cd3d79..f8d829f4 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/OrientedCloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/OrientedCloudBlock.java @@ -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()); } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/PoreousCloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/PoreousCloudBlock.java index 04a21112..12e312ce 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/PoreousCloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/PoreousCloudBlock.java @@ -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)); diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/ShapingBenchBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/ShapingBenchBlock.java index 1eec2c05..2a2c8a47 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/ShapingBenchBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/ShapingBenchBlock.java @@ -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; } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/SoggyCloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/SoggyCloudBlock.java index 2cc6fcfe..945bbb6c 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/SoggyCloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/SoggyCloudBlock.java @@ -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); } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/SoggyCloudSlabBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/SoggyCloudSlabBlock.java index 4983effe..6ca54b55 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/SoggyCloudSlabBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/SoggyCloudSlabBlock.java @@ -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); } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/cloud/WaterloggableCloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/cloud/WaterloggableCloudBlock.java index d35aeed0..2bce9024 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/cloud/WaterloggableCloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/cloud/WaterloggableCloudBlock.java @@ -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); } } diff --git a/src/main/java/com/minelittlepony/unicopia/block/jar/FluidOnlyJarContents.java b/src/main/java/com/minelittlepony/unicopia/block/jar/FluidOnlyJarContents.java index 4ab39cf8..115a2a68 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/jar/FluidOnlyJarContents.java +++ b/src/main/java/com/minelittlepony/unicopia/block/jar/FluidOnlyJarContents.java @@ -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; } diff --git a/src/main/java/com/minelittlepony/unicopia/block/jar/ItemsJarContents.java b/src/main/java/com/minelittlepony/unicopia/block/jar/ItemsJarContents.java index 5bcb929a..5f28bf56 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/jar/ItemsJarContents.java +++ b/src/main/java/com/minelittlepony/unicopia/block/jar/ItemsJarContents.java @@ -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; } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntityReference.java b/src/main/java/com/minelittlepony/unicopia/entity/EntityReference.java index f6e0b5c2..93f955b1 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntityReference.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/EntityReference.java @@ -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 The type of the entity this reference points to. */ public class EntityReference implements NbtSerialisable, TrackableObject> { - private static final Serializer SERIALIZER = Serializer.of(EntityReference::new); + public static final Codec> CODEC = EntityValues.CODEC.xmap(r -> new EntityReference<>(r), r -> r.reference); + public static final Codec>> LIST_CODEC = CODEC.listOf(); - @SuppressWarnings("unchecked") - public static Serializer> getSerializer() { - return (Serializer>)SERIALIZER; + public static Codec>> codec() { + return Untyped.cast(CODEC); + } + + public static Codec>> listCodec() { + return Untyped.cast(LIST_CODEC); } @Nullable private EntityValues reference; - private WeakReference directReference = new WeakReference<>(null); private boolean dirty = true; @@ -57,6 +66,10 @@ public class EntityReference implements NbtSerialisable, Track fromNBT(nbt, lookup); } + private EntityReference(EntityValues reference) { + this.reference = reference; + } + @SuppressWarnings("unchecked") public void copyFrom(EntityReference other) { this.reference = ((EntityReference)other).reference; @@ -102,24 +115,33 @@ public class EntityReference 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 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)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 implements NbtSerialisable, Track boolean isDead, Levelled.LevelStore level, Levelled.LevelStore corruption) { + public static final Codec> 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 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 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); } } } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/ButterflyEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/ButterflyEntity.java index b3380d5f..f150e91f 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/ButterflyEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/ButterflyEntity.java @@ -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 -> { diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java index bc3cf790..ab6a367c 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/CastSpellEntity.java @@ -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 compound.put("altar", NbtSerialisable.encode(Altar.CODEC, altar))); + altar.ifPresent(altar -> compound.put("altar", NbtSerialisable.encode(Altar.CODEC, altar, getRegistryManager()))); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/entity/mob/SpellbookEntity.java b/src/main/java/com/minelittlepony/unicopia/entity/mob/SpellbookEntity.java index 2d783a08..a01cf94b 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/mob/SpellbookEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/mob/SpellbookEntity.java @@ -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())); }); } diff --git a/src/main/java/com/minelittlepony/unicopia/entity/player/Acrobatics.java b/src/main/java/com/minelittlepony/unicopia/entity/player/Acrobatics.java index e25492dd..f99d5213 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/player/Acrobatics.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/player/Acrobatics.java @@ -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)); } } diff --git a/src/main/java/com/minelittlepony/unicopia/projectile/MagicBeamEntity.java b/src/main/java/com/minelittlepony/unicopia/projectile/MagicBeamEntity.java index 168ea2bb..2181189e 100644 --- a/src/main/java/com/minelittlepony/unicopia/projectile/MagicBeamEntity.java +++ b/src/main/java/com/minelittlepony/unicopia/projectile/MagicBeamEntity.java @@ -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 T cast(K t) { + return (T)t; + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/util/serialization/CodecUtils.java b/src/main/java/com/minelittlepony/unicopia/util/serialization/CodecUtils.java index 5633cf81..a2fa1e17 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/serialization/CodecUtils.java +++ b/src/main/java/com/minelittlepony/unicopia/util/serialization/CodecUtils.java @@ -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; diff --git a/src/main/java/com/minelittlepony/unicopia/util/serialization/NbtMap.java b/src/main/java/com/minelittlepony/unicopia/util/serialization/NbtMap.java index 84127d58..c1bdaaa9 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/serialization/NbtMap.java +++ b/src/main/java/com/minelittlepony/unicopia/util/serialization/NbtMap.java @@ -48,12 +48,12 @@ public class NbtMap 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); } } diff --git a/src/main/java/com/minelittlepony/unicopia/util/serialization/NbtSerialisable.java b/src/main/java/com/minelittlepony/unicopia/util/serialization/NbtSerialisable.java index a48674e0..62da0a4b 100644 --- a/src/main/java/com/minelittlepony/unicopia/util/serialization/NbtSerialisable.java +++ b/src/main/java/com/minelittlepony/unicopia/util/serialization/NbtSerialisable.java @@ -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 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 Optional decode(Codec codec, NbtElement nbt, WrapperLookup lookup) { + return codec.decode(lookup.getOps(NbtOps.INSTANCE), nbt).result().map(Pair::getFirst); + } + + static NbtElement encode(Codec 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 Optional decode(Codec codec, NbtElement nbt) { - return codec.decode(NbtOps.INSTANCE, nbt).result().map(Pair::getFirst); - } - - static NbtElement encode(Codec 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 { - T read(N compound, WrapperLookup lookup); - - N write(T t, WrapperLookup lookup); - - @SuppressWarnings("unchecked") - default Optional 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, WrapperLookup lookup) { - t.map(l -> write(l, lookup)).ifPresent(tag -> compound.put(name, tag)); - } - - default NbtList writeAll(Collection ts, WrapperLookup lookup) { - NbtList list = new NbtList(); - ts.stream().map(l -> write(l, lookup)).forEach(list::add); - return list; - } - - @SuppressWarnings("unchecked") - default Stream readAll(NbtList list, WrapperLookup lookup) { - return list.stream().map(l -> read((N)l, lookup)).filter(Objects::nonNull); - } - - static Serializer of(Supplier factory) { - return of((nbt, lookup) -> { - T value = factory.get(); - value.fromNBT(nbt, lookup); - return value; - }, (value, lookup) -> value.toNBT(lookup)); - } - - static Serializer ofCodec(Codec codec) { - return of((value, lookup) -> decode(codec, value).get(), (t, lookup) -> encode(codec, t)); - } - - static Serializer of(BiFunction read, BiFunction 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); - } - }; - } - } }