Clean up deprications

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

View file

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

View file

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

View file

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

View file

@ -135,14 +135,14 @@ public class HydrophobicSpell extends AbstractSpell {
@Override @Override
public void toNBT(NbtCompound compound, WrapperLookup lookup) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound, 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 @Override
public void fromNBT(NbtCompound compound, WrapperLookup lookup) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound, lookup); super.fromNBT(compound, lookup);
storedFluidPositions.clear(); 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. * Calculates the maximum radius of the shield. aka The area of effect.

View file

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

View file

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

View file

@ -148,7 +148,7 @@ public class EdibleBlock extends HayBlock {
} }
@Override @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); return SHAPE_CACHE.apply(state);
} }

View file

@ -71,13 +71,12 @@ public class FancyBedBlock extends BedBlock {
} }
@Override @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)); return SHAPES.get(state.get(PART).ordinal()).apply(BedBlock.getOppositePartDirection(state));
} }
@Deprecated
@Override @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) { if (state.hasBlockEntity() && !state.isOf(newState.getBlock()) && state.get(PART) == BedPart.HEAD) {
world.getBlockEntity(pos, UBlockEntities.FANCY_BED).ifPresent(tile -> { world.getBlockEntity(pos, UBlockEntities.FANCY_BED).ifPresent(tile -> {
SheetPattern pattern = tile.getPattern(); SheetPattern pattern = tile.getPattern();

View file

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

View file

@ -71,20 +71,19 @@ public class FruitBlock extends Block implements Buckable {
} }
@Override @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; return shape;
} }
@Override @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()); BlockPos attachedPos = pos.offset(attachmentFace.getOpposite());
BlockState attachedState = world.getBlockState(attachedPos); BlockState attachedState = world.getBlockState(attachedPos);
return canAttachTo(attachedState); return canAttachTo(attachedState);
} }
@Deprecated
@Override @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)) { if (!state.canPlaceAt(world, pos)) {
return Blocks.AIR.getDefaultState(); return Blocks.AIR.getDefaultState();
} }
@ -92,15 +91,14 @@ public class FruitBlock extends Block implements Buckable {
} }
@Override @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)) { if (!state.canPlaceAt(world, pos)) {
world.breakBlock(pos, true); world.breakBlock(pos, true);
} }
} }
@Deprecated
@Override @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); super.onStateReplaced(state, world, pos, newState, moved);
if (!newState.isOf(state.getBlock())) { if (!newState.isOf(state.getBlock())) {
BlockState leaves = world.getBlockState(pos.up()); BlockState leaves = world.getBlockState(pos.up());

View file

@ -73,7 +73,7 @@ public class GrowableBlock extends SpreadableBlock {
} }
@Override @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)) { if (!canSurvive(state, world, pos)) {
world.setBlockState(pos, dead.get().getDefaultState()); world.setBlockState(pos, dead.get().getDefaultState());
return; return;

View file

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

View file

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

View file

@ -59,13 +59,12 @@ public class JarBlock extends TransparentBlock implements Waterloggable {
} }
@Override @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; return SHAPE;
} }
@Deprecated
@Override @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)) { if (state.get(WATERLOGGED)) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); 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); return getDefaultState().with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER);
} }
@Deprecated
@Override @Override
public FluidState getFluidState(BlockState state) { protected FluidState getFluidState(BlockState state) {
return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); return state.get(WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state);
} }

View file

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

View file

