Updating to 1.21 (part 2)

This commit is contained in:
Sollace 2024-09-26 21:36:35 +01:00
parent 74d30d7c95
commit 259b0cddc4
No known key found for this signature in database
GPG key ID: E52FACE7B5C773DB
191 changed files with 1216 additions and 1139 deletions

View file

@ -12,7 +12,7 @@ jobs:
- name: Set up JDK - name: Set up JDK
uses: actions/setup-java@v1 uses: actions/setup-java@v1
with: with:
java-version: 17 java-version: 21
- name: Build Gradle - name: Build Gradle
uses: eskatos/gradle-command-action@v1 uses: eskatos/gradle-command-action@v1
with: with:

View file

@ -12,7 +12,7 @@ jobs:
- name: Set up JDK - name: Set up JDK
uses: actions/setup-java@v1 uses: actions/setup-java@v1
with: with:
java-version: 17 java-version: 21
- name: Build Gradle - name: Build Gradle
uses: eskatos/gradle-command-action@v1 uses: eskatos/gradle-command-action@v1
with: with:

View file

@ -16,7 +16,7 @@ jobs:
- name: Set up JDK - name: Set up JDK
uses: actions/setup-java@v1 uses: actions/setup-java@v1
with: with:
java-version: 17 java-version: 21
- name: Prepare Datagen - name: Prepare Datagen
uses: eskatos/gradle-command-action@v1 uses: eskatos/gradle-command-action@v1
with: with:

View file

@ -12,7 +12,7 @@ apply plugin: 'io.github.dexman545.outlet'
java { java {
toolchain { toolchain {
languageVersion = JavaLanguageVersion.of(17) languageVersion = JavaLanguageVersion.of(21)
} }
withSourcesJar() withSourcesJar()
} }

View file

@ -20,7 +20,7 @@ org.gradle.daemon=false
modrinth_project_id=9K7RJlvM modrinth_project_id=9K7RJlvM
# Dependencies # Dependencies
fabwork_version=1.3.1+1.21 fabwork_version=1.3.2-beta.1+1.21
modmenu_version=11.0.0-beta.1 modmenu_version=11.0.0-beta.1
minelp_version=4.12.0+1.21 minelp_version=4.12.0+1.21
kirin_version=1.19.0+1.21 kirin_version=1.19.0+1.21

View file

@ -24,7 +24,7 @@ public interface Debug {
AtomicReference<World> LAST_TESTED_WORLD = new AtomicReference<>(null); AtomicReference<World> LAST_TESTED_WORLD = new AtomicReference<>(null);
static void runTests(World world) { static void runTests(World world) {
if (!CHECK_GAME_VALUES || !world.getDimensionKey().getValue().equals(DimensionTypes.OVERWORLD_ID) || (LAST_TESTED_WORLD.getAndSet(world) == world)) { if (!CHECK_GAME_VALUES || !world.getDimensionEntry().matchesKey(DimensionTypes.OVERWORLD) || (LAST_TESTED_WORLD.getAndSet(world) == world)) {
return; return;
} }

View file

@ -202,7 +202,7 @@ public record Race (
Identifier id = Identifier.tryParse(s); Identifier id = Identifier.tryParse(s);
if (id != null) { if (id != null) {
if (id.getNamespace() == Identifier.DEFAULT_NAMESPACE) { if (id.getNamespace() == Identifier.DEFAULT_NAMESPACE) {
id = new Identifier(Unicopia.DEFAULT_NAMESPACE, id.getPath()); id = Unicopia.id(id.getPath());
} }
return REGISTRY.getOrEmpty(id).orElse(def); return REGISTRY.getOrEmpty(id).orElse(def);
} }
@ -231,7 +231,7 @@ public record Race (
Identifier id = context.getArgument(name, RegistryKey.class).getValue(); Identifier id = context.getArgument(name, RegistryKey.class).getValue();
final Identifier idf = id; final Identifier idf = id;
if (id.getNamespace() == Identifier.DEFAULT_NAMESPACE && !REGISTRY.containsId(id)) { if (id.getNamespace() == Identifier.DEFAULT_NAMESPACE && !REGISTRY.containsId(id)) {
id = new Identifier(REGISTRY_KEY.getValue().getNamespace(), id.getPath()); id = REGISTRY_KEY.getValue().withPath(id.getPath());
} }
return REGISTRY.getOrEmpty(id).orElseThrow(() -> UNKNOWN_RACE_EXCEPTION.create(idf)); return REGISTRY.getOrEmpty(id).orElseThrow(() -> UNKNOWN_RACE_EXCEPTION.create(idf));
} }

View file

@ -16,7 +16,7 @@ public interface UConventionalTags {
TagKey<Block> CORALS = block("corals"); TagKey<Block> CORALS = block("corals");
private static TagKey<Block> block(String name) { private static TagKey<Block> block(String name) {
return TagKey.of(RegistryKeys.BLOCK, new Identifier("c", name)); return TagKey.of(RegistryKeys.BLOCK, Identifier.of("c", name));
} }
} }
@ -65,7 +65,7 @@ public interface UConventionalTags {
TagKey<Item> TOOL_KNIVES = item("tools/knives"); TagKey<Item> TOOL_KNIVES = item("tools/knives");
private static TagKey<Item> item(String name) { private static TagKey<Item> item(String name) {
return TagKey.of(RegistryKeys.ITEM, new Identifier("c", name)); return TagKey.of(RegistryKeys.ITEM, Identifier.of("c", name));
} }
} }
} }

View file

@ -2,16 +2,17 @@ package com.minelittlepony.unicopia;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.registry.Registry; import net.minecraft.registry.Registry;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.world.event.GameEvent; import net.minecraft.world.event.GameEvent;
public interface UGameEvents { public interface UGameEvents {
GameEvent PIE_STOMP = register("pie_stomp", 5); RegistryEntry<GameEvent> PIE_STOMP = register("pie_stomp", 5);
static GameEvent register(String name, int range) { static RegistryEntry<GameEvent> register(String name, int range) {
Identifier id = Unicopia.id(name); Identifier id = Unicopia.id(name);
return Registry.register(Registries.GAME_EVENT, id, new GameEvent(range)); return Registry.registerReference(Registries.GAME_EVENT, id, new GameEvent(range));
} }
static void bootstrap() { static void bootstrap() {

View file

@ -56,7 +56,7 @@ public interface USounds {
SoundEvent ENTITY_HOT_AIR_BALLOON_BURNER_FIRE = ENTITY_GHAST_SHOOT; SoundEvent ENTITY_HOT_AIR_BALLOON_BURNER_FIRE = ENTITY_GHAST_SHOOT;
SoundEvent ENTITY_HOT_AIR_BALLOON_STEP = BLOCK_WOOL_STEP; SoundEvent ENTITY_HOT_AIR_BALLOON_STEP = BLOCK_WOOL_STEP;
SoundEvent ENTITY_HOT_AIR_BALLOON_BASKET_STEP = BLOCK_BAMBOO_STEP; SoundEvent ENTITY_HOT_AIR_BALLOON_BASKET_STEP = BLOCK_BAMBOO_STEP;
SoundEvent ENTITY_HOT_AIR_BALLOON_EQUIP_CANOPY = ITEM_ARMOR_EQUIP_LEATHER; RegistryEntry<SoundEvent> ENTITY_HOT_AIR_BALLOON_EQUIP_CANOPY = ITEM_ARMOR_EQUIP_LEATHER;
SoundEvent ENTITY_HOT_AIR_BALLOON_EQUIP_BURNER = ENTITY_IRON_GOLEM_DAMAGE; SoundEvent ENTITY_HOT_AIR_BALLOON_EQUIP_BURNER = ENTITY_IRON_GOLEM_DAMAGE;
SoundEvent ENTITY_SOMBRA_AMBIENT = register("entity.sombra.ambient"); SoundEvent ENTITY_SOMBRA_AMBIENT = register("entity.sombra.ambient");

View file

@ -137,7 +137,7 @@ public interface UTags {
TagKey<DimensionType> HAS_NO_ATMOSPHERE = dimension("has_no_atmosphere"); TagKey<DimensionType> HAS_NO_ATMOSPHERE = dimension("has_no_atmosphere");
private static TagKey<DimensionType> dimension(String name) { private static TagKey<DimensionType> dimension(String name) {
return TagKey.of(RegistryKeys.DIMENSION_TYPE, new Identifier("c", name)); return TagKey.of(RegistryKeys.DIMENSION_TYPE, Identifier.of("c", name));
} }
} }

View file

@ -57,7 +57,7 @@ public class Unicopia implements ModInitializer {
} }
public static Identifier id(String name) { public static Identifier id(String name) {
return new Identifier(DEFAULT_NAMESPACE, name); return Identifier.of(DEFAULT_NAMESPACE, name);
} }
@Override @Override

View file

@ -6,6 +6,8 @@ import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.ability.data.Hit; import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.Util; import net.minecraft.util.Util;
@ -106,7 +108,7 @@ public interface Ability<T extends Hit> {
/** /**
* Gets the serializer to use for reading data over the network. * Gets the serializer to use for reading data over the network.
*/ */
Hit.Serializer<T> getSerializer(); PacketCodec<? extends ByteBuf, T> getSerializer();
/** /**
* Called on the client to get any data required to activate the ability. * Called on the client to get any data required to activate the ability.

View file

@ -17,6 +17,7 @@ import com.minelittlepony.unicopia.util.NbtSerialisable;
import com.minelittlepony.unicopia.util.Tickable; import com.minelittlepony.unicopia.util.Tickable;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public class AbilityDispatcher implements Tickable, NbtSerialisable { public class AbilityDispatcher implements Tickable, NbtSerialisable {
@ -83,20 +84,20 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable {
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
if (compound.contains("stats")) { if (compound.contains("stats")) {
stats.clear(); stats.clear();
NbtCompound li = compound.getCompound("stats"); NbtCompound li = compound.getCompound("stats");
li.getKeys().forEach(key -> { li.getKeys().forEach(key -> {
getStat(AbilitySlot.valueOf(key)).fromNBT(li.getCompound(key)); getStat(AbilitySlot.valueOf(key)).fromNBT(li.getCompound(key), lookup);
}); });
} }
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
NbtCompound li = new NbtCompound(); NbtCompound li = new NbtCompound();
stats.forEach((key, value) -> li.put(key.name(), value.toNBT())); stats.forEach((key, value) -> li.put(key.name(), value.toNBT(lookup)));
compound.put("stats", li); compound.put("stats", li);
} }
@ -283,7 +284,7 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable {
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
compound.putInt("warmup", warmup); compound.putInt("warmup", warmup);
compound.putInt("cooldown", cooldown); compound.putInt("cooldown", cooldown);
compound.putInt("maxWarmup", maxWarmup); compound.putInt("maxWarmup", maxWarmup);
@ -295,13 +296,13 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable {
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
warmup = compound.getInt("warmup"); warmup = compound.getInt("warmup");
cooldown = compound.getInt("cooldown"); cooldown = compound.getInt("cooldown");
maxWarmup = compound.getInt("maxWarmup"); maxWarmup = compound.getInt("maxWarmup");
maxCooldown = compound.getInt("maxCooldown"); maxCooldown = compound.getInt("maxCooldown");
triggered = compound.getBoolean("triggered"); triggered = compound.getBoolean("triggered");
activeAbility = Abilities.REGISTRY.getOrEmpty(new Identifier(compound.getString("activeAbility"))); activeAbility = Abilities.REGISTRY.getOrEmpty(Identifier.of(compound.getString("activeAbility")));
} }
} }
} }

View file

@ -5,6 +5,8 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellTyp
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.particle.MagicParticleEffect; import com.minelittlepony.unicopia.particle.MagicParticleEffect;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.TypedActionResult; import net.minecraft.util.TypedActionResult;
@ -52,8 +54,8 @@ abstract class AbstractSpellCastingAbility implements Ability<Hit> {
} }
@Override @Override
public Hit.Serializer<Hit> getSerializer() { public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
return Hit.SERIALIZER; return Hit.CODEC;
} }
@Override @Override

View file

@ -6,6 +6,8 @@ import com.minelittlepony.unicopia.ability.data.Multi;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.TraceHelper; import com.minelittlepony.unicopia.util.TraceHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
/** /**
@ -43,8 +45,8 @@ public class BatPonyHangAbility implements Ability<Multi> {
} }
@Override @Override
public Multi.Serializer<Multi> getSerializer() { public PacketCodec<? extends ByteBuf, Multi> getSerializer() {
return Multi.SERIALIZER; return Multi.CODEC;
} }
@Override @Override

View file

@ -11,9 +11,11 @@ import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.TraceHelper; import com.minelittlepony.unicopia.util.TraceHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.world.World; import net.minecraft.world.World;
/** /**
@ -48,8 +50,8 @@ public class CarryAbility implements Ability<Hit> {
} }
@Override @Override
public Hit.Serializer<Hit> getSerializer() { public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
return Hit.SERIALIZER; return Hit.CODEC;
} }
@Override @Override

View file

@ -15,7 +15,11 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.item.FriendshipBraceletItem; import com.minelittlepony.unicopia.item.FriendshipBraceletItem;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -58,8 +62,8 @@ public class ChangeFormAbility implements Ability<Hit> {
} }
@Override @Override
public Hit.Serializer<Hit> getSerializer() { public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
return Hit.SERIALIZER; return Hit.CODEC;
} }
@Override @Override
@ -77,7 +81,7 @@ public class ChangeFormAbility implements Ability<Hit> {
player.subtractEnergyCost(5 * targets.size()); player.subtractEnergyCost(5 * targets.size());
TrinketsDelegate.EquippedStack amulet = UItems.PEARL_NECKLACE.getForEntity(player.asEntity()); TrinketsDelegate.EquippedStack amulet = UItems.PEARL_NECKLACE.getForEntity(player.asEntity());
if (!amulet.stack().isEmpty()) { if (!amulet.stack().isEmpty()) {
amulet.stack().damage(1, player.asEntity(), amulet.breakStatusSender()); amulet.stack().damage(1, (ServerWorld)player.asWorld(), (ServerPlayerEntity)player.asEntity(), amulet.breakStatusSender());
} }
boolean isTransforming = player.getSuppressedRace().isUnset(); boolean isTransforming = player.getSuppressedRace().isUnset();

View file

@ -15,6 +15,7 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.TraceHelper; import com.minelittlepony.unicopia.util.TraceHelper;
import com.minelittlepony.unicopia.util.VecHelper; import com.minelittlepony.unicopia.util.VecHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.mob.HostileEntity; import net.minecraft.entity.mob.HostileEntity;
@ -23,6 +24,7 @@ import net.minecraft.entity.passive.MerchantEntity;
import net.minecraft.entity.passive.PigEntity; import net.minecraft.entity.passive.PigEntity;
import net.minecraft.entity.passive.SheepEntity; import net.minecraft.entity.passive.SheepEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
/** /**
@ -54,8 +56,8 @@ public class ChangelingFeedAbility implements Ability<Hit> {
} }
@Override @Override
public Hit.Serializer<Hit> getSerializer() { public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
return Hit.SERIALIZER; return Hit.CODEC;
} }
@Override @Override

View file

@ -18,6 +18,7 @@ import com.minelittlepony.unicopia.server.world.ModificationType;
import com.minelittlepony.unicopia.util.TraceHelper; import com.minelittlepony.unicopia.util.TraceHelper;
import com.minelittlepony.unicopia.util.VecHelper; import com.minelittlepony.unicopia.util.VecHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
@ -26,6 +27,7 @@ import net.minecraft.block.FarmlandBlock;
import net.minecraft.item.BoneMealItem; import net.minecraft.item.BoneMealItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
@ -54,8 +56,8 @@ public class EarthPonyGrowAbility implements Ability<Pos> {
} }
@Override @Override
public Hit.Serializer<Pos> getSerializer() { public PacketCodec<? extends ByteBuf, Pos> getSerializer() {
return Pos.SERIALIZER; return Pos.CODEC;
} }
@Override @Override

View file

@ -6,7 +6,6 @@ import java.util.stream.Stream;
import org.jetbrains.annotations.Nullable; import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.ability.data.Pos; import com.minelittlepony.unicopia.ability.data.Pos;
import com.minelittlepony.unicopia.ability.data.tree.TreeType; import com.minelittlepony.unicopia.ability.data.tree.TreeType;
import com.minelittlepony.unicopia.client.minelittlepony.MineLPDelegate; import com.minelittlepony.unicopia.client.minelittlepony.MineLPDelegate;
@ -20,6 +19,7 @@ import com.minelittlepony.unicopia.server.world.BlockDestructionManager;
import com.minelittlepony.unicopia.server.world.ModificationType; import com.minelittlepony.unicopia.server.world.ModificationType;
import com.minelittlepony.unicopia.util.*; import com.minelittlepony.unicopia.util.*;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.BeehiveBlock; import net.minecraft.block.BeehiveBlock;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
@ -30,6 +30,7 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.passive.BeeEntity; import net.minecraft.entity.passive.BeeEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -145,8 +146,8 @@ public class EarthPonyKickAbility implements Ability<Pos> {
} }
@Override @Override
public Hit.Serializer<Pos> getSerializer() { public PacketCodec<? extends ByteBuf, Pos> getSerializer() {
return Pos.SERIALIZER; return Pos.CODEC;
} }
@Override @Override

View file

@ -23,6 +23,7 @@ import com.minelittlepony.unicopia.server.world.ModificationType;
import com.minelittlepony.unicopia.util.PosHelper; import com.minelittlepony.unicopia.util.PosHelper;
import com.minelittlepony.unicopia.util.VecHelper; import com.minelittlepony.unicopia.util.VecHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.EnchantmentHelper;
@ -31,6 +32,7 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.attribute.EntityAttributes; import net.minecraft.entity.attribute.EntityAttributes;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.particle.BlockStateParticleEffect; import net.minecraft.particle.BlockStateParticleEffect;
import net.minecraft.registry.tag.BlockTags; import net.minecraft.registry.tag.BlockTags;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
@ -69,7 +71,7 @@ public class EarthPonyStompAbility implements Ability<Hit> {
public Identifier getIcon(Pony player) { public Identifier getIcon(Pony player) {
Identifier id = Abilities.REGISTRY.getId(this); Identifier id = Abilities.REGISTRY.getId(this);
Race race = player.getObservedSpecies(); Race race = player.getObservedSpecies();
return new Identifier(id.getNamespace(), "textures/gui/ability/" + id.getPath() return id.withPath(p -> "textures/gui/ability/" + p
+ "_" + (race.isHuman() ? Race.EARTH : race).getId().getPath() + "_" + (race.isHuman() ? Race.EARTH : race).getId().getPath()
+ ".png"); + ".png");
} }
@ -94,8 +96,8 @@ public class EarthPonyStompAbility implements Ability<Hit> {
} }
@Override @Override
public Hit.Serializer<Hit> getSerializer() { public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
return Hit.SERIALIZER; return Hit.CODEC;
} }
private void thrustDownwards(Pony player) { private void thrustDownwards(Pony player) {

View file

@ -7,6 +7,9 @@ import org.jetbrains.annotations.Nullable;
import com.minelittlepony.unicopia.ability.data.Hit; import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.PacketCodec;
/** /**
* Dashing ability for flying creatures. * Dashing ability for flying creatures.
*/ */
@ -29,8 +32,8 @@ public class FlyingDashAbility implements Ability<Hit> {
} }
@Override @Override
public Hit.Serializer<Hit> getSerializer() { public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
return Hit.SERIALIZER; return Hit.CODEC;
} }
@Override @Override

View file

@ -34,7 +34,7 @@ public class HugAbility extends CarryAbility {
creeper.startRiding(player, true); creeper.startRiding(player, true);
Living.getOrEmpty(creeper).ifPresent(living -> living.setCarrier(player)); Living.getOrEmpty(creeper).ifPresent(living -> living.setCarrier(player));
} else if (rider != null) { } else if (rider != null) {
rider.teleport(player.getX(), player.getY() + 0.5, player.getZ()); rider.teleport(player.getX(), player.getY() + 0.5, player.getZ(), false);
rider.setYaw(player.getYaw() + 180); rider.setYaw(player.getYaw() + 180);
if (rider instanceof FriendlyCreeperEntity) { if (rider instanceof FriendlyCreeperEntity) {

View file

@ -11,6 +11,8 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.block.state.StateMaps; import com.minelittlepony.unicopia.block.state.StateMaps;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.text.Text; import net.minecraft.text.Text;
@ -36,8 +38,8 @@ public class KirinRageAbility implements Ability<Hit> {
} }
@Override @Override
public Hit.Serializer<Hit> getSerializer() { public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
return Hit.SERIALIZER; return Hit.CODEC;
} }
@Override @Override

View file

@ -11,9 +11,11 @@ import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation.Recipient
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.ExplosionUtil; import com.minelittlepony.unicopia.util.ExplosionUtil;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageTypes; import net.minecraft.entity.damage.DamageTypes;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
@ -42,8 +44,8 @@ public class NirikBlastAbility implements Ability<Hit> {
} }
@Override @Override
public Hit.Serializer<Hit> getSerializer() { public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
return Hit.SERIALIZER; return Hit.CODEC;
} }
@Override @Override

View file

@ -5,18 +5,19 @@ import java.util.Optional;
import com.minelittlepony.unicopia.EquinePredicates; import com.minelittlepony.unicopia.EquinePredicates;
import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.ability.data.Hit; import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.ability.data.Numeric;
import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.damage.UDamageTypes; import com.minelittlepony.unicopia.entity.damage.UDamageTypes;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.TraceHelper; import com.minelittlepony.unicopia.util.TraceHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.registry.tag.BlockTags; import net.minecraft.registry.tag.BlockTags;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
@ -59,8 +60,8 @@ public class PeckAbility implements Ability<Hit> {
} }
@Override @Override
public Numeric.Serializer<Hit> getSerializer() { public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
return Hit.SERIALIZER; return Hit.CODEC;
} }
protected LivingEntity findTarget(PlayerEntity player, World w) { protected LivingEntity findTarget(PlayerEntity player, World w) {

View file

@ -9,7 +9,9 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.particle.MagicParticleEffect; import com.minelittlepony.unicopia.particle.MagicParticleEffect;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket; import net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text; import net.minecraft.text.Text;
@ -39,8 +41,8 @@ public class PegasusCaptureStormAbility implements Ability<Hit> {
} }
@Override @Override
public Hit.Serializer<Hit> getSerializer() { public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
return Hit.SERIALIZER; return Hit.CODEC;
} }
@Override @Override

View file

@ -10,6 +10,9 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.particle.MagicParticleEffect; import com.minelittlepony.unicopia.particle.MagicParticleEffect;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.PacketCodec;
/** /**
* Pegasus ability to perform rainbooms * Pegasus ability to perform rainbooms
*/ */
@ -32,8 +35,8 @@ public class PegasusRainboomAbility implements Ability<Hit> {
} }
@Override @Override
public Hit.Serializer<Hit> getSerializer() { public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
return Hit.SERIALIZER; return Hit.CODEC;
} }
@Override @Override

View file

@ -16,7 +16,9 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.RegistryUtils; import com.minelittlepony.unicopia.util.RegistryUtils;
import com.minelittlepony.unicopia.util.VecHelper; import com.minelittlepony.unicopia.util.VecHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -58,8 +60,8 @@ public class ScreechAbility implements Ability<Numeric> {
} }
@Override @Override
public Numeric.Serializer<Numeric> getSerializer() { public PacketCodec<? extends ByteBuf, Numeric> getSerializer() {
return Numeric.SERIALIZER; return Numeric.CODEC;
} }
@Override @Override

View file

@ -13,11 +13,13 @@ import com.minelittlepony.unicopia.entity.player.Pony;
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 io.netty.buffer.ByteBuf;
import net.minecraft.block.ChestBlock; import net.minecraft.block.ChestBlock;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityGroup;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.mob.HostileEntity; import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.registry.tag.FluidTags; import net.minecraft.registry.tag.FluidTags;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
@ -44,8 +46,8 @@ public class SeaponySonarPulseAbility implements Ability<Hit> {
} }
@Override @Override
public Hit.Serializer<Hit> getSerializer() { public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
return Hit.SERIALIZER; return Hit.CODEC;
} }
@Override @Override
@ -58,7 +60,7 @@ public class SeaponySonarPulseAbility implements Ability<Hit> {
player.setAnimation(Animation.ARMS_UP, Animation.Recipient.ANYONE); player.setAnimation(Animation.ARMS_UP, Animation.Recipient.ANYONE);
for (Entity target : player.findAllEntitiesInRange(64, e -> { for (Entity target : player.findAllEntitiesInRange(64, e -> {
return (e instanceof LivingEntity && (e instanceof HostileEntity || ((LivingEntity)e).getGroup() == EntityGroup.AQUATIC)) && e.isSubmergedInWater(); return (e instanceof LivingEntity && (e instanceof HostileEntity || isWaterCreature(((LivingEntity)e).getType().getSpawnGroup()))) && e.isSubmergedInWater();
}).sorted(Comparator.comparing(e -> e.distanceTo(player.asEntity()))).toList()) { }).sorted(Comparator.comparing(e -> e.distanceTo(player.asEntity()))).toList()) {
Vec3d offset = target.getPos().subtract(player.getOriginVector()); Vec3d offset = target.getPos().subtract(player.getOriginVector());
float distance = target.distanceTo(player.asEntity()); float distance = target.distanceTo(player.asEntity());
@ -105,4 +107,12 @@ public class SeaponySonarPulseAbility implements Ability<Hit> {
@Override @Override
public void coolDown(Pony player, AbilitySlot slot) { public void coolDown(Pony player, AbilitySlot slot) {
} }
private static boolean isWaterCreature(SpawnGroup group) {
return switch (group) {
case AXOLOTLS, UNDERGROUND_WATER_CREATURE, WATER_CREATURE, WATER_AMBIENT -> true;
default -> false;
};
}
} }

View file

@ -3,13 +3,15 @@ package com.minelittlepony.unicopia.ability;
import java.util.Optional; import java.util.Optional;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.ability.data.Hit.Serializer;
import com.minelittlepony.unicopia.ability.data.Rot; import com.minelittlepony.unicopia.ability.data.Rot;
import com.minelittlepony.unicopia.ability.magic.spell.CastingMethod; import com.minelittlepony.unicopia.ability.magic.spell.CastingMethod;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.server.world.UGameRules; import com.minelittlepony.unicopia.server.world.UGameRules;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.PacketCodec;
public class TimeChangeAbility implements Ability<Rot> { public class TimeChangeAbility implements Ability<Rot> {
@Override @Override
@ -33,8 +35,8 @@ public class TimeChangeAbility implements Ability<Rot> {
} }
@Override @Override
public Serializer<Rot> getSerializer() { public PacketCodec<? extends ByteBuf, Rot> getSerializer() {
return Rot.SERIALIZER; return Rot.CODEC;
} }
@Override @Override

View file

@ -10,6 +10,8 @@ import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
import com.minelittlepony.unicopia.entity.Living; import com.minelittlepony.unicopia.entity.Living;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -32,15 +34,14 @@ public class ToggleFlightAbility implements Ability<Hit> {
} }
@Override @Override
public Hit.Serializer<Hit> getSerializer() { public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
return Hit.SERIALIZER; return Hit.CODEC;
} }
@Override @Override
public Identifier getIcon(Pony player) { public Identifier getIcon(Pony player) {
Identifier id = Abilities.REGISTRY.getId(this);
Race race = player.getObservedSpecies(); Race race = player.getObservedSpecies();
return new Identifier(id.getNamespace(), "textures/gui/ability/" + id.getPath() return Abilities.REGISTRY.getId(this).withPath(p -> "textures/gui/ability/" + p
+ (player.getPhysics().isFlying() ? "_land" : "_takeoff") + (player.getPhysics().isFlying() ? "_land" : "_takeoff")
+ "_" + (race.isHuman() ? Race.EARTH : race).getId().getPath() + "_" + (race.isHuman() ? Race.EARTH : race).getId().getPath()
+ ".png"); + ".png");

View file

@ -14,6 +14,8 @@ import com.minelittlepony.unicopia.particle.MagicParticleEffect;
import com.minelittlepony.unicopia.util.TraceHelper; import com.minelittlepony.unicopia.util.TraceHelper;
import com.minelittlepony.unicopia.util.VecHelper; import com.minelittlepony.unicopia.util.VecHelper;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -39,13 +41,12 @@ public class UnicornDispellAbility implements Ability<Pos> {
@Override @Override
public Identifier getIcon(Pony player) { public Identifier getIcon(Pony player) {
Identifier id = Abilities.REGISTRY.getId(this); return Abilities.REGISTRY.getId(this).withPath(p -> "textures/gui/ability/" + p + (player.getSpecies() == Race.CHANGELING ? "_changeling" : "") + ".png");
return new Identifier(id.getNamespace(), "textures/gui/ability/" + id.getPath() + (player.getSpecies() == Race.CHANGELING ? "_changeling" : "") + ".png");
} }
@Override @Override
public Pos.Serializer<Pos> getSerializer() { public PacketCodec<? extends ByteBuf, Pos> getSerializer() {
return Pos.SERIALIZER; return Pos.CODEC;
} }
@Override @Override

View file

@ -3,7 +3,6 @@ package com.minelittlepony.unicopia.ability;
import java.util.Optional; import java.util.Optional;
import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.ability.data.Hit;
import com.minelittlepony.unicopia.ability.data.Pos; import com.minelittlepony.unicopia.ability.data.Pos;
import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.Caster;
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType; import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
@ -14,6 +13,7 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.particle.MagicParticleEffect; import com.minelittlepony.unicopia.particle.MagicParticleEffect;
import com.minelittlepony.unicopia.util.Trace; import com.minelittlepony.unicopia.util.Trace;
import io.netty.buffer.ByteBuf;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.LeavesBlock; import net.minecraft.block.LeavesBlock;
@ -21,6 +21,7 @@ import net.minecraft.block.PowderSnowBlock;
import net.minecraft.block.ShapeContext; import net.minecraft.block.ShapeContext;
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.network.codec.PacketCodec;
import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.text.Text; import net.minecraft.text.Text;
@ -131,8 +132,8 @@ public class UnicornTeleportAbility implements Ability<Pos> {
} }
@Override @Override
public Hit.Serializer<Pos> getSerializer() { public PacketCodec<? extends ByteBuf, Pos> getSerializer() {
return Pos.SERIALIZER; return Pos.CODEC;
} }
@Override @Override
@ -177,10 +178,11 @@ public class UnicornTeleportAbility implements Ability<Pos> {
yPos, yPos,
destination.z() + offset.getZ() destination.z() + offset.getZ()
); );
participant.teleport(dest.x, dest.y, dest.z); // TODO: teleport -> requestTeleport
participant.requestTeleport(dest.x, dest.y, dest.z);
if (participant.getWorld().getBlockCollisions(participant, participant.getBoundingBox()).iterator().hasNext()) { if (participant.getWorld().getBlockCollisions(participant, participant.getBoundingBox()).iterator().hasNext()) {
dest = destination.vec(); dest = destination.vec();
participant.teleport(dest.x, participant.getY(), dest.z); participant.requestTeleport(dest.x, participant.getY(), dest.z);
} }
teleporter.subtractEnergyCost(distance); teleporter.subtractEnergyCost(distance);

View file

@ -2,17 +2,13 @@ package com.minelittlepony.unicopia.ability.data;
import java.util.Optional; import java.util.Optional;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.codec.PacketCodec;
public interface Hit { public interface Hit {
Optional<Hit> INSTANCE = Optional.of(new Hit() {}); Optional<Hit> INSTANCE = Optional.of(new Hit() {});
Serializer<Hit> SERIALIZER = new Serializer<>(buf -> INSTANCE.get(), (buf, t) -> {}); PacketCodec<PacketByteBuf, Hit> CODEC = PacketCodec.unit(INSTANCE.get());
static Optional<Hit> of(boolean value) { static Optional<Hit> of(boolean value) {
return value ? INSTANCE : Optional.empty(); return value ? INSTANCE : Optional.empty();
} }
public record Serializer<T extends Hit> (
PacketByteBuf.PacketReader<T> read,
PacketByteBuf.PacketWriter<T> write) {
}
} }

View file

@ -1,14 +1,16 @@
package com.minelittlepony.unicopia.ability.data; package com.minelittlepony.unicopia.ability.data;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.util.math.Vec3i; import net.minecraft.util.math.Vec3i;
public record Multi (Pos pos, int hitType) implements Hit { public record Multi (Pos pos, int hitType) implements Hit {
public static final Serializer<Multi> SERIALIZER = new Serializer<>( public static final PacketCodec<PacketByteBuf, Multi> CODEC = PacketCodec.tuple(
buf -> new Multi(Pos.SERIALIZER.read().apply(buf), buf.readInt()), Pos.CODEC, Multi::pos,
(buf, t) -> { PacketCodecs.INTEGER, Multi::hitType,
Pos.SERIALIZER.write().accept(buf, t.pos()); Multi::new
buf.writeInt(t.hitType()); );
});
public Multi(Vec3i pos, int hit) { public Multi(Vec3i pos, int hit) {
this(new Pos(pos), hit); this(new Pos(pos), hit);

View file

@ -2,10 +2,12 @@ package com.minelittlepony.unicopia.ability.data;
import java.util.Optional; import java.util.Optional;
import io.netty.buffer.ByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
public record Numeric (int type) implements Hit { public record Numeric (int type) implements Hit {
public static final Serializer<Numeric> SERIALIZER = new Serializer<>( public static final PacketCodec<ByteBuf, Numeric> CODEC = PacketCodecs.INTEGER.xmap(Numeric::new, Numeric::type);
buf -> new Numeric(buf.readInt()),
(buf, t) -> buf.writeInt(t.type()));
public static Optional<Numeric> of(int type) { public static Optional<Numeric> of(int type) {
return Optional.of(new Numeric(type)); return Optional.of(new Numeric(type));

View file

@ -2,16 +2,18 @@ package com.minelittlepony.unicopia.ability.data;
import com.minelittlepony.unicopia.ability.magic.Caster; import com.minelittlepony.unicopia.ability.magic.Caster;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.util.math.*; import net.minecraft.util.math.*;
public record Pos (int x, int y, int z) implements Hit { public record Pos (int x, int y, int z) implements Hit {
public static final Serializer<Pos> SERIALIZER = new Serializer<>( public static final PacketCodec<PacketByteBuf, Pos> CODEC = PacketCodec.tuple(
buf -> new Pos(buf.readInt(), buf.readInt(), buf.readInt()), PacketCodecs.INTEGER, Pos::x,
(buf, t) -> { PacketCodecs.INTEGER, Pos::y,
buf.writeInt(t.x()); PacketCodecs.INTEGER, Pos::z,
buf.writeInt(t.y()); Pos::new
buf.writeInt(t.z()); );
});
public Pos(Vec3i pos) { public Pos(Vec3i pos) {
this(pos.getX(), pos.getY(), pos.getZ()); this(pos.getX(), pos.getY(), pos.getZ());

View file

@ -2,15 +2,17 @@ package com.minelittlepony.unicopia.ability.data;
import com.minelittlepony.unicopia.EntityConvertable; import com.minelittlepony.unicopia.EntityConvertable;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
public record Rot (float pitch, float yaw) implements Hit { public record Rot (float pitch, float yaw) implements Hit {
public static final Serializer<Rot> SERIALIZER = new Serializer<>( public static final PacketCodec<PacketByteBuf, Rot> CODEC = PacketCodec.tuple(
buf -> new Rot(buf.readFloat(), buf.readFloat()), PacketCodecs.FLOAT, Rot::pitch,
(buf, t) -> { PacketCodecs.FLOAT, Rot::yaw,
buf.writeFloat(t.pitch()); Rot::new
buf.writeFloat(t.yaw()); );
});
public Rot applyTo(EntityConvertable<?> target) { public Rot applyTo(EntityConvertable<?> target) {
Vec3d pos = target.getOriginVector(); Vec3d pos = target.getOriginVector();

View file

@ -14,12 +14,14 @@ import com.minelittlepony.unicopia.network.track.MsgTrackedValues;
import com.minelittlepony.unicopia.network.track.ObjectTracker; import com.minelittlepony.unicopia.network.track.ObjectTracker;
import com.minelittlepony.unicopia.network.track.Trackable; import com.minelittlepony.unicopia.network.track.Trackable;
import com.minelittlepony.unicopia.network.track.TrackableObject; import com.minelittlepony.unicopia.network.track.TrackableObject;
import com.minelittlepony.unicopia.network.track.MsgTrackedValues.TrackerEntries;
import com.minelittlepony.unicopia.util.NbtSerialisable; import com.minelittlepony.unicopia.util.NbtSerialisable;
import com.minelittlepony.unicopia.util.serialization.PacketCodec;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
/** /**
* Container for multiple spells * Container for multiple spells
@ -68,12 +70,12 @@ class MultiSpellSlot implements SpellSlots, NbtSerialisable {
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
compound.put("spells", NbtSerialisable.writeMap(tracker.entries(), UUID::toString, entry -> entry.spell.toNBT())); compound.put("spells", NbtSerialisable.writeMap(tracker.entries(), UUID::toString, entry -> entry.spell.toNBT(lookup)));
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
tracker.load(NbtSerialisable.readMap(compound.getCompound("spells"), key -> { tracker.load(NbtSerialisable.readMap(compound.getCompound("spells"), key -> {
try { try {
return UUID.fromString(key); return UUID.fromString(key);
@ -82,7 +84,7 @@ class MultiSpellSlot implements SpellSlots, NbtSerialisable {
}, (key, nbt) -> { }, (key, nbt) -> {
try { try {
Entry<Spell> entry = new Entry<>(owner); Entry<Spell> entry = new Entry<>(owner);
entry.spell.fromNBT((NbtCompound)nbt); entry.spell.fromNBT((NbtCompound)nbt, lookup);
return entry; return entry;
} catch (Throwable t) { } catch (Throwable t) {
Unicopia.LOGGER.warn("Exception loading tracked object: {}", t.getMessage()); Unicopia.LOGGER.warn("Exception loading tracked object: {}", t.getMessage());
@ -135,34 +137,34 @@ class MultiSpellSlot implements SpellSlots, NbtSerialisable {
} }
@Override @Override
public void readTrackedNbt(NbtCompound nbt) { public void readTrackedNbt(NbtCompound nbt, WrapperLookup lookup) {
spell.fromNBT(nbt); spell.fromNBT(nbt, lookup);
} }
@Override @Override
public NbtCompound writeTrackedNbt() { public NbtCompound writeTrackedNbt(WrapperLookup lookup) {
return spell.toNBT(); return spell.toNBT(lookup);
} }
@Override @Override
public void read(PacketByteBuf buffer) { public void read(PacketByteBuf buffer, WrapperLookup lookup) {
byte contentType = buffer.readByte(); byte contentType = buffer.readByte();
if (contentType == 1) { if (contentType == 1) {
readTrackedNbt(PacketCodec.COMPRESSED_NBT.read(buffer)); readTrackedNbt(PacketCodecs.NBT_COMPOUND.decode(buffer), lookup);
} else { } else {
T spell = this.spell.get(); T spell = this.spell.get();
if (spell != null) { if (spell != null) {
spell.getDataTracker().load(new MsgTrackedValues.TrackerEntries(buffer)); spell.getDataTracker().load(MsgTrackedValues.TrackerEntries.PACKET_CODEC.decode(buffer));
} }
} }
} }
@Override @Override
public Optional<PacketByteBuf> write(Status status) { public Optional<PacketByteBuf> write(Status status, WrapperLookup lookup) {
if (status != Status.DEFAULT) { if (status != Status.DEFAULT) {
PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer()); PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer());
buffer.writeByte(1); buffer.writeByte(1);
PacketCodec.COMPRESSED_NBT.write(buffer, spell.toNBT()); PacketCodecs.NBT_COMPOUND.encode(buffer, spell.toNBT(lookup));
return Optional.of(buffer); return Optional.of(buffer);
} }
@Nullable T spell = this.spell.get(); @Nullable T spell = this.spell.get();
@ -172,7 +174,7 @@ class MultiSpellSlot implements SpellSlots, NbtSerialisable {
return spell.getDataTracker().getDirtyPairs().map(entries -> { return spell.getDataTracker().getDirtyPairs().map(entries -> {
PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer()); PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer());
buffer.writeByte(0); buffer.writeByte(0);
entries.write(buffer); TrackerEntries.PACKET_CODEC.encode(buffer, entries);
return buffer; return buffer;
}); });
} }

View file

@ -9,6 +9,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.Spell;
import com.minelittlepony.unicopia.network.track.Trackable; import com.minelittlepony.unicopia.network.track.Trackable;
import com.minelittlepony.unicopia.util.NbtSerialisable; import com.minelittlepony.unicopia.util.NbtSerialisable;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
/** /**
* Container for a single spell * Container for a single spell
@ -57,13 +58,13 @@ class SingleSpellSlot implements SpellSlots, NbtSerialisable {
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
compound.put("effect", entry.spell.toNBT()); compound.put("effect", entry.spell.toNBT(lookup));
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
entry.spell.fromNBT(compound.getCompound("effect")); entry.spell.fromNBT(compound.getCompound("effect"), lookup);
} }
@Override @Override

View file

@ -11,6 +11,7 @@ import com.minelittlepony.unicopia.network.track.DataTracker;
import com.minelittlepony.unicopia.server.world.Ether; import com.minelittlepony.unicopia.server.world.Ether;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
public abstract class AbstractDelegatingSpell implements Spell { public abstract class AbstractDelegatingSpell implements Spell {
private UUID uuid = UUID.randomUUID(); private UUID uuid = UUID.randomUUID();
@ -109,17 +110,17 @@ public abstract class AbstractDelegatingSpell implements Spell {
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
compound.putUuid("uuid", uuid); compound.putUuid("uuid", uuid);
compound.put("spell", delegate.toNBT()); compound.put("spell", delegate.toNBT(lookup));
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
if (compound.contains("uuid")) { if (compound.contains("uuid")) {
uuid = compound.getUuid("uuid"); uuid = compound.getUuid("uuid");
} }
delegate.fromNBT(compound.getCompound("spell")); delegate.fromNBT(compound.getCompound("spell"), lookup);
} }
@Override @Override

View file

@ -14,6 +14,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
/** /**
* Base implementation for a spell that changes the player's appearance. * Base implementation for a spell that changes the player's appearance.
@ -53,14 +54,14 @@ public abstract class AbstractDisguiseSpell extends AbstractSpell implements Dis
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
disguise.toNBT(compound); disguise.toNBT(compound);
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
disguise.fromNBT(compound); disguise.fromNBT(compound);
} }

View file

@ -23,6 +23,7 @@ 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.nbt.NbtElement;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
public class ChangelingFeedingSpell extends AbstractSpell { public class ChangelingFeedingSpell extends AbstractSpell {
@ -141,22 +142,22 @@ public class ChangelingFeedingSpell extends AbstractSpell {
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
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)); compound.put("targets", EntityReference.<LivingEntity>getSerializer().writeAll(targets, lookup));
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
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 = compound.contains("targets", NbtElement.LIST_TYPE)
? EntityReference.<LivingEntity>getSerializer().readAll(compound.getList("targets", NbtElement.COMPOUND_TYPE)).toList() ? EntityReference.<LivingEntity>getSerializer().readAll(compound.getList("targets", NbtElement.COMPOUND_TYPE), lookup).toList()
: List.of(); : List.of();
} }
} }

View file

@ -15,6 +15,7 @@ import com.minelittlepony.unicopia.particle.MagicParticleEffect;
import com.minelittlepony.unicopia.particle.UParticles; import com.minelittlepony.unicopia.particle.UParticles;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
/** /**
* Shapeshifts the player. * Shapeshifts the player.
@ -95,15 +96,15 @@ public class DispersableDisguiseSpell extends AbstractDisguiseSpell implements I
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
compound.putInt("suppressionCounter", suppressionCounter); compound.putInt("suppressionCounter", suppressionCounter);
compound.putBoolean("forced", forced); compound.putBoolean("forced", forced);
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
suppressionCounter = compound.getInt("suppressionCounter"); suppressionCounter = compound.getInt("suppressionCounter");
forced = compound.getBoolean("forced"); forced = compound.getBoolean("forced");
if (suppressionCounter > 0) { if (suppressionCounter > 0) {

View file

@ -8,6 +8,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
import com.minelittlepony.unicopia.network.track.DataTracker; import com.minelittlepony.unicopia.network.track.DataTracker;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.Util; import net.minecraft.util.Util;
public final class EmptySpell implements Spell { public final class EmptySpell implements Spell {
@ -16,10 +17,10 @@ public final class EmptySpell implements Spell {
private EmptySpell() {} private EmptySpell() {}
@Override @Override
public void toNBT(NbtCompound compound) { } public void toNBT(NbtCompound compound, WrapperLookup lookup) { }
@Override @Override
public void fromNBT(NbtCompound compound) { } public void fromNBT(NbtCompound compound, WrapperLookup lookup) { }
@Override @Override
public CustomisedSpellType<?> getTypeAndTraits() { public CustomisedSpellType<?> getTypeAndTraits() {

View file

@ -18,6 +18,7 @@ import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtElement;
import net.minecraft.registry.RegistryKey; import net.minecraft.registry.RegistryKey;
import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -120,9 +121,9 @@ public class PlacementControlSpell extends AbstractSpell implements OrientedSpel
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
compound.put("spell", Spell.writeNbt(delegate)); compound.put("spell", Spell.writeNbt(delegate, lookup));
position.get().ifPresent(pos -> compound.put("position", NbtSerialisable.writeVector(pos))); position.get().ifPresent(pos -> compound.put("position", NbtSerialisable.writeVector(pos)));
orientation.get().ifPresent(o -> compound.put("orientation", NbtSerialisable.writeVector(o))); orientation.get().ifPresent(o -> compound.put("orientation", NbtSerialisable.writeVector(o)));
dimension.get().ifPresent(d -> compound.putString("dimension", d.getValue().toString())); dimension.get().ifPresent(d -> compound.putString("dimension", d.getValue().toString()));
@ -132,9 +133,9 @@ public class PlacementControlSpell extends AbstractSpell implements OrientedSpel
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
delegate = Spell.readNbt(compound.getCompound("spell")); delegate = Spell.readNbt(compound.getCompound("spell"), lookup);
placedEntityId.set(compound.containsUuid("placedEntityId") ? compound.getUuid("placedEntityId") : null); placedEntityId.set(compound.containsUuid("placedEntityId") ? compound.getUuid("placedEntityId") : null);
position.set(compound.contains("position") ? Optional.of(NbtSerialisable.readVector(compound.getList("position", NbtElement.DOUBLE_TYPE))) : Optional.empty()); position.set(compound.contains("position") ? Optional.of(NbtSerialisable.readVector(compound.getList("position", NbtElement.DOUBLE_TYPE))) : Optional.empty());
orientation.set(compound.contains("orientation") ? Optional.of(NbtSerialisable.readVector(compound.getList("orientation", NbtElement.DOUBLE_TYPE))) : Optional.empty()); orientation.set(compound.contains("orientation") ? Optional.of(NbtSerialisable.readVector(compound.getList("orientation", NbtElement.DOUBLE_TYPE))) : Optional.empty());

View file

@ -15,6 +15,7 @@ import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageTypes; import net.minecraft.entity.damage.DamageTypes;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
@ -130,14 +131,14 @@ public class RageAbilitySpell extends AbstractSpell {
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
compound.putInt("age", age); compound.putInt("age", age);
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
age = compound.getInt("age"); age = compound.getInt("age");
} }
} }

View file

@ -19,6 +19,7 @@ import com.minelittlepony.unicopia.util.shape.Sphere;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
/** /**
@ -85,14 +86,14 @@ public class RainboomAbilitySpell extends AbstractSpell {
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
compound.putInt("age", age); compound.putInt("age", age);
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
age = compound.getInt("age"); age = compound.getInt("age");
boundParticle = null; boundParticle = null;
} }

View file

@ -18,13 +18,15 @@ import com.minelittlepony.unicopia.server.world.Ether;
import com.minelittlepony.unicopia.util.NbtSerialisable; import com.minelittlepony.unicopia.util.NbtSerialisable;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.Util; 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 {
Serializer<Spell> SERIALIZER = Serializer.of(Spell::readNbt, Spell::writeNbt); @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.
@ -133,7 +135,7 @@ public interface Spell extends NbtSerialisable, Affine {
} }
@Nullable @Nullable
static <T extends Spell> T readNbt(@Nullable NbtCompound compound) { static <T extends Spell> T readNbt(@Nullable NbtCompound compound, WrapperLookup lookup) {
try { try {
if (compound != null) { if (compound != null) {
return CustomisedSpellType.<T>fromNBT(compound).create(compound); return CustomisedSpellType.<T>fromNBT(compound).create(compound);
@ -149,16 +151,16 @@ public interface Spell extends NbtSerialisable, Affine {
return compound == null || !compound.containsUuid("uuid") ? Util.NIL_UUID : compound.getUuid("uuid"); return compound == null || !compound.containsUuid("uuid") ? Util.NIL_UUID : compound.getUuid("uuid");
} }
static NbtCompound writeNbt(@Nullable Spell effect) { static NbtCompound writeNbt(@Nullable Spell effect, WrapperLookup lookup) {
if (effect == null) { if (effect == null) {
return new NbtCompound(); return new NbtCompound();
} }
NbtCompound compound = effect.toNBT(); NbtCompound compound = effect.toNBT(lookup);
effect.getTypeAndTraits().toNbt(compound); effect.getTypeAndTraits().toNbt(compound);
return compound; return compound;
} }
static <T extends Spell> Spell copy(T spell) { static <T extends Spell> Spell copy(T spell, WrapperLookup lookup) {
return readNbt(writeNbt(spell)); return readNbt(writeNbt(spell, lookup), lookup);
} }
} }

View file

@ -11,6 +11,7 @@ import com.minelittlepony.unicopia.ability.magic.SpellPredicate;
import com.minelittlepony.unicopia.util.NbtSerialisable; import com.minelittlepony.unicopia.util.NbtSerialisable;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
public final class SpellReference<T extends Spell> implements NbtSerialisable { public final class SpellReference<T extends Spell> implements NbtSerialisable {
@Nullable @Nullable
@ -50,19 +51,19 @@ public final class SpellReference<T extends Spell> implements NbtSerialisable {
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
if (spell != null && !spell.isDead()) { if (spell != null && !spell.isDead()) {
spell.toNBT(compound); spell.toNBT(compound, lookup);
spell.getTypeAndTraits().toNbt(compound); spell.getTypeAndTraits().toNbt(compound);
} }
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
if (spell == null || !Objects.equals(Spell.getUuid(compound), spell.getUuid())) { if (spell == null || !Objects.equals(Spell.getUuid(compound), spell.getUuid())) {
spell = Spell.readNbt(compound); spell = Spell.readNbt(compound, lookup);
} else { } else {
spell.fromNBT(compound); spell.fromNBT(compound, lookup);
} }
} }
} }

View file

@ -8,6 +8,7 @@ import com.minelittlepony.unicopia.server.world.UGameRules;
import com.minelittlepony.unicopia.server.world.UnicopiaWorldProperties; import com.minelittlepony.unicopia.server.world.UnicopiaWorldProperties;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
/** /**
@ -75,16 +76,16 @@ public class TimeControlAbilitySpell extends AbstractSpell {
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
compound.putBoolean("initilized", initilized); compound.putBoolean("initilized", initilized);
compound.putLong("timeOffset", timeOffset); compound.putLong("timeOffset", timeOffset);
compound.putFloat("angleOffset", angleOffset); compound.putFloat("angleOffset", angleOffset);
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
initilized = compound.getBoolean("initilized"); initilized = compound.getBoolean("initilized");
timeOffset = compound.getLong("timeOffset"); timeOffset = compound.getLong("timeOffset");
angleOffset = compound.getFloat("angleOffset"); angleOffset = compound.getFloat("angleOffset");

View file

@ -8,6 +8,7 @@ import com.minelittlepony.unicopia.util.NbtSerialisable;
import com.minelittlepony.unicopia.util.Tickable; import com.minelittlepony.unicopia.util.Tickable;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
/** /**
@ -44,13 +45,13 @@ public interface TimedSpell extends Spell {
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
compound.putInt("duration", duration); compound.putInt("duration", duration);
compound.putInt("maxDuration", maxDuration); compound.putInt("maxDuration", maxDuration);
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
duration = compound.getInt("duration"); duration = compound.getInt("duration");
maxDuration = compound.getInt("maxDuration"); maxDuration = compound.getInt("maxDuration");
} }

View file

@ -5,7 +5,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
import com.minelittlepony.unicopia.client.UnicopiaClient; import com.minelittlepony.unicopia.client.UnicopiaClient;
import com.minelittlepony.unicopia.client.gui.ItemTraitsTooltipRenderer; import com.minelittlepony.unicopia.client.gui.ItemTraitsTooltipRenderer;
import net.minecraft.item.ItemStack; import net.minecraft.component.type.AttributeModifiersComponent;
import net.minecraft.text.MutableText; import net.minecraft.text.MutableText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
@ -15,7 +15,7 @@ public enum AttributeFormat {
REGULAR { REGULAR {
@Override @Override
public String formatValue(float value) { public String formatValue(float value) {
return ItemStack.MODIFIER_FORMAT.format(value); return AttributeModifiersComponent.DECIMAL_FORMAT.format(value);
} }
}, },
TIME { TIME {
@ -27,7 +27,7 @@ public enum AttributeFormat {
PERCENTAGE { PERCENTAGE {
@Override @Override
public String formatValue(float value) { public String formatValue(float value) {
return ItemStack.MODIFIER_FORMAT.format((int)(Math.abs(value) * 100)) + "%"; return AttributeModifiersComponent.DECIMAL_FORMAT.format((int)(Math.abs(value) * 100)) + "%";
} }
}; };
@ -61,7 +61,7 @@ public enum AttributeFormat {
? trait.getName() ? trait.getName()
: Text.translatable("spell_attribute.unicopia.added_trait.unknown").formatted(Formatting.YELLOW) : Text.translatable("spell_attribute.unicopia.added_trait.unknown").formatted(Formatting.YELLOW)
: trait.getName().copy().formatted(Formatting.OBFUSCATED, Formatting.YELLOW); : trait.getName().copy().formatted(Formatting.OBFUSCATED, Formatting.YELLOW);
Text count = Text.literal(ItemStack.MODIFIER_FORMAT.format(value)); Text count = Text.literal(AttributeModifiersComponent.DECIMAL_FORMAT.format(value));
return Text.translatable("spell_attribute.unicopia.added_trait." + ((value > 0) ? "plus" : "take"), name, count).formatted(Formatting.DARK_AQUA); return Text.translatable("spell_attribute.unicopia.added_trait." + ((value > 0) ? "plus" : "take"), name, count).formatted(Formatting.DARK_AQUA);
} }

View file

@ -34,7 +34,6 @@ public record AltarRecipeMatch(
public void craft() { public void craft() {
ItemStack clockStack = result.copyWithCount(target.getStack().getCount()); ItemStack clockStack = result.copyWithCount(target.getStack().getCount());
clockStack.setNbt(target.getStack().getNbt());
target.setStack(clockStack); target.setStack(clockStack);
target.setInvulnerable(true); target.setInvulnerable(true);
ingredients.forEach(Entity::discard); ingredients.forEach(Entity::discard);

View file

@ -15,8 +15,11 @@ import com.mojang.serialization.Codec;
import net.minecraft.item.ItemConvertible; import net.minecraft.item.ItemConvertible;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.recipe.Ingredient; import net.minecraft.recipe.Ingredient;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DefaultedList; import net.minecraft.util.collection.DefaultedList;
public class IngredientWithSpell implements Predicate<ItemStack> { public class IngredientWithSpell implements Predicate<ItemStack> {
@ -27,6 +30,11 @@ public class IngredientWithSpell implements Predicate<ItemStack> {
pair -> new IngredientWithSpell(pair.getFirst(), pair.getSecond()), pair -> new IngredientWithSpell(pair.getFirst(), pair.getSecond()),
ingredient -> new Pair<>(ingredient.stack, ingredient.spell) ingredient -> new Pair<>(ingredient.stack, ingredient.spell)
); );
public static final PacketCodec<RegistryByteBuf, IngredientWithSpell> PACKET_CODEC = PacketCodec.tuple(
PacketCodecs.optional(Ingredient.PACKET_CODEC), i -> i.stack,
PacketCodecs.optional(Identifier.PACKET_CODEC.xmap(SpellType::getKey, SpellType::getId)), i -> i.spell,
IngredientWithSpell::new
);
public static final Codec<DefaultedList<IngredientWithSpell>> LIST_CODEC = CODEC.listOf().xmap( public static final Codec<DefaultedList<IngredientWithSpell>> LIST_CODEC = CODEC.listOf().xmap(
list -> DefaultedList.<IngredientWithSpell>copyOf(EMPTY, list.toArray(IngredientWithSpell[]::new)), list -> DefaultedList.<IngredientWithSpell>copyOf(EMPTY, list.toArray(IngredientWithSpell[]::new)),
@ -75,16 +83,4 @@ public class IngredientWithSpell implements Predicate<ItemStack> {
public boolean isEmpty() { public boolean isEmpty() {
return stack.filter(INGREDIENT_IS_PRESENT).isEmpty() && spell.isEmpty(); return stack.filter(INGREDIENT_IS_PRESENT).isEmpty() && spell.isEmpty();
} }
public void write(PacketByteBuf buf) {
buf.writeOptional(stack, (b, i) -> i.write(b));
buf.writeOptional(spell.map(SpellType::getId), PacketByteBuf::writeIdentifier);
}
public static IngredientWithSpell fromPacket(PacketByteBuf buf) {
return new IngredientWithSpell(
buf.readOptional(Ingredient::fromPacket),
buf.readOptional(PacketByteBuf::readIdentifier).flatMap(SpellType.REGISTRY::getOrEmpty)
);
}
} }

View file

@ -14,19 +14,40 @@ import com.minelittlepony.unicopia.util.CodecUtils;
import com.minelittlepony.unicopia.util.InventoryUtil; import com.minelittlepony.unicopia.util.InventoryUtil;
import com.mojang.datafixers.util.Pair; import com.mojang.datafixers.util.Pair;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.recipe.RecipeSerializer; import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.world.World; import net.minecraft.world.World;
/** /**
* A recipe for creating a new spell from input traits and items. * A recipe for creating a new spell from input traits and items.
*/ */
public class SpellCraftingRecipe implements SpellbookRecipe { public class SpellCraftingRecipe implements SpellbookRecipe {
private static final Codec<ItemStack> RESULT_CODEC = CodecUtils.extend(ItemStack.CODEC, SpellType.REGISTRY.getCodec().fieldOf("spell")).xmap(
pair -> pair.getSecond().map(spell -> EnchantableItem.enchant(pair.getFirst().orElse(ItemStack.EMPTY), spell)).orElse(pair.getFirst().orElse(ItemStack.EMPTY)),
stack -> Pair.of(Optional.of(stack), EnchantableItem.getSpellKeyOrEmpty(stack))
);
public static final MapCodec<SpellCraftingRecipe> CODEC = RecordCodecBuilder.<SpellCraftingRecipe>mapCodec(instance -> instance.group(
IngredientWithSpell.CODEC.fieldOf("material").forGetter(recipe -> recipe.material),
TraitIngredient.CODEC.fieldOf("traits").forGetter(recipe -> recipe.requiredTraits),
IngredientWithSpell.CODEC.listOf().fieldOf("ingredients").forGetter(recipe -> recipe.requiredItems),
RESULT_CODEC.fieldOf("result").forGetter(recipe -> recipe.output)
).apply(instance, SpellCraftingRecipe::new));
public static final PacketCodec<RegistryByteBuf, SpellCraftingRecipe> PACKET_CODEC = PacketCodec.tuple(
IngredientWithSpell.PACKET_CODEC, recipe -> recipe.material,
TraitIngredient.PACKET_CODEC, recipe -> recipe.requiredTraits,
IngredientWithSpell.PACKET_CODEC.collect(PacketCodecs.toList()), recipe -> recipe.requiredItems,
ItemStack.PACKET_CODEC, recipe -> recipe.output,
SpellCraftingRecipe::new
);
/** /**
* The ingredient to modify * The ingredient to modify
*/ */
@ -104,7 +125,7 @@ public class SpellCraftingRecipe implements SpellbookRecipe {
} }
@Override @Override
public ItemStack craft(SpellbookInventory inventory, DynamicRegistryManager registries) { public ItemStack craft(SpellbookInventory inventory, WrapperLookup registries) {
return getResult(registries).copy(); return getResult(registries).copy();
} }
@ -114,7 +135,7 @@ public class SpellCraftingRecipe implements SpellbookRecipe {
} }
@Override @Override
public ItemStack getResult(DynamicRegistryManager registries) { public ItemStack getResult(WrapperLookup registries) {
return output; return output;
} }
@ -122,41 +143,4 @@ public class SpellCraftingRecipe implements SpellbookRecipe {
public RecipeSerializer<?> getSerializer() { public RecipeSerializer<?> getSerializer() {
return URecipes.TRAIT_REQUIREMENT; return URecipes.TRAIT_REQUIREMENT;
} }
public static class Serializer implements RecipeSerializer<SpellCraftingRecipe> {
private static final Codec<ItemStack> RESULT_CODEC = CodecUtils.extend(ItemStack.RECIPE_RESULT_CODEC, SpellType.REGISTRY.getCodec().fieldOf("spell")).xmap(
pair -> pair.getSecond().map(spell -> EnchantableItem.enchant(pair.getFirst().orElse(ItemStack.EMPTY), spell)).orElse(pair.getFirst().orElse(ItemStack.EMPTY)),
stack -> Pair.of(Optional.of(stack), EnchantableItem.getSpellKeyOrEmpty(stack))
);
private static final Codec<SpellCraftingRecipe> CODEC = RecordCodecBuilder.<SpellCraftingRecipe>create(instance -> instance.group(
IngredientWithSpell.CODEC.fieldOf("material").forGetter(recipe -> recipe.material),
TraitIngredient.CODEC.fieldOf("traits").forGetter(recipe -> recipe.requiredTraits),
IngredientWithSpell.CODEC.listOf().fieldOf("ingredients").forGetter(recipe -> recipe.requiredItems),
RESULT_CODEC.fieldOf("result").forGetter(recipe -> recipe.output)
).apply(instance, SpellCraftingRecipe::new));
@Override
public Codec<SpellCraftingRecipe> codec() {
return CODEC;
}
@Override
public SpellCraftingRecipe read(PacketByteBuf buf) {
return new SpellCraftingRecipe(
IngredientWithSpell.fromPacket(buf),
TraitIngredient.fromPacket(buf),
buf.readCollection(DefaultedList::ofSize, IngredientWithSpell::fromPacket),
buf.readItemStack()
);
}
@Override
public void write(PacketByteBuf buf, SpellCraftingRecipe recipe) {
recipe.material.write(buf);
recipe.requiredTraits.write(buf);
buf.writeCollection(recipe.requiredItems, (b, i) -> i.write(b));
buf.writeItemStack(recipe.output);
}
}
} }

View file

@ -5,22 +5,24 @@ import com.minelittlepony.unicopia.container.inventory.SpellbookInventory;
import com.minelittlepony.unicopia.item.*; import com.minelittlepony.unicopia.item.*;
import com.minelittlepony.unicopia.recipe.URecipes; import com.minelittlepony.unicopia.recipe.URecipes;
import com.minelittlepony.unicopia.util.InventoryUtil; import com.minelittlepony.unicopia.util.InventoryUtil;
import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.recipe.RecipeSerializer; import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.world.World; import net.minecraft.world.World;
/** /**
* A recipe for creating a new spell from input traits and items. * A recipe for creating a new spell from input traits and items.
*/ */
public record SpellDuplicatingRecipe (IngredientWithSpell material) implements SpellbookRecipe { public record SpellDuplicatingRecipe (IngredientWithSpell material) implements SpellbookRecipe {
public static final Codec<SpellDuplicatingRecipe> CODEC = RecordCodecBuilder.create(instance -> instance.group( public static final MapCodec<SpellDuplicatingRecipe> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
IngredientWithSpell.CODEC.fieldOf("material").forGetter(recipe -> recipe.material) IngredientWithSpell.CODEC.fieldOf("material").forGetter(recipe -> recipe.material)
).apply(instance, SpellDuplicatingRecipe::new)); ).apply(instance, SpellDuplicatingRecipe::new));
public static final PacketCodec<RegistryByteBuf, SpellDuplicatingRecipe> PACKET_CODEC = IngredientWithSpell.PACKET_CODEC.xmap(SpellDuplicatingRecipe::new, SpellDuplicatingRecipe::material);
@Override @Override
public void buildCraftingTree(CraftingTreeBuilder builder) { public void buildCraftingTree(CraftingTreeBuilder builder) {
@ -50,7 +52,7 @@ public record SpellDuplicatingRecipe (IngredientWithSpell material) implements S
} }
@Override @Override
public ItemStack craft(SpellbookInventory inventory, DynamicRegistryManager registries) { public ItemStack craft(SpellbookInventory inventory, WrapperLookup registries) {
return InventoryUtil.stream(inventory) return InventoryUtil.stream(inventory)
.filter(i -> i.isOf(UItems.GEMSTONE)) .filter(i -> i.isOf(UItems.GEMSTONE))
.filter(EnchantableItem::isEnchanted) .filter(EnchantableItem::isEnchanted)
@ -68,7 +70,7 @@ public record SpellDuplicatingRecipe (IngredientWithSpell material) implements S
} }
@Override @Override
public ItemStack getResult(DynamicRegistryManager registries) { public ItemStack getResult(WrapperLookup registries) {
ItemStack stack = UItems.GEMSTONE.getDefaultStack(); ItemStack stack = UItems.GEMSTONE.getDefaultStack();
stack.setCount(2); stack.setCount(2);
return stack; return stack;
@ -78,21 +80,4 @@ public record SpellDuplicatingRecipe (IngredientWithSpell material) implements S
public RecipeSerializer<?> getSerializer() { public RecipeSerializer<?> getSerializer() {
return URecipes.SPELL_DUPLICATING; return URecipes.SPELL_DUPLICATING;
} }
public static class Serializer implements RecipeSerializer<SpellDuplicatingRecipe> {
@Override
public Codec<SpellDuplicatingRecipe> codec() {
return CODEC;
}
@Override
public SpellDuplicatingRecipe read(PacketByteBuf buf) {
return new SpellDuplicatingRecipe(IngredientWithSpell.fromPacket(buf));
}
@Override
public void write(PacketByteBuf buf, SpellDuplicatingRecipe recipe) {
recipe.material.write(buf);
}
}
} }

View file

@ -3,23 +3,25 @@ package com.minelittlepony.unicopia.ability.magic.spell.crafting;
import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits; import com.minelittlepony.unicopia.ability.magic.spell.trait.SpellTraits;
import com.minelittlepony.unicopia.container.inventory.SpellbookInventory; import com.minelittlepony.unicopia.container.inventory.SpellbookInventory;
import com.minelittlepony.unicopia.item.*; import com.minelittlepony.unicopia.item.*;
import com.mojang.serialization.Codec; import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder;
import com.minelittlepony.unicopia.recipe.URecipes; import com.minelittlepony.unicopia.recipe.URecipes;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.recipe.RecipeSerializer; import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.world.World; import net.minecraft.world.World;
/** /**
* Recipe for adding traits to an existing spell. * Recipe for adding traits to an existing spell.
*/ */
public record SpellEnhancingRecipe (IngredientWithSpell material) implements SpellbookRecipe { public record SpellEnhancingRecipe (IngredientWithSpell material) implements SpellbookRecipe {
public static final Codec<SpellEnhancingRecipe> CODEC = RecordCodecBuilder.create(instance -> instance.group( public static final MapCodec<SpellEnhancingRecipe> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
IngredientWithSpell.CODEC.fieldOf("material").forGetter(recipe -> recipe.material) IngredientWithSpell.CODEC.fieldOf("material").forGetter(recipe -> recipe.material)
).apply(instance, SpellEnhancingRecipe::new)); ).apply(instance, SpellEnhancingRecipe::new));
public static final PacketCodec<RegistryByteBuf, SpellEnhancingRecipe> PACKET_CODEC = IngredientWithSpell.PACKET_CODEC.xmap(SpellEnhancingRecipe::new, SpellEnhancingRecipe::material);
public IngredientWithSpell getBaseMaterial() { public IngredientWithSpell getBaseMaterial() {
return material; return material;
@ -42,7 +44,7 @@ public record SpellEnhancingRecipe (IngredientWithSpell material) implements Spe
} }
@Override @Override
public ItemStack craft(SpellbookInventory inventory, DynamicRegistryManager registries) { public ItemStack craft(SpellbookInventory inventory, WrapperLookup registries) {
return SpellTraits.of(inventory.getItemToModify()) return SpellTraits.of(inventory.getItemToModify())
.add(inventory.getTraits()) .add(inventory.getTraits())
.applyTo(inventory.getItemToModify()); .applyTo(inventory.getItemToModify());
@ -54,7 +56,7 @@ public record SpellEnhancingRecipe (IngredientWithSpell material) implements Spe
} }
@Override @Override
public ItemStack getResult(DynamicRegistryManager registries) { public ItemStack getResult(WrapperLookup registries) {
return UItems.GEMSTONE.getDefaultStack(); return UItems.GEMSTONE.getDefaultStack();
} }
@ -62,21 +64,4 @@ public record SpellEnhancingRecipe (IngredientWithSpell material) implements Spe
public RecipeSerializer<?> getSerializer() { public RecipeSerializer<?> getSerializer() {
return URecipes.TRAIT_COMBINING; return URecipes.TRAIT_COMBINING;
} }
public static class Serializer implements RecipeSerializer<SpellEnhancingRecipe> {
@Override
public Codec<SpellEnhancingRecipe> codec() {
return CODEC;
}
@Override
public SpellEnhancingRecipe read(PacketByteBuf buf) {
return new SpellEnhancingRecipe(IngredientWithSpell.fromPacket(buf));
}
@Override
public void write(PacketByteBuf buf, SpellEnhancingRecipe recipe) {
recipe.material().write(buf);
}
}
} }

View file

@ -2,21 +2,37 @@ package com.minelittlepony.unicopia.ability.magic.spell.crafting;
import com.minelittlepony.unicopia.item.EnchantableItem; import com.minelittlepony.unicopia.item.EnchantableItem;
import com.minelittlepony.unicopia.recipe.URecipes; import com.minelittlepony.unicopia.recipe.URecipes;
import com.minelittlepony.unicopia.util.InventoryUtil;
import com.mojang.serialization.Codec; import com.mojang.serialization.Codec;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.inventory.RecipeInputInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
import net.minecraft.recipe.RawShapedRecipe; import net.minecraft.recipe.RawShapedRecipe;
import net.minecraft.recipe.RecipeSerializer; import net.minecraft.recipe.RecipeSerializer;
import net.minecraft.recipe.ShapedRecipe; import net.minecraft.recipe.ShapedRecipe;
import net.minecraft.recipe.book.CraftingRecipeCategory; import net.minecraft.recipe.book.CraftingRecipeCategory;
import net.minecraft.registry.DynamicRegistryManager; import net.minecraft.recipe.input.CraftingRecipeInput;
import net.minecraft.util.dynamic.Codecs; import net.minecraft.registry.RegistryWrapper.WrapperLookup;
public class SpellShapedCraftingRecipe extends ShapedRecipe { public class SpellShapedCraftingRecipe extends ShapedRecipe {
public static final MapCodec<SpellShapedCraftingRecipe> CODEC = RecordCodecBuilder.mapCodec(instance -> instance.group(
Codec.STRING.optionalFieldOf("group", "").forGetter(SpellShapedCraftingRecipe::getGroup),
CraftingRecipeCategory.CODEC.fieldOf("category").orElse(CraftingRecipeCategory.MISC).forGetter(SpellShapedCraftingRecipe::getCategory),
RawShapedRecipe.CODEC.forGetter(recipe -> recipe.raw), ItemStack.VALIDATED_CODEC.fieldOf("result").forGetter(recipe -> recipe.result),
Codec.BOOL.optionalFieldOf("show_notification", true).forGetter(SpellShapedCraftingRecipe::showNotification)
).apply(instance, SpellShapedCraftingRecipe::new));
public static final PacketCodec<RegistryByteBuf, SpellShapedCraftingRecipe> PACKET_CODEC = PacketCodec.tuple(
PacketCodecs.STRING, SpellShapedCraftingRecipe::getGroup,
CraftingRecipeCategory.PACKET_CODEC, SpellShapedCraftingRecipe::getCategory,
RawShapedRecipe.PACKET_CODEC, recipe -> recipe.raw,
ItemStack.PACKET_CODEC, recipe -> recipe.result,
PacketCodecs.BOOL, SpellShapedCraftingRecipe::showNotification,
SpellShapedCraftingRecipe::new
);
private final RawShapedRecipe raw; private final RawShapedRecipe raw;
private final ItemStack result; private final ItemStack result;
@ -27,8 +43,8 @@ public class SpellShapedCraftingRecipe extends ShapedRecipe {
} }
@Override @Override
public ItemStack craft(RecipeInputInventory inventory, DynamicRegistryManager registries) { public ItemStack craft(CraftingRecipeInput inventory, WrapperLookup registries) {
return InventoryUtil.stream(inventory) return inventory.getStacks().stream()
.filter(stack -> stack.getItem() instanceof EnchantableItem) .filter(stack -> stack.getItem() instanceof EnchantableItem)
.filter(EnchantableItem::isEnchanted) .filter(EnchantableItem::isEnchanted)
.map(stack -> ((EnchantableItem)stack.getItem()).getSpellEffect(stack)) .map(stack -> ((EnchantableItem)stack.getItem()).getSpellEffect(stack))
@ -41,38 +57,4 @@ public class SpellShapedCraftingRecipe extends ShapedRecipe {
public RecipeSerializer<?> getSerializer() { public RecipeSerializer<?> getSerializer() {
return URecipes.CRAFTING_MAGICAL_SERIALIZER; return URecipes.CRAFTING_MAGICAL_SERIALIZER;
} }
public static class Serializer implements RecipeSerializer<SpellShapedCraftingRecipe> {
public static final Codec<SpellShapedCraftingRecipe> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codecs.createStrictOptionalFieldCodec(Codec.STRING, "group", "").forGetter(SpellShapedCraftingRecipe::getGroup),
CraftingRecipeCategory.CODEC.fieldOf("category").orElse(CraftingRecipeCategory.MISC).forGetter(SpellShapedCraftingRecipe::getCategory),
RawShapedRecipe.CODEC.forGetter(recipe -> recipe.raw), ItemStack.RECIPE_RESULT_CODEC.fieldOf("result").forGetter(recipe -> recipe.result),
Codecs.createStrictOptionalFieldCodec(Codec.BOOL, "show_notification", true).forGetter(SpellShapedCraftingRecipe::showNotification)
).apply(instance, SpellShapedCraftingRecipe::new));
@Override
public Codec<SpellShapedCraftingRecipe> codec() {
return CODEC;
}
@Override
public SpellShapedCraftingRecipe read(PacketByteBuf buffer) {
return new SpellShapedCraftingRecipe(
buffer.readString(),
buffer.readEnumConstant(CraftingRecipeCategory.class),
RawShapedRecipe.readFromBuf(buffer),
buffer.readItemStack(),
buffer.readBoolean()
);
}
@Override
public void write(PacketByteBuf packetByteBuf, SpellShapedCraftingRecipe shapedRecipe) {
packetByteBuf.writeString(shapedRecipe.getGroup());
packetByteBuf.writeEnumConstant(shapedRecipe.getCategory());
shapedRecipe.raw.writeToBuf(packetByteBuf);
packetByteBuf.writeItemStack(shapedRecipe.result);
packetByteBuf.writeBoolean(shapedRecipe.showNotification());
}
}
} }

View file

@ -10,7 +10,8 @@ import com.mojang.serialization.DataResult;
import com.mojang.serialization.codecs.RecordCodecBuilder; import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.dynamic.Codecs; import net.minecraft.network.codec.PacketCodec;
import net.minecraft.network.codec.PacketCodecs;
public record TraitIngredient ( public record TraitIngredient (
Optional<SpellTraits> min, Optional<SpellTraits> min,
@ -27,10 +28,15 @@ public record TraitIngredient (
ingredient -> !ingredient.isEmpty() ? DataResult.success(ingredient) : DataResult.error(() -> "No min or max supplied for ingredient"), ingredient -> !ingredient.isEmpty() ? DataResult.success(ingredient) : DataResult.error(() -> "No min or max supplied for ingredient"),
DataResult::success DataResult::success
); );
public static final Codec<TraitIngredient> CODEC = Codecs.xor(INLINE_CODEC, STRUCTURED_CODEC).flatXmap( public static final Codec<TraitIngredient> CODEC = Codec.xor(INLINE_CODEC, STRUCTURED_CODEC).flatXmap(
either -> either.left().or(either::right).map(DataResult::success).orElseGet(() -> DataResult.error(() -> "Invalid traits")), either -> either.left().or(either::right).map(DataResult::success).orElseGet(() -> DataResult.error(() -> "Invalid traits")),
ingredient -> DataResult.success(ingredient.max.isEmpty() ? Either.left(ingredient) : Either.right(ingredient)) ingredient -> DataResult.success(ingredient.max.isEmpty() ? Either.left(ingredient) : Either.right(ingredient))
); );
public static final PacketCodec<PacketByteBuf, TraitIngredient> PACKET_CODEC = PacketCodec.tuple(
PacketCodecs.optional(SpellTraits.PACKET_CODEC), TraitIngredient::min,
PacketCodecs.optional(SpellTraits.PACKET_CODEC), TraitIngredient::max,
TraitIngredient::new
);
public static TraitIngredient of(SpellTraits minTraits) { public static TraitIngredient of(SpellTraits minTraits) {
if (minTraits.isEmpty()) { if (minTraits.isEmpty()) {
@ -60,13 +66,4 @@ public record TraitIngredient (
boolean maxMatch = max.map(m -> m.includes(t)).orElse(true); boolean maxMatch = max.map(m -> m.includes(t)).orElse(true);
return minMatch && maxMatch; return minMatch && maxMatch;
} }
public void write(PacketByteBuf buf) {
buf.writeOptional(min, (b, m) -> m.write(b));
buf.writeOptional(max, (b, m) -> m.write(b));
}
public static TraitIngredient fromPacket(PacketByteBuf buf) {
return new TraitIngredient(SpellTraits.fromPacketOrEmpty(buf), SpellTraits.fromPacketOrEmpty(buf));
}
} }

View file

@ -10,6 +10,7 @@ import com.minelittlepony.unicopia.network.track.TrackableDataType;
import com.minelittlepony.unicopia.server.world.Ether; import com.minelittlepony.unicopia.server.world.Ether;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
public abstract class AbstractSpell implements Spell { public abstract class AbstractSpell implements Spell {
@ -97,7 +98,7 @@ public abstract class AbstractSpell implements Spell {
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
compound.putBoolean("dying", dying.get()); compound.putBoolean("dying", dying.get());
compound.putBoolean("dead", dead.get()); compound.putBoolean("dead", dead.get());
compound.putBoolean("hidden", hidden.get()); compound.putBoolean("hidden", hidden.get());
@ -106,7 +107,7 @@ public abstract class AbstractSpell implements Spell {
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
if (compound.containsUuid("uuid")) { if (compound.containsUuid("uuid")) {
uuid = compound.getUuid("uuid"); uuid = compound.getUuid("uuid");
} }

View file

@ -17,6 +17,7 @@ import com.minelittlepony.unicopia.entity.effect.EffectUtils;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.text.MutableText; import net.minecraft.text.MutableText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
@ -51,10 +52,10 @@ public record CustomisedSpellType<T extends Spell> (
} }
@Nullable @Nullable
public T create(NbtCompound compound) { public T create(NbtCompound compound, WrapperLookup lookup) {
T spell = create(); T spell = create();
if (spell != null) { if (spell != null) {
spell.fromNBT(compound); spell.fromNBT(compound, lookup);
} }
return spell; return spell;
} }

View file

@ -40,6 +40,7 @@ import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.hit.EntityHitResult;
@ -303,14 +304,14 @@ public class DarkVortexSpell extends AbstractSpell implements ProjectileDelegate
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
compound.putFloat("accumulatedMass", accumulatedMass.get()); compound.putFloat("accumulatedMass", accumulatedMass.get());
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
accumulatedMass.set(compound.getFloat("accumulatedMass")); accumulatedMass.set(compound.getFloat("accumulatedMass"));
} }
} }

View file

@ -15,6 +15,7 @@ import com.minelittlepony.unicopia.projectile.ProjectileDelegate;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -94,7 +95,8 @@ public class DisplacementSpell extends AbstractSpell implements HomingSpell, Pro
} }
private void teleport(Caster<?> source, Entity entity, Vec3d pos, Vec3d vel) { private void teleport(Caster<?> source, Entity entity, Vec3d pos, Vec3d vel) {
entity.teleport(pos.x, pos.y, pos.z); // TODO: teleport -> requestTeleport
entity.requestTeleport(pos.x, pos.y, pos.z);
entity.setVelocity(vel); entity.setVelocity(vel);
entity.setGlowing(false); entity.setGlowing(false);
entity.playSound(USounds.SPELL_DISPLACEMENT_TELEPORT, 1, 1); entity.playSound(USounds.SPELL_DISPLACEMENT_TELEPORT, 1, 1);
@ -124,16 +126,16 @@ public class DisplacementSpell extends AbstractSpell implements HomingSpell, Pro
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
compound.putInt("ticks", ticks); compound.putInt("ticks", ticks);
compound.put("target", target.toNBT()); compound.put("target", target.toNBT(lookup));
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
ticks = compound.getInt("ticks"); ticks = compound.getInt("ticks");
target.fromNBT(compound.getCompound("target")); target.fromNBT(compound.getCompound("target"), lookup);
} }
} }

View file

@ -19,6 +19,7 @@ import com.minelittlepony.unicopia.particle.ParticleUtils;
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.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
@ -124,14 +125,14 @@ public class FeatherFallSpell extends AbstractSpell implements TimedSpell {
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
timer.toNBT(compound); timer.toNBT(compound, lookup);
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
timer.fromNBT(compound); timer.fromNBT(compound, lookup);
} }
} }

View file

@ -18,6 +18,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.predicate.entity.EntityPredicates; import net.minecraft.predicate.entity.EntityPredicates;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.hit.EntityHitResult;
public class FireBoltSpell extends AbstractSpell implements HomingSpell, public class FireBoltSpell extends AbstractSpell implements HomingSpell,
@ -112,14 +113,14 @@ public class FireBoltSpell extends AbstractSpell implements HomingSpell,
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
compound.put("target", target.toNBT()); compound.put("target", target.toNBT(lookup));
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
target.fromNBT(compound.getCompound("target")); target.fromNBT(compound.getCompound("target"), lookup);
} }
} }

View file

@ -17,13 +17,17 @@ import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.particle.UParticles; import com.minelittlepony.unicopia.particle.UParticles;
import com.minelittlepony.unicopia.projectile.MagicProjectileEntity; import com.minelittlepony.unicopia.projectile.MagicProjectileEntity;
import com.minelittlepony.unicopia.server.world.Ether; import com.minelittlepony.unicopia.server.world.Ether;
import com.minelittlepony.unicopia.util.CodecUtils;
import com.minelittlepony.unicopia.util.NbtSerialisable; import com.minelittlepony.unicopia.util.NbtSerialisable;
import com.minelittlepony.unicopia.util.shape.*; import com.minelittlepony.unicopia.util.shape.*;
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.fluid.*; import net.minecraft.fluid.*;
import net.minecraft.nbt.*; import net.minecraft.nbt.*;
import net.minecraft.state.property.Properties; import net.minecraft.state.property.Properties;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.registry.tag.TagKey; import net.minecraft.registry.tag.TagKey;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -129,16 +133,16 @@ public class HydrophobicSpell extends AbstractSpell {
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
compound.put("storedFluidPositions", Entry.SERIALIZER.writeAll(storedFluidPositions)); compound.put("storedFluidPositions", NbtSerialisable.encode(Entry.SET_CODEC, storedFluidPositions));
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
storedFluidPositions.clear(); storedFluidPositions.clear();
storedFluidPositions.addAll(Entry.SERIALIZER.readAll(compound.getList("storedFluidPositions", NbtElement.COMPOUND_TYPE)).toList()); NbtSerialisable.decode(Entry.SET_CODEC, compound.getList("storedFluidPositions", NbtElement.COMPOUND_TYPE)).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.
@ -152,15 +156,11 @@ public class HydrophobicSpell extends AbstractSpell {
} }
record Entry (BlockPos pos, BlockState blockState) { record Entry (BlockPos pos, BlockState blockState) {
public static final Serializer<Entry> SERIALIZER = Serializer.of(compound -> new Entry( public static final Codec<Entry> CODEC = RecordCodecBuilder.create(instance -> instance.group(
NbtSerialisable.BLOCK_POS.read(compound.getCompound("pos")), BlockPos.CODEC.fieldOf("pos").forGetter(Entry::pos),
NbtSerialisable.decode(BlockState.CODEC, compound.get("blockState")).orElse(Blocks.AIR.getDefaultState()) BlockState.CODEC.optionalFieldOf("blockState", Blocks.AIR.getDefaultState()).forGetter(Entry::blockState)
), entry -> { ).apply(instance, Entry::new));
NbtCompound compound = new NbtCompound(); public static final Codec<Set<Entry>> SET_CODEC = CodecUtils.setOf(CODEC);
compound.put("pos", NbtSerialisable.BLOCK_POS.write(entry.pos));
compound.put("blockState", NbtSerialisable.encode(BlockState.CODEC, entry.blockState));
return compound;
});
void restore(World world) { void restore(World world) {
BlockState state = world.getBlockState(pos); BlockState state = world.getBlockState(pos);

View file

@ -24,6 +24,7 @@ import com.minelittlepony.unicopia.util.VecHelper;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList; import net.minecraft.nbt.NbtList;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
public class LightSpell extends AbstractSpell implements TimedSpell, ProjectileDelegate.HitListener { public class LightSpell extends AbstractSpell implements TimedSpell, ProjectileDelegate.HitListener {
@ -109,26 +110,26 @@ public class LightSpell extends AbstractSpell implements TimedSpell, ProjectileD
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
timer.toNBT(compound); timer.toNBT(compound, lookup);
if (!lights.isEmpty()) { if (!lights.isEmpty()) {
NbtList list = new NbtList(); NbtList list = new NbtList();
lights.forEach(light -> { lights.forEach(light -> {
list.add(light.toNBT()); list.add(light.toNBT(lookup));
}); });
compound.put("lights", list); compound.put("lights", list);
} }
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
timer.fromNBT(compound); timer.fromNBT(compound, lookup);
lights.clear(); lights.clear();
if (compound.contains("lights", NbtElement.LIST_TYPE)) { if (compound.contains("lights", NbtElement.LIST_TYPE)) {
compound.getList("lights", NbtElement.COMPOUND_TYPE).forEach(nbt -> { compound.getList("lights", NbtElement.COMPOUND_TYPE).forEach(nbt -> {
lights.add(new EntityReference<>((NbtCompound)nbt)); lights.add(new EntityReference<>((NbtCompound)nbt, lookup));
}); });
} }
} }

View file

@ -6,6 +6,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.attribute.TooltipFactory;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
public class MimicSpell extends AbstractDisguiseSpell implements HomingSpell, TimedSpell { public class MimicSpell extends AbstractDisguiseSpell implements HomingSpell, TimedSpell {
@ -40,14 +41,14 @@ public class MimicSpell extends AbstractDisguiseSpell implements HomingSpell, Ti
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
timer.toNBT(compound); timer.toNBT(compound, lookup);
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
timer.fromNBT(compound); timer.fromNBT(compound, lookup);
} }
} }

View file

@ -25,6 +25,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtElement;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.world.GameMode; import net.minecraft.world.GameMode;
@ -192,18 +193,18 @@ public class MindSwapSpell extends MimicSpell implements ProjectileDelegate.Enti
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
compound.put("counterpart", counterpart.toNBT()); compound.put("counterpart", counterpart.toNBT(lookup));
compound.putBoolean("initialized", initialized); compound.putBoolean("initialized", initialized);
myStoredInventory.ifPresent(mine -> compound.put("myStoredInventory", mine.toNBT(new NbtCompound()))); myStoredInventory.ifPresent(mine -> compound.put("myStoredInventory", mine.toNBT(new NbtCompound())));
theirStoredInventory.ifPresent(mine -> compound.put("theirStoredInventory", mine.toNBT(new NbtCompound()))); theirStoredInventory.ifPresent(mine -> compound.put("theirStoredInventory", mine.toNBT(new NbtCompound())));
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
counterpart.fromNBT(compound.getCompound("counterpart")); counterpart.fromNBT(compound.getCompound("counterpart"), lookup);
initialized = compound.getBoolean("initialized"); initialized = compound.getBoolean("initialized");
myStoredInventory = Optional.ofNullable(compound.contains("myStoredInventory", NbtElement.COMPOUND_TYPE) ? Inventory.fromNBT(compound.getCompound("myStoredInventory")) : null); myStoredInventory = Optional.ofNullable(compound.contains("myStoredInventory", NbtElement.COMPOUND_TYPE) ? Inventory.fromNBT(compound.getCompound("myStoredInventory")) : null);
theirStoredInventory = Optional.ofNullable(compound.contains("theirStoredInventory", NbtElement.COMPOUND_TYPE) ? Inventory.fromNBT(compound.getCompound("theirStoredInventory")) : null); theirStoredInventory = Optional.ofNullable(compound.contains("theirStoredInventory", NbtElement.COMPOUND_TYPE) ? Inventory.fromNBT(compound.getCompound("theirStoredInventory")) : null);

View file

@ -35,6 +35,7 @@ import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList; import net.minecraft.nbt.NbtList;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -217,24 +218,24 @@ public class NecromancySpell extends AbstractAreaEffectSpell implements Projecti
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
compound.putInt("spawnCountdown", spawnCountdown); compound.putInt("spawnCountdown", spawnCountdown);
if (summonedEntities.size() > 0) { if (summonedEntities.size() > 0) {
NbtList list = new NbtList(); NbtList list = new NbtList();
summonedEntities.forEach(ref -> list.add(ref.toNBT())); summonedEntities.forEach(ref -> list.add(ref.toNBT(lookup)));
compound.put("summonedEntities", list); compound.put("summonedEntities", list);
} }
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
spawnCountdown = compound.getInt("spawnCountdown"); spawnCountdown = compound.getInt("spawnCountdown");
summonedEntities.clear(); summonedEntities.clear();
if (compound.contains("summonedEntities")) { if (compound.contains("summonedEntities")) {
compound.getList("summonedEntities", NbtElement.COMPOUND_TYPE).forEach(tag -> { compound.getList("summonedEntities", NbtElement.COMPOUND_TYPE).forEach(tag -> {
summonedEntities.add(new EntityReference<>((NbtCompound)tag)); summonedEntities.add(new EntityReference<>((NbtCompound)tag, lookup));
}); });
} }
} }

View file

@ -26,6 +26,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.s2c.play.PositionFlag; import net.minecraft.network.packet.s2c.play.PositionFlag;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.Util; import net.minecraft.util.Util;
@ -226,10 +227,10 @@ public class PortalSpell extends AbstractSpell implements PlacementControlSpell.
} }
@Override @Override
public void toNBT(NbtCompound compound) { public void toNBT(NbtCompound compound, WrapperLookup lookup) {
super.toNBT(compound); super.toNBT(compound, lookup);
compound.putUuid("targetPortalId", targetPortalId.get()); compound.putUuid("targetPortalId", targetPortalId.get());
compound.put("teleportationTarget", teleportationTarget.toNBT()); compound.put("teleportationTarget", teleportationTarget.toNBT(lookup));
compound.putFloat("pitch", getPitch()); compound.putFloat("pitch", getPitch());
compound.putFloat("yaw", getYaw()); compound.putFloat("yaw", getYaw());
compound.putFloat("targetPortalPitch", getTargetPitch()); compound.putFloat("targetPortalPitch", getTargetPitch());
@ -237,10 +238,10 @@ public class PortalSpell extends AbstractSpell implements PlacementControlSpell.
} }
@Override @Override
public void fromNBT(NbtCompound compound) { public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
super.fromNBT(compound); super.fromNBT(compound, lookup);
targetPortalId.set(compound.containsUuid("targetPortalId") ? compound.getUuid("targetPortalId") : Util.NIL_UUID); targetPortalId.set(compound.containsUuid("targetPortalId") ? compound.getUuid("targetPortalId") : Util.NIL_UUID);
teleportationTarget.fromNBT(compound.getCompound("teleportationTarget")); teleportationTarget.fromNBT(compound.getCompound("teleportationTarget"), lookup);
pitch.set(compound.getFloat("pitch")); pitch.set(compound.getFloat("pitch"));
yaw.set(compound.getFloat("yaw")); yaw.set(compound.getFloat("yaw"));
targetPortalPitch.set(compound.getFloat("targetPortalPitch")); targetPortalPitch.set(compound.getFloat("targetPortalPitch"));

View file

@ -35,6 +35,8 @@ import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement; import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtOps; import net.minecraft.nbt.NbtOps;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.RegistryByteBuf;
import net.minecraft.network.codec.PacketCodec;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
@ -51,6 +53,7 @@ public final class SpellTraits implements Iterable<Map.Entry<Trait, Float>> {
map -> DataResult.success(fromEntries(map.entrySet().stream()).orElse(EMPTY)), map -> DataResult.success(fromEntries(map.entrySet().stream()).orElse(EMPTY)),
traits -> DataResult.success(traits.traits) traits -> DataResult.success(traits.traits)
); );
public static final PacketCodec<PacketByteBuf, SpellTraits> PACKET_CODEC = PacketCodec.ofStatic((a, b) -> b.write(a), SpellTraits::fromPacket);
public static void load(Map<Identifier, SpellTraits> newRegistry) { public static void load(Map<Identifier, SpellTraits> newRegistry) {
REGISTRY = newRegistry; REGISTRY = newRegistry;
@ -169,6 +172,7 @@ public final class SpellTraits implements Iterable<Map.Entry<Trait, Float>> {
return nbt; return nbt;
} }
@Deprecated
public void write(PacketByteBuf buf) { public void write(PacketByteBuf buf) {
buf.writeInt(traits.size()); buf.writeInt(traits.size());
traits.forEach((trait, value) -> { traits.forEach((trait, value) -> {
@ -264,10 +268,12 @@ public final class SpellTraits implements Iterable<Map.Entry<Trait, Float>> {
return CODEC.decode(NbtOps.INSTANCE, traits).result().map(Pair::getFirst); return CODEC.decode(NbtOps.INSTANCE, traits).result().map(Pair::getFirst);
} }
@Deprecated
public static Optional<SpellTraits> fromPacketOrEmpty(PacketByteBuf buf) { public static Optional<SpellTraits> fromPacketOrEmpty(PacketByteBuf buf) {
return buf.readOptional(SpellTraits::fromPacket).filter(SpellTraits::isPresent); return buf.readOptional(SpellTraits::fromPacket).filter(SpellTraits::isPresent);
} }
@Deprecated
public static SpellTraits fromPacket(PacketByteBuf buf) { public static SpellTraits fromPacket(PacketByteBuf buf) {
Map<Trait, Float> entries = new HashMap<>(); Map<Trait, Float> entries = new HashMap<>();
int count = buf.readInt(); int count = buf.readInt();

View file

@ -16,7 +16,6 @@ import net.minecraft.entity.Entity;
import net.minecraft.predicate.entity.EntityPredicate; import net.minecraft.predicate.entity.EntityPredicate;
import net.minecraft.predicate.entity.LootContextPredicate; import net.minecraft.predicate.entity.LootContextPredicate;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.dynamic.Codecs;
public class CustomEventCriterion extends AbstractCriterion<CustomEventCriterion.Conditions> { public class CustomEventCriterion extends AbstractCriterion<CustomEventCriterion.Conditions> {
@Override @Override
@ -61,7 +60,7 @@ public class CustomEventCriterion extends AbstractCriterion<CustomEventCriterion
TriState flying, TriState flying,
int repeatCount) implements AbstractCriterion.Conditions { int repeatCount) implements AbstractCriterion.Conditions {
public static final Codec<Conditions> CODEC = RecordCodecBuilder.create(instance -> instance.group( public static final Codec<Conditions> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codecs.createStrictOptionalFieldCodec(EntityPredicate.LOOT_CONTEXT_PREDICATE_CODEC, "player").forGetter(Conditions::player), EntityPredicate.LOOT_CONTEXT_PREDICATE_CODEC.optionalFieldOf("player").forGetter(Conditions::player),
Codec.STRING.fieldOf("event").forGetter(Conditions::event), Codec.STRING.fieldOf("event").forGetter(Conditions::event),
RacePredicate.CODEC.optionalFieldOf("races", RacePredicate.EMPTY).forGetter(Conditions::races), RacePredicate.CODEC.optionalFieldOf("races", RacePredicate.EMPTY).forGetter(Conditions::races),
CodecUtils.tristateOf("flying").forGetter(Conditions::flying), CodecUtils.tristateOf("flying").forGetter(Conditions::flying),

View file

@ -12,7 +12,6 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.predicate.entity.EntityPredicate; import net.minecraft.predicate.entity.EntityPredicate;
import net.minecraft.predicate.entity.LootContextPredicate; import net.minecraft.predicate.entity.LootContextPredicate;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.dynamic.Codecs;
public class RaceChangeCriterion extends AbstractCriterion<RaceChangeCriterion.Conditions> { public class RaceChangeCriterion extends AbstractCriterion<RaceChangeCriterion.Conditions> {
@Override @Override
@ -31,7 +30,7 @@ public class RaceChangeCriterion extends AbstractCriterion<RaceChangeCriterion.C
Race race Race race
) implements AbstractCriterion.Conditions { ) implements AbstractCriterion.Conditions {
public static final Codec<Conditions> CODEC = RecordCodecBuilder.create(instance -> instance.group( public static final Codec<Conditions> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codecs.createStrictOptionalFieldCodec(EntityPredicate.LOOT_CONTEXT_PREDICATE_CODEC, "player").forGetter(Conditions::player), EntityPredicate.LOOT_CONTEXT_PREDICATE_CODEC.optionalFieldOf("player").forGetter(Conditions::player),
Race.REGISTRY.getCodec().fieldOf("race").forGetter(Conditions::race) Race.REGISTRY.getCodec().fieldOf("race").forGetter(Conditions::race)
).apply(instance, Conditions::new)); ).apply(instance, Conditions::new));

View file

@ -19,7 +19,6 @@ import net.minecraft.predicate.item.ItemPredicate;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.TypeFilter; import net.minecraft.util.TypeFilter;
import net.minecraft.util.dynamic.Codecs;
public class SendViaDragonBreathScrollCriterion extends AbstractCriterion<SendViaDragonBreathScrollCriterion.Conditions> { public class SendViaDragonBreathScrollCriterion extends AbstractCriterion<SendViaDragonBreathScrollCriterion.Conditions> {
@Override @Override
@ -57,7 +56,7 @@ public class SendViaDragonBreathScrollCriterion extends AbstractCriterion<SendVi
RacePredicate races RacePredicate races
) implements AbstractCriterion.Conditions { ) implements AbstractCriterion.Conditions {
public static final Codec<Conditions> CODEC = RecordCodecBuilder.create(instance -> instance.group( public static final Codec<Conditions> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codecs.createStrictOptionalFieldCodec(EntityPredicate.LOOT_CONTEXT_PREDICATE_CODEC, "player").forGetter(Conditions::player), EntityPredicate.LOOT_CONTEXT_PREDICATE_CODEC.optionalFieldOf("player").forGetter(Conditions::player),
ItemPredicate.CODEC.optionalFieldOf("item").forGetter(Conditions::item), ItemPredicate.CODEC.optionalFieldOf("item").forGetter(Conditions::item),
Codec.BOOL.optionalFieldOf("is_receiving_end", false).forGetter(Conditions::isReceivingEnd), Codec.BOOL.optionalFieldOf("is_receiving_end", false).forGetter(Conditions::isReceivingEnd),
Codec.STRING.optionalFieldOf("recipient_name").forGetter(Conditions::recipientName), Codec.STRING.optionalFieldOf("recipient_name").forGetter(Conditions::recipientName),

View file

@ -14,7 +14,6 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.predicate.entity.EntityPredicate; import net.minecraft.predicate.entity.EntityPredicate;
import net.minecraft.predicate.entity.LootContextPredicate; import net.minecraft.predicate.entity.LootContextPredicate;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.dynamic.Codecs;
public class TraitDiscoveredCriterion extends AbstractCriterion<TraitDiscoveredCriterion.Conditions> { public class TraitDiscoveredCriterion extends AbstractCriterion<TraitDiscoveredCriterion.Conditions> {
@Override @Override
@ -34,7 +33,7 @@ public class TraitDiscoveredCriterion extends AbstractCriterion<TraitDiscoveredC
public record Conditions(Optional<LootContextPredicate> player, Set<Trait> traits) implements AbstractCriterion.Conditions { public record Conditions(Optional<LootContextPredicate> player, Set<Trait> traits) implements AbstractCriterion.Conditions {
public static final Codec<Conditions> CODEC = RecordCodecBuilder.create(instance -> instance.group( public static final Codec<Conditions> CODEC = RecordCodecBuilder.create(instance -> instance.group(
Codecs.createStrictOptionalFieldCodec(EntityPredicate.LOOT_CONTEXT_PREDICATE_CODEC, "player").forGetter(Conditions::player), EntityPredicate.LOOT_CONTEXT_PREDICATE_CODEC.optionalFieldOf("player").forGetter(Conditions::player),
Trait.SET_CODEC.fieldOf("traits").forGetter(Conditions::traits) Trait.SET_CODEC.fieldOf("traits").forGetter(Conditions::traits)
).apply(instance, Conditions::new)); ).apply(instance, Conditions::new));

View file

@ -7,7 +7,7 @@ import net.minecraft.block.ButtonBlock;
import net.minecraft.block.LeavesBlock; import net.minecraft.block.LeavesBlock;
import net.minecraft.block.MapColor; import net.minecraft.block.MapColor;
import net.minecraft.block.PillarBlock; import net.minecraft.block.PillarBlock;
import net.minecraft.block.enums.Instrument; import net.minecraft.block.enums.NoteBlockInstrument;
import net.minecraft.block.piston.PistonBehavior; import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.sound.BlockSoundGroup; import net.minecraft.sound.BlockSoundGroup;
@ -29,11 +29,11 @@ public interface BlockConstructionUtils {
} }
static PillarBlock createLogBlock(MapColor topMapColor, MapColor sideMapColor) { static PillarBlock createLogBlock(MapColor topMapColor, MapColor sideMapColor) {
return new PillarBlock(AbstractBlock.Settings.create().mapColor(state -> state.get(PillarBlock.AXIS) == Direction.Axis.Y ? topMapColor : sideMapColor).instrument(Instrument.BASS).strength(2.0f).sounds(BlockSoundGroup.WOOD).burnable()); return new PillarBlock(AbstractBlock.Settings.create().mapColor(state -> state.get(PillarBlock.AXIS) == Direction.Axis.Y ? topMapColor : sideMapColor).instrument(NoteBlockInstrument.BASS).strength(2.0f).sounds(BlockSoundGroup.WOOD).burnable());
} }
static PillarBlock createWoodBlock(MapColor mapColor) { static PillarBlock createWoodBlock(MapColor mapColor) {
return new PillarBlock(AbstractBlock.Settings.create().mapColor(mapColor).instrument(Instrument.BASS).strength(2.0f).sounds(BlockSoundGroup.WOOD).burnable()); return new PillarBlock(AbstractBlock.Settings.create().mapColor(mapColor).instrument(NoteBlockInstrument.BASS).strength(2.0f).sounds(BlockSoundGroup.WOOD).burnable());
} }
static LeavesBlock createLeavesBlock(BlockSoundGroup soundGroup) { static LeavesBlock createLeavesBlock(BlockSoundGroup soundGroup) {

View file

@ -24,13 +24,14 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.state.StateManager; import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties; import net.minecraft.state.property.Properties;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
@ -98,33 +99,32 @@ public class CrystalDoorBlock extends DoorBlock implements BlockEntityProvider {
} }
@Override @Override
public ActionResult onUse(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 (!shouldProvideAccess(world, pos, player)) { if (!shouldProvideAccess(world, pos, player)) {
if (isLocked(world, pos) || !player.getStackInHand(hand).isOf(UItems.MEADOWBROOKS_STAFF)) { if (isLocked(world, pos) || !stack.isOf(UItems.MEADOWBROOKS_STAFF)) {
playOpenCloseSound(player, world, pos, false); playOpenCloseSound(player, world, pos, false);
setOnGuard(state, world, pos, true); setOnGuard(state, world, pos, true);
return ActionResult.CONSUME; return ItemActionResult.CONSUME;
} else { } else {
world.playSound(player, pos, USounds.ENTITY_CRYSTAL_SHARDS_AMBIENT, SoundCategory.BLOCKS, 1, world.getRandom().nextFloat() * 0.1F + 0.9F); world.playSound(player, pos, USounds.ENTITY_CRYSTAL_SHARDS_AMBIENT, SoundCategory.BLOCKS, 1, world.getRandom().nextFloat() * 0.1F + 0.9F);
} }
} else if (!isLocked(world, pos)) { } else if (!isLocked(world, pos)) {
ItemStack heldStack = player.getStackInHand(hand); if (stack.isOf(UItems.FRIENDSHIP_BRACELET)) {
if (heldStack.isOf(UItems.FRIENDSHIP_BRACELET)) {
@Nullable @Nullable
UUID signator = FriendshipBraceletItem.getSignatorId(heldStack); UUID signator = FriendshipBraceletItem.getSignatorId(stack);
if (signator != null) { if (signator != null) {
BlockEntityUtil.getOrCreateBlockEntity(world, state.get(HALF) == DoubleBlockHalf.LOWER ? pos.up() : pos, UBlockEntities.CRYSTAL_DOOR).ifPresent(data -> { BlockEntityUtil.getOrCreateBlockEntity(world, state.get(HALF) == DoubleBlockHalf.LOWER ? pos.up() : pos, UBlockEntities.CRYSTAL_DOOR).ifPresent(data -> {
data.setSignator(signator); data.setSignator(signator);
setOnGuard(state, world, pos, true); setOnGuard(state, world, pos, true);
world.playSound(player, pos, USounds.ENTITY_CRYSTAL_SHARDS_AMBIENT, SoundCategory.BLOCKS, 1, world.getRandom().nextFloat() * 0.1F + 0.9F); world.playSound(player, pos, USounds.ENTITY_CRYSTAL_SHARDS_AMBIENT, SoundCategory.BLOCKS, 1, world.getRandom().nextFloat() * 0.1F + 0.9F);
}); });
return ActionResult.SUCCESS; return ItemActionResult.SUCCESS;
} }
} else { } else {
setOnGuard(state, world, pos, false); setOnGuard(state, world, pos, false);
} }
} }
return super.onUse(state, world, pos, player, hand, hit); return super.onUseWithItem(stack, state, world, pos, player, hand, hit);
} }
private void setOnGuard(BlockState state, World world, BlockPos pos, boolean locked) { private void setOnGuard(BlockState state, World world, BlockPos pos, boolean locked) {
@ -178,12 +178,12 @@ public class CrystalDoorBlock extends DoorBlock implements BlockEntityProvider {
} }
@Override @Override
public void readNbt(NbtCompound nbt) { public void readNbt(NbtCompound nbt, WrapperLookup lookup) {
signator = nbt.containsUuid("signator") ? nbt.getUuid("signator") : null; signator = nbt.containsUuid("signator") ? nbt.getUuid("signator") : null;
} }
@Override @Override
protected void writeNbt(NbtCompound nbt) { protected void writeNbt(NbtCompound nbt, WrapperLookup lookup) {
if (signator != null) { if (signator != null) {
nbt.putUuid("signator", signator); nbt.putUuid("signator", signator);
} }

View file

@ -1,7 +1,5 @@
package com.minelittlepony.unicopia.block; package com.minelittlepony.unicopia.block;
import java.util.List;
import com.minelittlepony.unicopia.ability.EarthPonyGrowAbility.Growable; import com.minelittlepony.unicopia.ability.EarthPonyGrowAbility.Growable;
import com.minelittlepony.unicopia.entity.mob.IgnominiousBulbEntity; import com.minelittlepony.unicopia.entity.mob.IgnominiousBulbEntity;
import com.minelittlepony.unicopia.particle.MagicParticleEffect; import com.minelittlepony.unicopia.particle.MagicParticleEffect;
@ -10,8 +8,9 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.FlowerBlock; import net.minecraft.block.FlowerBlock;
import net.minecraft.block.SuspiciousStewIngredient; import net.minecraft.component.type.SuspiciousStewEffectsComponent;
import net.minecraft.client.util.ParticleUtil; import net.minecraft.particle.ParticleUtil;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.entity.Dismounting; import net.minecraft.entity.Dismounting;
import net.minecraft.entity.effect.StatusEffect; import net.minecraft.entity.effect.StatusEffect;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -24,11 +23,11 @@ public class CuringJokeBlock extends FlowerBlock implements Growable {
FlowerBlock.createSettingsCodec() FlowerBlock.createSettingsCodec()
).apply(instance, CuringJokeBlock::new)); ).apply(instance, CuringJokeBlock::new));
public CuringJokeBlock(StatusEffect suspiciousStewEffect, int effectDuration, Settings settings) { public CuringJokeBlock(RegistryEntry<StatusEffect> suspiciousStewEffect, int effectDuration, Settings settings) {
super(suspiciousStewEffect, effectDuration, settings); super(suspiciousStewEffect, effectDuration, settings);
} }
protected CuringJokeBlock(List<SuspiciousStewIngredient.StewEffect> effects, Settings settings) { protected CuringJokeBlock(SuspiciousStewEffectsComponent effects, Settings settings) {
super(effects, settings); super(effects, settings);
} }

View file

@ -17,6 +17,7 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks; import net.minecraft.block.Blocks;
import net.minecraft.block.HayBlock; import net.minecraft.block.HayBlock;
import net.minecraft.block.ShapeContext; import net.minecraft.block.ShapeContext;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
@ -27,6 +28,7 @@ import net.minecraft.state.property.BooleanProperty;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.Util; import net.minecraft.util.Util;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -94,10 +96,18 @@ public class EdibleBlock extends HayBlock {
for (EdibleBlock edibleBlock : REGISTRY) { for (EdibleBlock edibleBlock : REGISTRY) {
Block match = edibleBlock.getBaseBlock(); Block match = edibleBlock.getBaseBlock();
if (match != Blocks.AIR && state.isOf(match)) { if (match != Blocks.AIR && state.isOf(match)) {
ActionResult result = StateUtil.copyState(state, edibleBlock.getDefaultState()).onUse(world, player, hand, hitResult); BlockState copiedState = StateUtil.copyState(state, edibleBlock.getDefaultState());
ItemActionResult result = copiedState.onUseWithItem(player.getStackInHand(hand), world, player, hand, hitResult);
if (result.isAccepted()) { if (result.isAccepted()) {
return result; return result.toActionResult();
}
if (result == ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION && hand == Hand.MAIN_HAND) {
ActionResult actionResult = copiedState.onUse(world, player, hitResult);
if (actionResult.isAccepted()) {
return actionResult;
}
} }
} }
} }
@ -144,13 +154,11 @@ public class EdibleBlock extends HayBlock {
@Override @Override
@Deprecated @Deprecated
public ActionResult onUse(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 (player.isSpectator()) { if (player.isSpectator()) {
return ActionResult.FAIL; return ItemActionResult.FAIL;
} }
ItemStack stack = player.getStackInHand(hand);
if (!stack.isEmpty() && stack.isOf(Registries.ITEM.get(material))) { if (!stack.isEmpty() && stack.isOf(Registries.ITEM.get(material))) {
BooleanProperty segment = getHitCorner(hit, 1); BooleanProperty segment = getHitCorner(hit, 1);
@ -167,23 +175,23 @@ public class EdibleBlock extends HayBlock {
} }
world.playSound(player, pos, getSoundGroup(state).getPlaceSound(), SoundCategory.BLOCKS); world.playSound(player, pos, getSoundGroup(state).getPlaceSound(), SoundCategory.BLOCKS);
return ActionResult.SUCCESS; return ItemActionResult.SUCCESS;
} }
return ActionResult.FAIL; return ItemActionResult.FAIL;
} }
BooleanProperty corner = getHitCorner(hit, -1); BooleanProperty corner = getHitCorner(hit, -1);
if (!state.get(corner)) { if (!state.get(corner)) {
return ActionResult.PASS; return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
} }
boolean usingHoe = stack.isIn(ItemTags.HOES); boolean usingHoe = stack.isIn(ItemTags.HOES);
if (!usingHoe) { if (!usingHoe) {
if (!(player.isCreative() || player.getHungerManager().isNotFull()) || !player.isSneaking()) { if (!(player.isCreative() || player.getHungerManager().isNotFull()) || !player.isSneaking()) {
return ActionResult.FAIL; return ItemActionResult.FAIL;
} }
} }
@ -197,7 +205,7 @@ public class EdibleBlock extends HayBlock {
} }
if (usingHoe) { if (usingHoe) {
stack.damage(1, player, p -> p.sendToolBreakStatus(hand)); stack.damage(1, player, LivingEntity.getSlotForHand(hand));
dropStack(world, pos, Registries.ITEM.get(material).getDefaultStack()); dropStack(world, pos, Registries.ITEM.get(material).getDefaultStack());
player.playSound(USounds.Vanilla.ITEM_HOE_TILL, 1, 1); player.playSound(USounds.Vanilla.ITEM_HOE_TILL, 1, 1);
} else { } else {
@ -207,7 +215,7 @@ public class EdibleBlock extends HayBlock {
} }
player.getHungerManager().add(2, 1.3F); player.getHungerManager().add(2, 1.3F);
} }
return ActionResult.SUCCESS; return ItemActionResult.SUCCESS;
} }
static BooleanProperty getHitCorner(BlockHitResult hit, int direction) { static BooleanProperty getHitCorner(BlockHitResult hit, int direction) {

View file

@ -24,6 +24,7 @@ import net.minecraft.entity.mob.PiglinBrain;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NbtCompound; import net.minecraft.nbt.NbtCompound;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.registry.tag.BlockTags; import net.minecraft.registry.tag.BlockTags;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.DyeColor; import net.minecraft.util.DyeColor;
@ -150,18 +151,18 @@ public class FancyBedBlock extends BedBlock {
} }
@Override @Override
public void readNbt(NbtCompound nbt) { public void readNbt(NbtCompound nbt, WrapperLookup lookup) {
pattern = SheetPattern.byId(nbt.getString("pattern")); pattern = SheetPattern.byId(nbt.getString("pattern"));
} }
@Override @Override
protected void writeNbt(NbtCompound nbt) { protected void writeNbt(NbtCompound nbt, WrapperLookup lookup) {
nbt.putString("pattern", pattern.asString()); nbt.putString("pattern", pattern.asString());
} }
@Override @Override
public NbtCompound toInitialChunkDataNbt() { public NbtCompound toInitialChunkDataNbt(WrapperLookup lookup) {
return createNbt(); return createNbt(lookup);
} }
public String getBase() { public String getBase() {

View file

@ -34,13 +34,14 @@ 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.NbtElement;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.registry.entry.RegistryEntry;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.state.StateManager; import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Property; import net.minecraft.state.property.Property;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
@ -142,7 +143,7 @@ public class HiveBlock extends ConnectingBlock implements BlockEntityProvider {
} }
@Override @Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) {
if (EquineContext.of(player).getCompositeRace().includes(Race.CHANGELING)) { if (EquineContext.of(player).getCompositeRace().includes(Race.CHANGELING)) {
world.setBlockState(pos, state.with(CONSUMING, true)); world.setBlockState(pos, state.with(CONSUMING, true));
if (!world.isClient) { if (!world.isClient) {
@ -214,22 +215,22 @@ public class HiveBlock extends ConnectingBlock implements BlockEntityProvider {
} }
@Override @Override
public void readNbt(NbtCompound nbt) { 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)) { if (nbt.contains("storedBlocks", NbtElement.LIST_TYPE)) {
Entry.SERIALIZER.readAll(nbt.getList("storedBlocks", NbtElement.COMPOUND_TYPE)).forEach(entry -> { Entry.SERIALIZER.readAll(nbt.getList("storedBlocks", NbtElement.COMPOUND_TYPE), lookup).forEach(entry -> {
storedBlocks.put(entry.pos(), entry); storedBlocks.put(entry.pos(), entry);
}); });
} }
} }
@Override @Override
protected void writeNbt(NbtCompound nbt) { 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())); nbt.put("storedBlocks", Entry.SERIALIZER.writeAll(storedBlocks.values(), lookup));
} }
static void tick(World world, BlockPos pos, BlockState state, TileData data) { static void tick(World world, BlockPos pos, BlockState state, TileData data) {
@ -312,22 +313,23 @@ public class HiveBlock extends ConnectingBlock implements BlockEntityProvider {
} }
record Entry (BlockPos pos, BlockState state, @Nullable BlockEntity data) { record Entry (BlockPos pos, BlockState state, @Nullable BlockEntity data) {
public static final Serializer<Entry> SERIALIZER = Serializer.of(compound -> new Entry( public static final Serializer<NbtCompound, Entry> SERIALIZER = Serializer.of((compound, lookup) -> new Entry(
NbtSerialisable.BLOCK_POS.read(compound.getCompound("pos")), NbtSerialisable.BLOCK_POS.read(compound.getCompound("pos"), lookup),
NbtSerialisable.decode(BlockState.CODEC, compound.get("state")).orElse(Blocks.AIR.getDefaultState()), NbtSerialisable.decode(BlockState.CODEC, compound.get("state")).orElse(Blocks.AIR.getDefaultState()),
compound.getCompound("data") compound.getCompound("data"),
), entry -> { lookup
), (entry, lookup) -> {
NbtCompound compound = new NbtCompound(); NbtCompound compound = new NbtCompound();
compound.put("pos", NbtSerialisable.BLOCK_POS.write(entry.pos())); compound.put("pos", NbtSerialisable.BLOCK_POS.write(entry.pos(), lookup));
compound.put("state", NbtSerialisable.encode(BlockState.CODEC, entry.state())); compound.put("state", NbtSerialisable.encode(BlockState.CODEC, entry.state()));
if (entry.data() != null) { if (entry.data() != null) {
compound.put("data", entry.data().createNbtWithId()); compound.put("data", entry.data().createNbtWithId(lookup));
} }
return compound; return compound;
}); });
Entry(BlockPos pos, BlockState state, NbtCompound nbt) { Entry(BlockPos pos, BlockState state, NbtCompound nbt, WrapperLookup lookup) {
this(pos, state, BlockEntity.createFromNbt(pos, state, nbt)); this(pos, state, BlockEntity.createFromNbt(pos, state, nbt, lookup));
} }
@SuppressWarnings("deprecation") @SuppressWarnings("deprecation")
@ -365,7 +367,7 @@ public class HiveBlock extends ConnectingBlock implements BlockEntityProvider {
} }
@Override @Override
public boolean listen(ServerWorld world, GameEvent event, Emitter emitter, Vec3d emitterPos) { public boolean listen(ServerWorld world, RegistryEntry<GameEvent> event, Emitter emitter, Vec3d emitterPos) {
if (isImportant(event) || (EquinePredicates.IS_PLAYER.test(emitter.sourceEntity()) && !EquinePredicates.CHANGELING.test(emitter.sourceEntity()))) { if (isImportant(event) || (EquinePredicates.IS_PLAYER.test(emitter.sourceEntity()) && !EquinePredicates.CHANGELING.test(emitter.sourceEntity()))) {
closing = true; closing = true;
markDirty(); markDirty();
@ -374,7 +376,7 @@ public class HiveBlock extends ConnectingBlock implements BlockEntityProvider {
return false; return false;
} }
private boolean isImportant(GameEvent event) { private boolean isImportant(RegistryEntry<GameEvent> event) {
return event == GameEvent.EXPLODE return event == GameEvent.EXPLODE
|| event == GameEvent.PRIME_FUSE || event == GameEvent.PRIME_FUSE
|| event == GameEvent.SHRIEK; || event == GameEvent.SHRIEK;

View file

@ -25,9 +25,11 @@ import net.minecraft.nbt.NbtElement;
import net.minecraft.network.listener.ClientPlayPacketListener; import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.TypedActionResult; import net.minecraft.util.TypedActionResult;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -52,11 +54,11 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven
} }
@Override @Override
public ActionResult onUse(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) {
if (hand == Hand.OFF_HAND) { if (hand == Hand.OFF_HAND) {
return ActionResult.PASS; return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
} }
return world.getBlockEntity(pos, UBlockEntities.ITEM_JAR).map(data -> data.interact(player, hand)).orElse(ActionResult.PASS); return world.getBlockEntity(pos, UBlockEntities.ITEM_JAR).map(data -> data.interact(player, hand)).orElse(ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION);
} }
@Deprecated @Deprecated
@ -110,10 +112,10 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven
super(UBlockEntities.ITEM_JAR, pos, state); super(UBlockEntities.ITEM_JAR, pos, state);
} }
public ActionResult interact(PlayerEntity player, Hand hand) { public ItemActionResult interact(PlayerEntity player, Hand hand) {
TypedActionResult<JarContents> result = contents.interact(player, hand); TypedActionResult<JarContents> result = contents.interact(player, hand);
contents = result.getValue(); contents = result.getValue();
return result.getResult(); return result.getResult().isAccepted() ? ItemActionResult.SUCCESS : result.getResult() == ActionResult.FAIL ? ItemActionResult.FAIL : ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
} }
public JarContents getContents() { public JarContents getContents() {
@ -146,8 +148,8 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven
} }
@Override @Override
public NbtCompound toInitialChunkDataNbt() { public NbtCompound toInitialChunkDataNbt(WrapperLookup lookup) {
return createNbt(); return createNbt(lookup);
} }
@Override @Override
@ -159,9 +161,9 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven
} }
@Override @Override
public void readNbt(NbtCompound nbt) { public void readNbt(NbtCompound nbt, WrapperLookup lookup) {
if (nbt.contains("items", NbtElement.COMPOUND_TYPE)) { if (nbt.contains("items", NbtElement.COMPOUND_TYPE)) {
contents = new ItemsJarContents(this, nbt.getCompound("items")); contents = new ItemsJarContents(this, nbt.getCompound("items"), lookup);
} 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)) {
@ -172,14 +174,14 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven
} }
@Override @Override
protected void writeNbt(NbtCompound nbt) { protected void writeNbt(NbtCompound nbt, WrapperLookup lookup) {
var items = getItems(); var items = getItems();
if (items != null) { if (items != null) {
nbt.put("items", items.toNBT(new NbtCompound())); nbt.put("items", items.toNBT(new NbtCompound(), lookup));
} else if (getEntity() != null) { } else if (getEntity() != null) {
nbt.put("entity", getEntity().toNBT(new NbtCompound())); nbt.put("entity", getEntity().toNBT(new NbtCompound(), lookup));
} else if (getFluid() != null) { } else if (getFluid() != null) {
nbt.put("fluid", getFluid().toNBT(new NbtCompound())); nbt.put("fluid", getFluid().toNBT(new NbtCompound(), lookup));
} else if (getFakeFluid() != null) { } else if (getFakeFluid() != null) {
nbt.put("fakeFluid", getFakeFluid().toNBT(new NbtCompound())); nbt.put("fakeFluid", getFakeFluid().toNBT(new NbtCompound()));
} }
@ -191,7 +193,7 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven
void onDestroyed(); void onDestroyed();
NbtCompound toNBT(NbtCompound compound); NbtCompound toNBT(NbtCompound compound, WrapperLookup lookup);
default void consumeAndSwap(PlayerEntity player, Hand hand, ItemStack output) { default void consumeAndSwap(PlayerEntity player, Hand hand, ItemStack output) {
player.setStackInHand(hand, ItemUsage.exchangeStack(player.getStackInHand(hand), player, output.copy())); player.setStackInHand(hand, ItemUsage.exchangeStack(player.getStackInHand(hand), player, output.copy()));

View file

@ -20,8 +20,8 @@ import net.minecraft.sound.SoundCategory;
import net.minecraft.stat.Stats; import net.minecraft.stat.Stats;
import net.minecraft.state.StateManager; import net.minecraft.state.StateManager;
import net.minecraft.state.property.*; import net.minecraft.state.property.*;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.*; import net.minecraft.util.math.*;
import net.minecraft.util.math.random.Random; import net.minecraft.util.math.random.Random;
@ -80,39 +80,38 @@ public class PieBlock extends Block implements Waterloggable {
@Deprecated @Deprecated
@Override @Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { public ItemActionResult onUseWithItem(ItemStack itemStack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
ItemStack itemStack = player.getStackInHand(hand);
if (world.isClient) { if (world.isClient) {
if (itemStack.isIn(UTags.Items.CAN_CUT_PIE)) { if (itemStack.isIn(UTags.Items.CAN_CUT_PIE)) {
return ActionResult.SUCCESS; return ItemActionResult.SUCCESS;
} }
if (tryEat(world, pos, state, player).isAccepted()) { if (tryEat(world, pos, state, player).isAccepted()) {
return ActionResult.SUCCESS; return ItemActionResult.SUCCESS;
} }
if (itemStack.isEmpty()) { if (itemStack.isEmpty()) {
return ActionResult.CONSUME; return ItemActionResult.CONSUME;
} }
} }
if (itemStack.isIn(UTags.Items.CAN_CUT_PIE)) { if (itemStack.isIn(UTags.Items.CAN_CUT_PIE)) {
SoundEmitter.playSoundAt(player, USounds.BLOCK_PIE_SLICE, SoundCategory.NEUTRAL, 1, 1); SoundEmitter.playSoundAt(player, USounds.BLOCK_PIE_SLICE, SoundCategory.NEUTRAL, 1, 1);
removeSlice(world, pos, state, player); removeSlice(world, pos, state, player);
itemStack.damage(1, player, p -> p.sendToolBreakStatus(hand)); itemStack.damage(1, player, LivingEntity.getSlotForHand(hand));
SoundEmitter.playSoundAt(player, USounds.BLOCK_PIE_SLICE_POP, SoundCategory.NEUTRAL, 0.5F, world.getRandom().nextFloat() * 0.1F + 0.9F); SoundEmitter.playSoundAt(player, USounds.BLOCK_PIE_SLICE_POP, SoundCategory.NEUTRAL, 0.5F, world.getRandom().nextFloat() * 0.1F + 0.9F);
Block.dropStack(world, pos, sliceItem.asItem().getDefaultStack()); Block.dropStack(world, pos, sliceItem.asItem().getDefaultStack());
return ActionResult.SUCCESS; return ItemActionResult.SUCCESS;
} }
return tryEat(world, pos, state, player); return tryEat(world, pos, state, player);
} }
protected ActionResult tryEat(WorldAccess world, BlockPos pos, BlockState state, PlayerEntity player) { protected ItemActionResult tryEat(WorldAccess world, BlockPos pos, BlockState state, PlayerEntity player) {
if (!player.canConsume(false)) { if (!player.canConsume(false)) {
return ActionResult.PASS; return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
} }
player.incrementStat(Stats.EAT_CAKE_SLICE); player.incrementStat(Stats.EAT_CAKE_SLICE);
player.getHungerManager().add(state.get(STOMPED) ? 1 : 2, 0.1f); player.getHungerManager().add(state.get(STOMPED) ? 1 : 2, 0.1f);
@ -126,7 +125,7 @@ public class PieBlock extends Block implements Waterloggable {
} }
removeSlice(world, pos, state, player); removeSlice(world, pos, state, player);
return ActionResult.SUCCESS; return ItemActionResult.SUCCESS;
} }
protected void removeSlice(WorldAccess world, BlockPos pos, BlockState state, PlayerEntity player) { protected void removeSlice(WorldAccess world, BlockPos pos, BlockState state, PlayerEntity player) {
@ -232,7 +231,7 @@ public class PieBlock extends Block implements Waterloggable {
} }
@Override @Override
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { public boolean canPathfindThrough(BlockState state, NavigationType type) {
return false; return false;
} }
} }

View file

@ -17,7 +17,6 @@ import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Box; import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction; import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldAccess; import net.minecraft.world.WorldAccess;
import net.minecraft.world.WorldView; import net.minecraft.world.WorldView;
@ -95,7 +94,7 @@ public class SpikesBlock extends OrientedBlock {
} }
@Override @Override
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { public boolean canPathfindThrough(BlockState state, NavigationType type) {
return false; return false;
} }
} }

View file

@ -35,7 +35,6 @@ import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.item.cloud.CloudBlockItem; import com.minelittlepony.unicopia.item.cloud.CloudBlockItem;
import com.minelittlepony.unicopia.item.group.ItemGroupRegistry; import com.minelittlepony.unicopia.item.group.ItemGroupRegistry;
import com.minelittlepony.unicopia.server.world.UTreeGen; import com.minelittlepony.unicopia.server.world.UTreeGen;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.fabricmc.fabric.api.registry.CompostingChanceRegistry; import net.fabricmc.fabric.api.registry.CompostingChanceRegistry;
import net.fabricmc.fabric.api.registry.FlammableBlockRegistry; import net.fabricmc.fabric.api.registry.FlammableBlockRegistry;
import net.fabricmc.fabric.api.registry.OxidizableBlocksRegistry; import net.fabricmc.fabric.api.registry.OxidizableBlocksRegistry;
@ -44,7 +43,7 @@ import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.block.*; import net.minecraft.block.*;
import net.minecraft.block.AbstractBlock.Settings; import net.minecraft.block.AbstractBlock.Settings;
import net.minecraft.block.entity.BlockEntityType; import net.minecraft.block.entity.BlockEntityType;
import net.minecraft.block.enums.Instrument; import net.minecraft.block.enums.NoteBlockInstrument;
import net.minecraft.block.piston.PistonBehavior; import net.minecraft.block.piston.PistonBehavior;
import net.minecraft.item.*; import net.minecraft.item.*;
import net.minecraft.sound.BlockSoundGroup; import net.minecraft.sound.BlockSoundGroup;
@ -69,7 +68,7 @@ public interface UBlocks {
.strength(2) .strength(2)
.sounds(BlockSoundGroup.STONE))); .sounds(BlockSoundGroup.STONE)));
Block FROSTED_OBSIDIAN = register("frosted_obsidian", new FrostedObsidianBlock(FabricBlockSettings.copy(Blocks.OBSIDIAN).ticksRandomly())); Block FROSTED_OBSIDIAN = register("frosted_obsidian", new FrostedObsidianBlock(Block.Settings.copy(Blocks.OBSIDIAN).ticksRandomly()));
Block ZAP_LOG = register("zap_log", new ZapAppleLogBlock(Blocks.OAK_LOG.getDefaultState(), ZapAppleLogBlock.settings(MapColor.GRAY, MapColor.DEEPSLATE_GRAY)), ItemGroups.BUILDING_BLOCKS); Block ZAP_LOG = register("zap_log", new ZapAppleLogBlock(Blocks.OAK_LOG.getDefaultState(), ZapAppleLogBlock.settings(MapColor.GRAY, MapColor.DEEPSLATE_GRAY)), ItemGroups.BUILDING_BLOCKS);
Block ZAP_WOOD = register("zap_wood", new ZapAppleLogBlock(Blocks.OAK_WOOD.getDefaultState(), ZapAppleLogBlock.settings(MapColor.DEEPSLATE_GRAY, MapColor.DEEPSLATE_GRAY)), ItemGroups.BUILDING_BLOCKS); Block ZAP_WOOD = register("zap_wood", new ZapAppleLogBlock(Blocks.OAK_WOOD.getDefaultState(), ZapAppleLogBlock.settings(MapColor.DEEPSLATE_GRAY, MapColor.DEEPSLATE_GRAY)), ItemGroups.BUILDING_BLOCKS);
@ -110,14 +109,14 @@ public interface UBlocks {
Block PALM_SLAB = register("palm_slab", new SlabBlock(Settings.create().mapColor(PALM_PLANKS.getDefaultMapColor()).strength(2, 3).sounds(BlockSoundGroup.WOOD).pistonBehavior(PistonBehavior.NORMAL)), ItemGroups.BUILDING_BLOCKS); Block PALM_SLAB = register("palm_slab", new SlabBlock(Settings.create().mapColor(PALM_PLANKS.getDefaultMapColor()).strength(2, 3).sounds(BlockSoundGroup.WOOD).pistonBehavior(PistonBehavior.NORMAL)), ItemGroups.BUILDING_BLOCKS);
Block PALM_FENCE = register("palm_fence", new FenceBlock(Settings.create().mapColor(PALM_PLANKS.getDefaultMapColor()).strength(2, 3).sounds(BlockSoundGroup.WOOD).pistonBehavior(PistonBehavior.NORMAL)), ItemGroups.BUILDING_BLOCKS); Block PALM_FENCE = register("palm_fence", new FenceBlock(Settings.create().mapColor(PALM_PLANKS.getDefaultMapColor()).strength(2, 3).sounds(BlockSoundGroup.WOOD).pistonBehavior(PistonBehavior.NORMAL)), ItemGroups.BUILDING_BLOCKS);
Block PALM_FENCE_GATE = register("palm_fence_gate", new FenceGateBlock(UWoodTypes.PALM, Settings.create().mapColor(PALM_PLANKS.getDefaultMapColor()).strength(2, 3).sounds(BlockSoundGroup.WOOD).pistonBehavior(PistonBehavior.NORMAL)), ItemGroups.BUILDING_BLOCKS); Block PALM_FENCE_GATE = register("palm_fence_gate", new FenceGateBlock(UWoodTypes.PALM, Settings.create().mapColor(PALM_PLANKS.getDefaultMapColor()).strength(2, 3).sounds(BlockSoundGroup.WOOD).pistonBehavior(PistonBehavior.NORMAL)), ItemGroups.BUILDING_BLOCKS);
Block PALM_DOOR = register("palm_door", new DoorBlock(UWoodTypes.PALM.setType(), Settings.create().mapColor(PALM_PLANKS.getDefaultMapColor()).instrument(Instrument.BASS).strength(3.0f).nonOpaque().burnable().pistonBehavior(PistonBehavior.DESTROY)), ItemGroups.FUNCTIONAL); Block PALM_DOOR = register("palm_door", new DoorBlock(UWoodTypes.PALM.setType(), Settings.create().mapColor(PALM_PLANKS.getDefaultMapColor()).instrument(NoteBlockInstrument.BASS).strength(3.0f).nonOpaque().burnable().pistonBehavior(PistonBehavior.DESTROY)), ItemGroups.FUNCTIONAL);
Block PALM_TRAPDOOR = register("palm_trapdoor", new TrapdoorBlock(UWoodTypes.PALM.setType(), Settings.create().mapColor(PALM_PLANKS.getDefaultMapColor()).instrument(Instrument.BASS).strength(3).nonOpaque().allowsSpawning(BlockConstructionUtils::never).burnable()), ItemGroups.FUNCTIONAL); Block PALM_TRAPDOOR = register("palm_trapdoor", new TrapdoorBlock(UWoodTypes.PALM.setType(), Settings.create().mapColor(PALM_PLANKS.getDefaultMapColor()).instrument(NoteBlockInstrument.BASS).strength(3).nonOpaque().allowsSpawning(BlockConstructionUtils::never).burnable()), ItemGroups.FUNCTIONAL);
Block PALM_PRESSURE_PLATE = register("palm_pressure_plate", new PressurePlateBlock(UWoodTypes.PALM.setType(), Settings.create().mapColor(PALM_PLANKS.getDefaultMapColor()).noCollision().strength(0.5f).sounds(BlockSoundGroup.WOOD).pistonBehavior(PistonBehavior.DESTROY)), ItemGroups.BUILDING_BLOCKS); Block PALM_PRESSURE_PLATE = register("palm_pressure_plate", new PressurePlateBlock(UWoodTypes.PALM.setType(), Settings.create().mapColor(PALM_PLANKS.getDefaultMapColor()).noCollision().strength(0.5f).sounds(BlockSoundGroup.WOOD).pistonBehavior(PistonBehavior.DESTROY)), ItemGroups.BUILDING_BLOCKS);
Block PALM_BUTTON = register("palm_button", BlockConstructionUtils.woodenButton(UWoodTypes.PALM.setType()), ItemGroups.BUILDING_BLOCKS); Block PALM_BUTTON = register("palm_button", BlockConstructionUtils.woodenButton(UWoodTypes.PALM.setType()), ItemGroups.BUILDING_BLOCKS);
Block PALM_SIGN = register("palm_sign", new SignBlock(UWoodTypes.PALM, Settings.create().mapColor(PALM_PLANKS.getDefaultMapColor()).solid().instrument(Instrument.BASS).noCollision().strength(1).burnable().sounds(BlockSoundGroup.WOOD))); Block PALM_SIGN = register("palm_sign", new SignBlock(UWoodTypes.PALM, Settings.create().mapColor(PALM_PLANKS.getDefaultMapColor()).solid().instrument(NoteBlockInstrument.BASS).noCollision().strength(1).burnable().sounds(BlockSoundGroup.WOOD)));
Block PALM_WALL_SIGN = register("palm_wall_sign", new WallSignBlock(UWoodTypes.PALM, Settings.create().mapColor(PALM_PLANKS.getDefaultMapColor()).solid().instrument(Instrument.BASS).noCollision().strength(1).dropsLike(PALM_SIGN).burnable())); Block PALM_WALL_SIGN = register("palm_wall_sign", new WallSignBlock(UWoodTypes.PALM, Settings.create().mapColor(PALM_PLANKS.getDefaultMapColor()).solid().instrument(NoteBlockInstrument.BASS).noCollision().strength(1).dropsLike(PALM_SIGN).burnable()));
Block PALM_HANGING_SIGN = register("palm_hanging_sign", new HangingSignBlock(UWoodTypes.PALM, Settings.create().mapColor(PALM_LOG.getDefaultMapColor()).solid().instrument(Instrument.BASS).noCollision().strength(1).burnable())); Block PALM_HANGING_SIGN = register("palm_hanging_sign", new HangingSignBlock(UWoodTypes.PALM, Settings.create().mapColor(PALM_LOG.getDefaultMapColor()).solid().instrument(NoteBlockInstrument.BASS).noCollision().strength(1).burnable()));
Block PALM_WALL_HANGING_SIGN = register("palm_wall_hanging_sign", new WallHangingSignBlock(UWoodTypes.PALM, Settings.create().mapColor(PALM_LOG.getDefaultMapColor()).solid().instrument(Instrument.BASS).noCollision().strength(1.0f).burnable().dropsLike(PALM_HANGING_SIGN))); Block PALM_WALL_HANGING_SIGN = register("palm_wall_hanging_sign", new WallHangingSignBlock(UWoodTypes.PALM, Settings.create().mapColor(PALM_LOG.getDefaultMapColor()).solid().instrument(NoteBlockInstrument.BASS).noCollision().strength(1.0f).burnable().dropsLike(PALM_HANGING_SIGN)));
Block PALM_LEAVES = register("palm_leaves", BlockConstructionUtils.createLeavesBlock(BlockSoundGroup.GRASS), ItemGroups.BUILDING_BLOCKS); Block PALM_LEAVES = register("palm_leaves", BlockConstructionUtils.createLeavesBlock(BlockSoundGroup.GRASS), ItemGroups.BUILDING_BLOCKS);
Block BANANAS = register("bananas", new FruitBlock(Direction.DOWN, PALM_LEAVES, VoxelShapes.fullCube(), Settings.create().mapColor(MapColor.YELLOW).sounds(BlockSoundGroup.WOOD).noCollision().ticksRandomly().breakInstantly().pistonBehavior(PistonBehavior.DESTROY))); Block BANANAS = register("bananas", new FruitBlock(Direction.DOWN, PALM_LEAVES, VoxelShapes.fullCube(), Settings.create().mapColor(MapColor.YELLOW).sounds(BlockSoundGroup.WOOD).noCollision().ticksRandomly().breakInstantly().pistonBehavior(PistonBehavior.DESTROY)));
@ -128,7 +127,7 @@ public interface UBlocks {
0xCCFFAA00, 0xCCFFAA00,
() -> UBlocks.MANGO, () -> UBlocks.MANGO,
() -> UItems.MANGO.getDefaultStack(), () -> UItems.MANGO.getDefaultStack(),
FabricBlockSettings.copy(Blocks.JUNGLE_LEAVES) Block.Settings.copy(Blocks.JUNGLE_LEAVES)
), ItemGroups.NATURAL); ), ItemGroups.NATURAL);
Block MANGO = register("mango", new FruitBlock(Direction.DOWN, MANGO_LEAVES, FruitBlock.DEFAULT_SHAPE, Settings.create().mapColor(MapColor.ORANGE))); Block MANGO = register("mango", new FruitBlock(Direction.DOWN, MANGO_LEAVES, FruitBlock.DEFAULT_SHAPE, Settings.create().mapColor(MapColor.ORANGE)));
@ -138,7 +137,7 @@ public interface UBlocks {
0xE5FFFF88, 0xE5FFFF88,
() -> UBlocks.GREEN_APPLE, () -> UBlocks.GREEN_APPLE,
() -> UItems.GREEN_APPLE.getDefaultStack(), () -> UItems.GREEN_APPLE.getDefaultStack(),
FabricBlockSettings.copy(Blocks.OAK_LEAVES) Block.Settings.copy(Blocks.OAK_LEAVES)
), ItemGroups.NATURAL); ), ItemGroups.NATURAL);
Block GREEN_APPLE = register("green_apple", new FruitBlock(Direction.DOWN, GREEN_APPLE_LEAVES, FruitBlock.DEFAULT_SHAPE, Settings.create().mapColor(MapColor.GREEN))); Block GREEN_APPLE = register("green_apple", new FruitBlock(Direction.DOWN, GREEN_APPLE_LEAVES, FruitBlock.DEFAULT_SHAPE, Settings.create().mapColor(MapColor.GREEN)));
Block GREEN_APPLE_SPROUT = register("green_apple_sprout", new SproutBlock(0xE5FFFF88, () -> UItems.GREEN_APPLE_SEEDS, () -> UTreeGen.GREEN_APPLE_TREE.sapling().map(Block::getDefaultState).get(), SproutBlock.settings())); Block GREEN_APPLE_SPROUT = register("green_apple_sprout", new SproutBlock(0xE5FFFF88, () -> UItems.GREEN_APPLE_SEEDS, () -> UTreeGen.GREEN_APPLE_TREE.sapling().map(Block::getDefaultState).get(), SproutBlock.settings()));
@ -147,7 +146,7 @@ public interface UBlocks {
0xE5FFCC88, 0xE5FFCC88,
() -> UBlocks.SWEET_APPLE, () -> UBlocks.SWEET_APPLE,
() -> UItems.SWEET_APPLE.getDefaultStack(), () -> UItems.SWEET_APPLE.getDefaultStack(),
FabricBlockSettings.copy(Blocks.OAK_LEAVES) Block.Settings.copy(Blocks.OAK_LEAVES)
), ItemGroups.NATURAL); ), ItemGroups.NATURAL);
Block SWEET_APPLE = register("sweet_apple", new FruitBlock(Direction.DOWN, SWEET_APPLE_LEAVES, FruitBlock.DEFAULT_SHAPE, Settings.create().mapColor(MapColor.GREEN))); Block SWEET_APPLE = register("sweet_apple", new FruitBlock(Direction.DOWN, SWEET_APPLE_LEAVES, FruitBlock.DEFAULT_SHAPE, Settings.create().mapColor(MapColor.GREEN)));
Block SWEET_APPLE_SPROUT = register("sweet_apple_sprout", new SproutBlock(0xE5FFCC88, () -> UItems.SWEET_APPLE_SEEDS, () -> UTreeGen.SWEET_APPLE_TREE.sapling().map(Block::getDefaultState).get(), SproutBlock.settings())); Block SWEET_APPLE_SPROUT = register("sweet_apple_sprout", new SproutBlock(0xE5FFCC88, () -> UItems.SWEET_APPLE_SEEDS, () -> UTreeGen.SWEET_APPLE_TREE.sapling().map(Block::getDefaultState).get(), SproutBlock.settings()));
@ -156,7 +155,7 @@ public interface UBlocks {
0xE5FFCCCC, 0xE5FFCCCC,
() -> UBlocks.SOUR_APPLE, () -> UBlocks.SOUR_APPLE,
() -> UItems.SOUR_APPLE.getDefaultStack(), () -> UItems.SOUR_APPLE.getDefaultStack(),
FabricBlockSettings.copy(Blocks.OAK_LEAVES) Block.Settings.copy(Blocks.OAK_LEAVES)
), ItemGroups.NATURAL); ), ItemGroups.NATURAL);
Block SOUR_APPLE = register("sour_apple", new FruitBlock(Direction.DOWN, SOUR_APPLE_LEAVES, FruitBlock.DEFAULT_SHAPE, Settings.create().mapColor(MapColor.GREEN))); Block SOUR_APPLE = register("sour_apple", new FruitBlock(Direction.DOWN, SOUR_APPLE_LEAVES, FruitBlock.DEFAULT_SHAPE, Settings.create().mapColor(MapColor.GREEN)));
Block SOUR_APPLE_SPROUT = register("sour_apple_sprout", new SproutBlock(0xE5FFCC88, () -> UItems.SOUR_APPLE_SEEDS, () -> UTreeGen.SOUR_APPLE_TREE.sapling().map(Block::getDefaultState).get(), SproutBlock.settings())); Block SOUR_APPLE_SPROUT = register("sour_apple_sprout", new SproutBlock(0xE5FFCC88, () -> UItems.SOUR_APPLE_SEEDS, () -> UTreeGen.SOUR_APPLE_TREE.sapling().map(Block::getDefaultState).get(), SproutBlock.settings()));
@ -171,7 +170,7 @@ public interface UBlocks {
MapColor.GOLD.color, MapColor.GOLD.color,
() -> UBlocks.GOLDEN_APPLE, () -> UBlocks.GOLDEN_APPLE,
() -> Items.GOLDEN_APPLE.getDefaultStack(), () -> Items.GOLDEN_APPLE.getDefaultStack(),
FabricBlockSettings.copy(Blocks.OAK_LEAVES) Block.Settings.copy(Blocks.OAK_LEAVES)
), ItemGroups.NATURAL); ), ItemGroups.NATURAL);
Block GOLDEN_APPLE = register("golden_apple", new EnchantedFruitBlock(Direction.DOWN, GOLDEN_OAK_LEAVES, FruitBlock.DEFAULT_SHAPE, false, Settings.create().mapColor(MapColor.GOLD))); Block GOLDEN_APPLE = register("golden_apple", new EnchantedFruitBlock(Direction.DOWN, GOLDEN_OAK_LEAVES, FruitBlock.DEFAULT_SHAPE, false, Settings.create().mapColor(MapColor.GOLD)));
Block GOLDEN_OAK_SPROUT = register("golden_oak_sprout", new SproutBlock(0xE5FFCC88, () -> UItems.GOLDEN_OAK_SEEDS, () -> UTreeGen.GOLDEN_APPLE_TREE.sapling().map(Block::getDefaultState).get(), SproutBlock.settings())); Block GOLDEN_OAK_SPROUT = register("golden_oak_sprout", new SproutBlock(0xE5FFCC88, () -> UItems.GOLDEN_OAK_SEEDS, () -> UTreeGen.GOLDEN_APPLE_TREE.sapling().map(Block::getDefaultState).get(), SproutBlock.settings()));
@ -238,7 +237,7 @@ public interface UBlocks {
Block CARVED_CLOUD = register("carved_cloud", new OrientedCloudBlock(false, Settings.copy(CLOUD).hardness(0.4F).requiresTool().solid()), ItemGroups.BUILDING_BLOCKS); Block CARVED_CLOUD = register("carved_cloud", new OrientedCloudBlock(false, Settings.copy(CLOUD).hardness(0.4F).requiresTool().solid()), ItemGroups.BUILDING_BLOCKS);
Block UNSTABLE_CLOUD = register("unstable_cloud", new UnstableCloudBlock(Settings.copy(CLOUD)), ItemGroups.NATURAL); Block UNSTABLE_CLOUD = register("unstable_cloud", new UnstableCloudBlock(Settings.copy(CLOUD)), ItemGroups.NATURAL);
Block CLOUD_PILLAR = register("cloud_pillar", new CloudPillarBlock(Settings.create().mapColor(MapColor.GRAY).hardness(0.5F).resistance(0).sounds(BlockSoundGroup.WOOL).solid()), ItemGroups.NATURAL); Block CLOUD_PILLAR = register("cloud_pillar", new CloudPillarBlock(Settings.create().mapColor(MapColor.GRAY).hardness(0.5F).resistance(0).sounds(BlockSoundGroup.WOOL).solid()), ItemGroups.NATURAL);
Block CLOUD_CHEST = register("cloud_chest", new CloudChestBlock(DENSE_CLOUD.getDefaultState(), Settings.copy(DENSE_CLOUD).instrument(Instrument.BASS).strength(2.5f)), ItemGroups.FUNCTIONAL); Block CLOUD_CHEST = register("cloud_chest", new CloudChestBlock(DENSE_CLOUD.getDefaultState(), Settings.copy(DENSE_CLOUD).instrument(NoteBlockInstrument.BASS).strength(2.5f)), ItemGroups.FUNCTIONAL);
Block CLOTH_BED = register("cloth_bed", new FancyBedBlock("cloth", Settings.copy(Blocks.WHITE_BED).sounds(BlockSoundGroup.WOOD))); Block CLOTH_BED = register("cloth_bed", new FancyBedBlock("cloth", Settings.copy(Blocks.WHITE_BED).sounds(BlockSoundGroup.WOOD)));
Block CLOUD_BED = register("cloud_bed", new CloudBedBlock("cloud", CLOUD.getDefaultState(), Settings.copy(Blocks.WHITE_BED).sounds(BlockSoundGroup.WOOL))); Block CLOUD_BED = register("cloud_bed", new CloudBedBlock("cloud", CLOUD.getDefaultState(), Settings.copy(Blocks.WHITE_BED).sounds(BlockSoundGroup.WOOL)));
@ -259,7 +258,7 @@ public interface UBlocks {
Block ZAP_JAR = register("zap_jar", new JarBlock(Settings.copy(Blocks.GLASS))); Block ZAP_JAR = register("zap_jar", new JarBlock(Settings.copy(Blocks.GLASS)));
Block WORM_BLOCK = register("worm_block", new ColoredFallingBlock(new ColorCode(0xFF0088), Settings.create().hardness(0.1F).resistance(0).requiresTool().sounds(BlockSoundGroup.MUD)), ItemGroups.NATURAL); Block WORM_BLOCK = register("worm_block", new ColoredFallingBlock(new ColorCode(0xFF0088), Settings.create().hardness(0.1F).resistance(0).requiresTool().sounds(BlockSoundGroup.MUD)), ItemGroups.NATURAL);
EdibleBlock HAY_BLOCK = register("hay_block", new EdibleBlock(new Identifier("hay_block"), new Identifier("wheat"), true)); EdibleBlock HAY_BLOCK = register("hay_block", new EdibleBlock(Identifier.ofVanilla("hay_block"), Identifier.ofVanilla("wheat"), true));
private static <T extends Block> T register(String name, T item) { private static <T extends Block> T register(String name, T item) {
return register(Unicopia.id(name), item); return register(Unicopia.id(name), item);
@ -290,8 +289,8 @@ public interface UBlocks {
static void bootstrap() { static void bootstrap() {
if (FabricLoader.getInstance().isModLoaded("farmersdelight")) { if (FabricLoader.getInstance().isModLoaded("farmersdelight")) {
register("rice_block", new EdibleBlock(new Identifier("farmersdelight", "rice_bale"), new Identifier("farmersdelight", "rice_panicle"), true)); register("rice_block", new EdibleBlock(Identifier.of("farmersdelight", "rice_bale"), Identifier.of("farmersdelight", "rice_panicle"), true));
register("straw_block", new EdibleBlock(new Identifier("farmersdelight", "straw_bale"), new Identifier("farmersdelight", "straw"), true)); register("straw_block", new EdibleBlock(Identifier.of("farmersdelight", "straw_bale"), Identifier.of("farmersdelight", "straw"), true));
} }
BlockEntityTypeSupportHelper.of(BlockEntityType.SIGN).addSupportedBlocks(PALM_SIGN, PALM_WALL_SIGN); BlockEntityTypeSupportHelper.of(BlockEntityType.SIGN).addSupportedBlocks(PALM_SIGN, PALM_WALL_SIGN);
BlockEntityTypeSupportHelper.of(BlockEntityType.HANGING_SIGN).addSupportedBlocks(PALM_HANGING_SIGN, PALM_WALL_HANGING_SIGN); BlockEntityTypeSupportHelper.of(BlockEntityType.HANGING_SIGN).addSupportedBlocks(PALM_HANGING_SIGN, PALM_WALL_HANGING_SIGN);

View file

@ -14,6 +14,7 @@ import net.minecraft.nbt.NbtCompound;
import net.minecraft.network.packet.Packet; import net.minecraft.network.packet.Packet;
import net.minecraft.network.listener.ClientPlayPacketListener; import net.minecraft.network.listener.ClientPlayPacketListener;
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket; import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.util.math.*; import net.minecraft.util.math.*;
@ -73,13 +74,13 @@ public class WeatherVaneBlock extends BlockWithEntity {
} }
@Override @Override
public void readNbt(NbtCompound nbt) { public void readNbt(NbtCompound nbt, WrapperLookup lookup) {
angle = nbt.getFloat("angle"); angle = nbt.getFloat("angle");
airflow = new Vec3d(nbt.getDouble("windX"), 0, nbt.getDouble("windZ")); airflow = new Vec3d(nbt.getDouble("windX"), 0, nbt.getDouble("windZ"));
} }
@Override @Override
protected void writeNbt(NbtCompound nbt) { protected void writeNbt(NbtCompound nbt, WrapperLookup lookup) {
nbt.putFloat("angle", angle); nbt.putFloat("angle", angle);
nbt.putDouble("windX", airflow.x); nbt.putDouble("windX", airflow.x);
nbt.putDouble("windZ", airflow.z); nbt.putDouble("windZ", airflow.z);
@ -91,8 +92,8 @@ public class WeatherVaneBlock extends BlockWithEntity {
} }
@Override @Override
public NbtCompound toInitialChunkDataNbt() { public NbtCompound toInitialChunkDataNbt(WrapperLookup lookup) {
return createNbt(); return createNbt(lookup);
} }
public static void serverTick(World world, BlockPos pos, BlockState state, WeatherVane entity) { public static void serverTick(World world, BlockPos pos, BlockState state, WeatherVane entity) {

View file

@ -15,8 +15,9 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.ai.pathing.NavigationType; import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemPlacementContext;
import net.minecraft.util.ActionResult; import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShape;
@ -76,11 +77,11 @@ public class CloudBedBlock extends FancyBedBlock implements CloudLike {
} }
@Override @Override
public ActionResult onUse(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) {
if (!baseBlock.canInteract(baseState, world, pos, EquineContext.of(player))) { if (!baseBlock.canInteract(baseState, world, pos, EquineContext.of(player))) {
return ActionResult.PASS; return ItemActionResult.SKIP_DEFAULT_BLOCK_INTERACTION;
} }
return super.onUse(state, world, pos, player, hand, hit); return super.onUseWithItem(stack, state, world, pos, player, hand, hit);
} }
@Deprecated @Deprecated
@ -91,7 +92,7 @@ public class CloudBedBlock extends FancyBedBlock implements CloudLike {
@Override @Override
@Deprecated @Deprecated
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { public boolean canPathfindThrough(BlockState state, NavigationType type) {
return baseState.canPathfindThrough(world, pos, type); return baseState.canPathfindThrough(type);
} }
} }

View file

@ -187,7 +187,7 @@ public class CloudBlock extends Block implements CloudLike {
@Override @Override
@Deprecated @Deprecated
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, 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();
} }
@ -200,7 +200,6 @@ public class CloudBlock extends Block implements CloudLike {
return context.collidesWithClouds() || context.hasFeatherTouch(); return context.collidesWithClouds() || context.hasFeatherTouch();
} }
@SuppressWarnings("deprecation")
protected boolean canReplace(BlockState state, ItemPlacementContext context, EquineContext equineContext) { protected boolean canReplace(BlockState state, ItemPlacementContext context, EquineContext equineContext) {
return super.canReplace(state, context); return super.canReplace(state, context);
} }

View file

@ -24,12 +24,13 @@ import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.DoubleInventory; import net.minecraft.inventory.DoubleInventory;
import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemPlacementContext;
import net.minecraft.item.ItemStack;
import net.minecraft.screen.GenericContainerScreenHandler; import net.minecraft.screen.GenericContainerScreenHandler;
import net.minecraft.screen.NamedScreenHandlerFactory; import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandler; import net.minecraft.screen.ScreenHandler;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShape;
@ -137,11 +138,11 @@ public class CloudChestBlock extends ChestBlock implements CloudLike {
} }
@Override @Override
public ActionResult onUse(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) {
if (!baseBlock.canInteract(baseState, world, pos, EquineContext.of(player))) { if (!baseBlock.canInteract(baseState, world, pos, EquineContext.of(player))) {
return ActionResult.PASS; return ItemActionResult.SKIP_DEFAULT_BLOCK_INTERACTION;
} }
return super.onUse(state, world, pos, player, hand, hit); return super.onUseWithItem(stack, state, world, pos, player, hand, hit);
} }
@Deprecated @Deprecated
@ -152,7 +153,7 @@ public class CloudChestBlock extends ChestBlock implements CloudLike {
@Override @Override
@Deprecated @Deprecated
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, 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

@ -16,8 +16,9 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.ai.pathing.NavigationType; import net.minecraft.entity.ai.pathing.NavigationType;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemPlacementContext; import net.minecraft.item.ItemPlacementContext;
import net.minecraft.util.ActionResult; import net.minecraft.item.ItemStack;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShape;
@ -79,11 +80,11 @@ public class CloudDoorBlock extends DoorBlock implements CloudLike {
} }
@Override @Override
public ActionResult onUse(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) {
if (!baseBlock.canInteract(baseState, world, pos, EquineContext.of(player))) { if (!baseBlock.canInteract(baseState, world, pos, EquineContext.of(player))) {
return ActionResult.PASS; return ItemActionResult.SKIP_DEFAULT_BLOCK_INTERACTION;
} }
return super.onUse(state, world, pos, player, hand, hit); return super.onUseWithItem(stack, state, world, pos, player, hand, hit);
} }
@Deprecated @Deprecated
@ -100,7 +101,7 @@ public class CloudDoorBlock extends DoorBlock implements CloudLike {
@Override @Override
@Deprecated @Deprecated
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { public boolean canPathfindThrough(BlockState state, NavigationType type) {
return !InteractionManager.getInstance().getPathingEquineContext().collidesWithClouds() || super.canPathfindThrough(state, world, pos, type); return !InteractionManager.getInstance().getPathingEquineContext().collidesWithClouds() || super.canPathfindThrough(state, type);
} }
} }