@ -72,15 +72,13 @@ public class PieBlock extends Block implements Waterloggable {
return CODEC; return CODEC;
} }
@Deprecated
@Override @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)]; return SHAPES[state.get(BITES)];
} }
@Deprecated
@Override @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) { if (world.isClient) {
@ -180,9 +178,8 @@ public class PieBlock extends Block implements Waterloggable {
} }
} }
@Deprecated
@Override @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)) { if (direction == Direction.DOWN && !state.canPlaceAt(world, pos)) {
return Blocks.AIR.getDefaultState(); return Blocks.AIR.getDefaultState();
} }
@ -192,13 +189,11 @@ public class PieBlock extends Block implements Waterloggable {
return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos); return super.getStateForNeighborUpdate(state, direction, neighborState, world, pos, neighborPos);
} }
@Deprecated
@Override @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); return world.getBlockState(pos.down()).isSideSolidFullSquare(world, pos, Direction.UP);
} }
@Deprecated
@Override @Override
public BlockState getPlacementState(ItemPlacementContext ctx) { public BlockState getPlacementState(ItemPlacementContext ctx) {
return super.getDefaultState() return super.getDefaultState()
@ -206,9 +201,8 @@ public class PieBlock extends Block implements Waterloggable {
.with(STOMPED, ctx.getStack().isOf(UItems.APPLE_PIE_HOOF)); .with(STOMPED, ctx.getStack().isOf(UItems.APPLE_PIE_HOOF));
} }
@Deprecated
@Override @Override
public FluidState getFluidState(BlockState state) { protected FluidState getFluidState(BlockState state) {
if (state.get(WATERLOGGED)) { if (state.get(WATERLOGGED)) {
return Fluids.WATER.getStill(false); return Fluids.WATER.getStill(false);
} }
@ -221,17 +215,17 @@ public class PieBlock extends Block implements Waterloggable {
} }
@Override @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; return (5 - state.get(BITES)) * 2;
} }
@Override @Override
public boolean hasComparatorOutput(BlockState state) { protected boolean hasComparatorOutput(BlockState state) {
return true; return true;
} }
@Override @Override
public boolean canPathfindThrough(BlockState state, NavigationType type) { protected boolean canPathfindThrough(BlockState state, NavigationType type) {
return false; return false;
} }
} }

View file

@ -58,7 +58,7 @@ public class PileBlock extends Block implements Waterloggable {
} }
@Override @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); Vec3d offset = state.getModelOffset(world, pos);
return shapes[state.get(COUNT) - 1].offset(offset.x, offset.y, offset.z); 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 @Override
public boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) { protected boolean canPlaceAt(BlockState state, WorldView world, BlockPos pos) {
pos = pos.down(); pos = pos.down();
return world.getBlockState(pos).isSideSolid(world, pos, Direction.UP, SideShapeType.CENTER); return world.getBlockState(pos).isSideSolid(world, pos, Direction.UP, SideShapeType.CENTER);
} }
@Deprecated
@Override @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); return (!context.shouldCancelInteraction() && context.getStack().isOf(asItem()) && state.get(COUNT) < MAX_COUNT) || super.canReplace(state, context);
} }
@Deprecated
@Override @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)) { if (!state.canPlaceAt(world, pos)) {
return Blocks.AIR.getDefaultState(); return Blocks.AIR.getDefaultState();
} }

View file

@ -60,7 +60,7 @@ public class PineappleCropBlock extends CropBlock {
} }
@Override @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)) { if (direction == Direction.UP && !neighborState.isOf(this)) {
return state.with(AGE, Math.min(state.get(AGE), getMaxAge() - 1)); return state.with(AGE, Math.min(state.get(AGE), getMaxAge() - 1));
} }
@ -68,7 +68,7 @@ public class PineappleCropBlock extends CropBlock {
} }
@Override @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) { if (state.get(HALF) == BlockHalf.BOTTOM) {
super.randomTick(state, world, pos, random); super.randomTick(state, world, pos, random);

View file

@ -75,20 +75,19 @@ public class RockCropBlock extends CropBlock {
} }
@Override @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())]; return AGE_TO_SHAPE[state.get(getAgeProperty())];
} }
@Override @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)) { if (canGrow(world, random, pos, state)) {
super.randomTick(state, world, pos, random); super.randomTick(state, world, pos, random);
} }
} }
@Override @Override
@Deprecated protected void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
super.onStateReplaced(state, world, pos, newState, moved); super.onStateReplaced(state, world, pos, newState, moved);
if (!moved && !(state.getBlock() == this && newState.getBlock() == this)) { if (!moved && !(state.getBlock() == this && newState.getBlock() == this)) {
if (!world.isClient) { if (!world.isClient) {

View file

@ -99,7 +99,7 @@ public class SegmentedCropBlock extends CropBlock implements SegmentedBlock {
} }
@Override @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 tip = getTip(world, pos);
BlockPos root = getRoot(world, pos); BlockPos root = getRoot(world, pos);
@ -119,7 +119,7 @@ public class SegmentedCropBlock extends CropBlock implements SegmentedBlock {
} }
@Override @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); 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 @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)) { if (direction == Direction.UP && !isNext(neighborState)) {
return state.with(getAgeProperty(), Math.min(state.get(getAgeProperty()), getMaxAge() - 1)); return state.with(getAgeProperty(), Math.min(state.get(getAgeProperty()), getMaxAge() - 1));
} }
@ -142,7 +142,7 @@ public class SegmentedCropBlock extends CropBlock implements SegmentedBlock {
} }
@Override @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 tip = getTip(world, pos);
BlockPos root = getRoot(world, pos); BlockPos root = getRoot(world, pos);