View file

@ -108,7 +108,7 @@ public class CloudStairsBlock extends StairsBlock implements CloudLike {
@Override @Override
@Deprecated @Deprecated
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) { public boolean canPathfindThrough(BlockState state, NavigationType type) {
return baseBlock.canPathfindThrough(state, world, pos, type); return baseBlock.canPathfindThrough(state, type);
} }
} }

View file

@ -12,6 +12,7 @@ import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.ConnectingBlock; import net.minecraft.block.ConnectingBlock;
import net.minecraft.block.ShapeContext; import net.minecraft.block.ShapeContext;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.registry.tag.ItemTags; import net.minecraft.registry.tag.ItemTags;
@ -20,10 +21,10 @@ import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager; import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Property; import net.minecraft.state.property.Property;
import net.minecraft.util.ActionResult;
import net.minecraft.util.BlockMirror; import net.minecraft.util.BlockMirror;
import net.minecraft.util.BlockRotation; import net.minecraft.util.BlockRotation;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.Util; import net.minecraft.util.Util;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -82,20 +83,19 @@ public class CompactedCloudBlock extends CloudBlock {
} }
@Override @Override
public ActionResult onUse(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) {
ItemStack stack = player.getStackInHand(hand);
if (stack.isIn(ItemTags.SHOVELS)) { if (stack.isIn(ItemTags.SHOVELS)) {
BooleanProperty property = FACING_PROPERTIES.get(hit.getSide()); BooleanProperty property = FACING_PROPERTIES.get(hit.getSide());
if (state.get(property)) { if (state.get(property)) {
world.setBlockState(pos, state.with(property, false)); world.setBlockState(pos, state.with(property, false));
stack.damage(1, player, p -> p.sendToolBreakStatus(hand)); stack.damage(1, player, LivingEntity.getSlotForHand(hand));
world.playSound(null, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS); world.playSound(null, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS);
return ActionResult.SUCCESS; return ItemActionResult.SUCCESS;
} }
} }
return ActionResult.PASS; return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
} }
@Override @Override