View file

@ -40,8 +40,7 @@ public class ShellsBlock extends Block implements Waterloggable {
} }
@Override @Override
@Deprecated protected VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
return SHAPE; 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); return getDefaultState().with(WATERLOGGED, ctx.getWorld().getFluidState(ctx.getBlockPos()).getFluid() == Fluids.WATER);
} }
@Deprecated
@Override @Override
public FluidState getFluidState(BlockState state) { protected FluidState getFluidState(BlockState state) {
if (state.get(WATERLOGGED).booleanValue()) { if (state.get(WATERLOGGED).booleanValue()) {
return Fluids.WATER.getStill(false); return Fluids.WATER.getStill(false);
} }
return super.getFluidState(state); return super.getFluidState(state);
} }
@Deprecated
@Override @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()) { if (state.get(WATERLOGGED).booleanValue()) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
} }
@ -76,7 +73,7 @@ public class ShellsBlock extends Block implements Waterloggable {
} }
@Override @Override
public boolean canPathfindThrough(BlockState state, NavigationType type) { protected boolean canPathfindThrough(BlockState state, NavigationType type) {
return (type == NavigationType.WATER) == state.getFluidState().isIn(FluidTags.WATER); return (type == NavigationType.WATER) == state.getFluidState().isIn(FluidTags.WATER);
} }
} }

View file

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

View file

@ -14,7 +14,7 @@ public class SpectralFireBlock extends SoulFireBlock {
} }
@Override @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)) { if (!(entity instanceof ItemEntity)) {
super.onEntityCollision(state, world, pos, entity); super.onEntityCollision(state, world, pos, entity);
} }

View file

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

View file

@ -68,12 +68,12 @@ public class SproutBlock extends CropBlock implements TintedBlock {
} }
@Override @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())]; return AGE_TO_SHAPE[state.get(getAgeProperty())];
} }
@Override @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); super.randomTick(state, world, pos, random);
state = world.getBlockState(pos); state = world.getBlockState(pos);
if (state.isOf(this)) { if (state.isOf(this)) {

View file

@ -28,7 +28,7 @@ public class StableDoorBlock extends DoorBlock {
} }
@Override @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); DoubleBlockHalf half = state.get(HALF);
if (direction.getAxis() == Direction.Axis.Y && half == DoubleBlockHalf.LOWER == (direction == Direction.UP)) { if (direction.getAxis() == Direction.Axis.Y && half == DoubleBlockHalf.LOWER == (direction == Direction.UP)) {

View file

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

View file

@ -55,14 +55,14 @@ public class ThornBudBlock extends Block implements EarthPonyGrowAbility.Growabl
} }
@Override @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) { if (random.nextInt(50) == 0) {
grow(world, state, pos); grow(world, state, pos);
} }
} }
@Override @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()))) { if (direction == state.get(FACING) && !(neighborState.isOf(this) || neighborState.isOf(branchState.getBlock()))) {
return Blocks.AIR.getDefaultState(); return Blocks.AIR.getDefaultState();
} }

View file

@ -39,9 +39,8 @@ public class WeatherVaneBlock extends BlockWithEntity {
return CODEC; return CODEC;
} }
@Deprecated
@Override @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; return SHAPE;
} }

View file

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

View file

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

View file

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

View file

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

View file