View file

@ -12,6 +12,7 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.minecraft.block.BedBlock; import net.minecraft.block.BedBlock;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
@ -19,8 +20,8 @@ import net.minecraft.registry.tag.ItemTags;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
import net.minecraft.state.property.BooleanProperty; import net.minecraft.state.property.BooleanProperty;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -49,17 +50,15 @@ public class NaturalCloudBlock extends PoreousCloudBlock {
} }
@Override @Override
public ActionResult onUse(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) {
ItemStack stack = player.getStackInHand(hand);
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));
stack.damage(1, player, p -> p.sendToolBreakStatus(hand)); stack.damage(1, player, LivingEntity.getSlotForHand(hand));
world.playSound(null, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS); world.playSound(null, pos, SoundEvents.ITEM_SHOVEL_FLATTEN, SoundCategory.BLOCKS);
return ActionResult.SUCCESS; return ItemActionResult.SUCCESS;
} }
return ActionResult.PASS; return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
} }
} }

View file

@ -15,7 +15,6 @@ import net.minecraft.screen.ScreenHandlerContext;
import net.minecraft.screen.SimpleNamedScreenHandlerFactory; import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
import net.minecraft.stat.Stats; import net.minecraft.stat.Stats;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.shape.VoxelShape; import net.minecraft.util.shape.VoxelShape;
@ -50,7 +49,7 @@ public class ShapingBenchBlock extends CloudBlock {
} }
@Override @Override
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { public 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

@ -17,8 +17,8 @@ import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
import net.minecraft.state.property.IntProperty; import net.minecraft.state.property.IntProperty;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.Util; import net.minecraft.util.Util;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -51,9 +51,8 @@ public interface Soakable {
} }
} }
static ActionResult tryCollectMoisture(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { static ItemActionResult tryCollectMoisture(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if (state.getBlock() instanceof Soakable soakable) { if (state.getBlock() instanceof Soakable soakable) {
ItemStack stack = player.getStackInHand(hand);
if (stack.getItem() == Items.GLASS_BOTTLE) { if (stack.getItem() == Items.GLASS_BOTTLE) {
if (!player.isCreative()) { if (!player.isCreative()) {
stack.split(1); stack.split(1);
@ -67,11 +66,11 @@ public interface Soakable {
world.emitGameEvent(player, GameEvent.FLUID_PICKUP, pos); world.emitGameEvent(player, GameEvent.FLUID_PICKUP, pos);
updateMoisture(soakable, state, world, pos, soakable.getMoisture(state) - 1); updateMoisture(soakable, state, world, pos, soakable.getMoisture(state) - 1);
return ActionResult.SUCCESS; return ItemActionResult.SUCCESS;
} }
} }
return ActionResult.PASS; return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
} }
static void tickMoisture(BlockState state, ServerWorld world, BlockPos pos, Random random) { static void tickMoisture(BlockState state, ServerWorld world, BlockPos pos, Random random) {

View file

@ -17,8 +17,8 @@ import net.minecraft.item.ItemStack;
import net.minecraft.registry.Registries; import net.minecraft.registry.Registries;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.state.StateManager; import net.minecraft.state.StateManager;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.ItemActionResult;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.Random; import net.minecraft.util.math.random.Random;
@ -66,8 +66,8 @@ public class SoggyCloudBlock extends CloudBlock implements Soakable {
@Override @Override
@Deprecated @Deprecated
public ActionResult onUse(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(state, world, pos, player, hand, hit); return Soakable.tryCollectMoisture(stack, state, world, pos, player, hand, hit);
} }
@Override @Override

Some files were not shown because too many files have changed in this diff Show more