@ -89,9 +89,8 @@ public class CloudPillarBlock extends CloudBlock {
.with(AXIS, axis); .with(AXIS, axis);
} }
@Deprecated
@Override @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)) { if (direction.getAxis() == state.get(AXIS)) {
return state.with(DIRECTION_PROPERTIES.get(direction), neighborState.isOf(this) && neighborState.get(AXIS) == 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 @Override
public BlockState rotate(BlockState state, BlockRotation rotation) { protected BlockState rotate(BlockState state, BlockRotation rotation) {
return PillarBlock.changeRotation(state, rotation); return PillarBlock.changeRotation(state, rotation);
} }
} }

View file

@ -48,7 +48,7 @@ public class CloudSlabBlock extends WaterloggableCloudBlock {
} }
@Override @Override
public boolean hasSidedTransparency(BlockState state) { protected boolean hasSidedTransparency(BlockState state) {
return state.get(SlabBlock.TYPE) != SlabType.DOUBLE; return state.get(SlabBlock.TYPE) != SlabType.DOUBLE;
} }
@ -59,7 +59,7 @@ public class CloudSlabBlock extends WaterloggableCloudBlock {
} }
@Override @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)) { return switch (state.get(SlabBlock.TYPE)) {
case DOUBLE -> VoxelShapes.fullCube(); case DOUBLE -> VoxelShapes.fullCube();
case TOP -> TOP_SHAPE; case TOP -> TOP_SHAPE;
@ -84,7 +84,7 @@ public class CloudSlabBlock extends WaterloggableCloudBlock {
} }
@Override @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); SlabType slabType = state.get(SlabBlock.TYPE);
if (slabType == SlabType.DOUBLE || !context.getStack().isOf(asItem())) { if (slabType == SlabType.DOUBLE || !context.getStack().isOf(asItem())) {
return false; return false;

View file

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

View file

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

View file

@ -50,7 +50,7 @@ public class NaturalCloudBlock extends PoreousCloudBlock {
} }
@Override @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)) { if (stack.isIn(ItemTags.SHOVELS)) {
BooleanProperty property = CompactedCloudBlock.FACING_PROPERTIES.get(hit.getSide()); BooleanProperty property = CompactedCloudBlock.FACING_PROPERTIES.get(hit.getSide());
world.setBlockState(pos, compactedBlock.get().getDefaultState().with(property, false)); world.setBlockState(pos, compactedBlock.get().getDefaultState().with(property, false));

View file

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

View file

@ -46,7 +46,7 @@ public class PoreousCloudBlock extends CloudBlock implements Soakable {
} }
@Override @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())) { if (state.getBlock() instanceof Soakable soakable && world.hasRain(pos) && world.isAir(pos.up())) {
@Nullable @Nullable
BlockState soggyState = soakable.getStateWithMoisture(state, random.nextBetween(1, 5)); BlockState soggyState = soakable.getStateWithMoisture(state, random.nextBetween(1, 5));

View file

@ -49,7 +49,7 @@ public class ShapingBenchBlock extends CloudBlock {
} }
@Override @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) { if (world.isClient) {
return ActionResult.SUCCESS; return ActionResult.SUCCESS;
} }

View file

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

View file

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

View file

@ -65,9 +65,8 @@ public class WaterloggableCloudBlock extends PoreousCloudBlock implements Waterl
return super.getFluidState(state); return super.getFluidState(state);
} }
@Deprecated
@Override @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()) { if (state.get(WATERLOGGED).booleanValue()) {
world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); world.scheduleFluidTick(pos, Fluids.WATER, Fluids.WATER.getTickRate(world));
} }
@ -75,7 +74,7 @@ public class WaterloggableCloudBlock extends PoreousCloudBlock implements Waterl
} }
@Override @Override
public boolean canPathfindThrough(BlockState state, NavigationType type) { protected boolean canPathfindThrough(BlockState state, NavigationType type) {
return (type == NavigationType.WATER) == state.getFluidState().isIn(FluidTags.WATER); return (type == NavigationType.WATER) == state.getFluidState().isIn(FluidTags.WATER);
} }
} }

View file

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

View file

@ -39,7 +39,7 @@ public record ItemsJarContents (
} }
public ItemsJarContents(TileData tile, NbtCompound compound, WrapperLookup lookup) { 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 @Override
@ -197,7 +197,7 @@ public record ItemsJarContents (
@Override @Override
public NbtCompound toNBT(NbtCompound compound, WrapperLookup lookup) { 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; return compound;
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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