mirror of
https://github.com/Sollace/Unicopia.git
synced 2024-11-27 15:17:59 +01:00
Updating to 1.21 (part 2)
This commit is contained in:
parent
74d30d7c95
commit
259b0cddc4
191 changed files with 1216 additions and 1139 deletions
2
.github/workflows/gradle-build.yml
vendored
2
.github/workflows/gradle-build.yml
vendored
|
@ -12,7 +12,7 @@ jobs:
|
|||
- name: Set up JDK
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 17
|
||||
java-version: 21
|
||||
- name: Build Gradle
|
||||
uses: eskatos/gradle-command-action@v1
|
||||
with:
|
||||
|
|
2
.github/workflows/gradle-check.yml
vendored
2
.github/workflows/gradle-check.yml
vendored
|
@ -12,7 +12,7 @@ jobs:
|
|||
- name: Set up JDK
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 17
|
||||
java-version: 21
|
||||
- name: Build Gradle
|
||||
uses: eskatos/gradle-command-action@v1
|
||||
with:
|
||||
|
|
2
.github/workflows/gradle-publish.yml
vendored
2
.github/workflows/gradle-publish.yml
vendored
|
@ -16,7 +16,7 @@ jobs:
|
|||
- name: Set up JDK
|
||||
uses: actions/setup-java@v1
|
||||
with:
|
||||
java-version: 17
|
||||
java-version: 21
|
||||
- name: Prepare Datagen
|
||||
uses: eskatos/gradle-command-action@v1
|
||||
with:
|
||||
|
|
|
@ -12,7 +12,7 @@ apply plugin: 'io.github.dexman545.outlet'
|
|||
|
||||
java {
|
||||
toolchain {
|
||||
languageVersion = JavaLanguageVersion.of(17)
|
||||
languageVersion = JavaLanguageVersion.of(21)
|
||||
}
|
||||
withSourcesJar()
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ org.gradle.daemon=false
|
|||
modrinth_project_id=9K7RJlvM
|
||||
|
||||
# Dependencies
|
||||
fabwork_version=1.3.1+1.21
|
||||
fabwork_version=1.3.2-beta.1+1.21
|
||||
modmenu_version=11.0.0-beta.1
|
||||
minelp_version=4.12.0+1.21
|
||||
kirin_version=1.19.0+1.21
|
||||
|
|
|
@ -24,7 +24,7 @@ public interface Debug {
|
|||
AtomicReference<World> LAST_TESTED_WORLD = new AtomicReference<>(null);
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -202,7 +202,7 @@ public record Race (
|
|||
Identifier id = Identifier.tryParse(s);
|
||||
if (id != null) {
|
||||
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);
|
||||
}
|
||||
|
@ -231,7 +231,7 @@ public record Race (
|
|||
Identifier id = context.getArgument(name, RegistryKey.class).getValue();
|
||||
final Identifier idf = 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));
|
||||
}
|
||||
|
|
|
@ -16,7 +16,7 @@ public interface UConventionalTags {
|
|||
TagKey<Block> CORALS = block("corals");
|
||||
|
||||
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");
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,16 +2,17 @@ package com.minelittlepony.unicopia;
|
|||
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.registry.Registry;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.world.event.GameEvent;
|
||||
|
||||
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);
|
||||
return Registry.register(Registries.GAME_EVENT, id, new GameEvent(range));
|
||||
return Registry.registerReference(Registries.GAME_EVENT, id, new GameEvent(range));
|
||||
}
|
||||
|
||||
static void bootstrap() {
|
||||
|
|
|
@ -56,7 +56,7 @@ public interface USounds {
|
|||
SoundEvent ENTITY_HOT_AIR_BALLOON_BURNER_FIRE = ENTITY_GHAST_SHOOT;
|
||||
SoundEvent ENTITY_HOT_AIR_BALLOON_STEP = BLOCK_WOOL_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_SOMBRA_AMBIENT = register("entity.sombra.ambient");
|
||||
|
|
|
@ -137,7 +137,7 @@ public interface UTags {
|
|||
TagKey<DimensionType> HAS_NO_ATMOSPHERE = dimension("has_no_atmosphere");
|
||||
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,7 @@ public class Unicopia implements ModInitializer {
|
|||
}
|
||||
|
||||
public static Identifier id(String name) {
|
||||
return new Identifier(DEFAULT_NAMESPACE, name);
|
||||
return Identifier.of(DEFAULT_NAMESPACE, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,6 +6,8 @@ import com.minelittlepony.unicopia.Race;
|
|||
import com.minelittlepony.unicopia.ability.data.Hit;
|
||||
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.util.Identifier;
|
||||
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.
|
||||
*/
|
||||
Hit.Serializer<T> getSerializer();
|
||||
PacketCodec<? extends ByteBuf, T> getSerializer();
|
||||
|
||||
/**
|
||||
* Called on the client to get any data required to activate the ability.
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.minelittlepony.unicopia.util.NbtSerialisable;
|
|||
import com.minelittlepony.unicopia.util.Tickable;
|
||||
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public class AbilityDispatcher implements Tickable, NbtSerialisable {
|
||||
|
@ -83,20 +84,20 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
if (compound.contains("stats")) {
|
||||
stats.clear();
|
||||
NbtCompound li = compound.getCompound("stats");
|
||||
li.getKeys().forEach(key -> {
|
||||
getStat(AbilitySlot.valueOf(key)).fromNBT(li.getCompound(key));
|
||||
getStat(AbilitySlot.valueOf(key)).fromNBT(li.getCompound(key), lookup);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
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);
|
||||
}
|
||||
|
||||
|
@ -283,7 +284,7 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
compound.putInt("warmup", warmup);
|
||||
compound.putInt("cooldown", cooldown);
|
||||
compound.putInt("maxWarmup", maxWarmup);
|
||||
|
@ -295,13 +296,13 @@ public class AbilityDispatcher implements Tickable, NbtSerialisable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
warmup = compound.getInt("warmup");
|
||||
cooldown = compound.getInt("cooldown");
|
||||
maxWarmup = compound.getInt("maxWarmup");
|
||||
maxCooldown = compound.getInt("maxCooldown");
|
||||
triggered = compound.getBoolean("triggered");
|
||||
activeAbility = Abilities.REGISTRY.getOrEmpty(new Identifier(compound.getString("activeAbility")));
|
||||
activeAbility = Abilities.REGISTRY.getOrEmpty(Identifier.of(compound.getString("activeAbility")));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,6 +5,8 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.CustomisedSpellTyp
|
|||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
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.util.ActionResult;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
|
@ -52,8 +54,8 @@ abstract class AbstractSpellCastingAbility implements Ability<Hit> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Hit.Serializer<Hit> getSerializer() {
|
||||
return Hit.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
|
||||
return Hit.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,6 +6,8 @@ import com.minelittlepony.unicopia.ability.data.Multi;
|
|||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.util.TraceHelper;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
/**
|
||||
|
@ -43,8 +45,8 @@ public class BatPonyHangAbility implements Ability<Multi> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Multi.Serializer<Multi> getSerializer() {
|
||||
return Multi.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Multi> getSerializer() {
|
||||
return Multi.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,9 +11,11 @@ import com.minelittlepony.unicopia.entity.Living;
|
|||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.util.TraceHelper;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
|
@ -48,8 +50,8 @@ public class CarryAbility implements Ability<Hit> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Hit.Serializer<Hit> getSerializer() {
|
||||
return Hit.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
|
||||
return Hit.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -15,7 +15,11 @@ import com.minelittlepony.unicopia.entity.player.Pony;
|
|||
import com.minelittlepony.unicopia.item.FriendshipBraceletItem;
|
||||
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.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
@ -58,8 +62,8 @@ public class ChangeFormAbility implements Ability<Hit> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Hit.Serializer<Hit> getSerializer() {
|
||||
return Hit.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
|
||||
return Hit.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -77,7 +81,7 @@ public class ChangeFormAbility implements Ability<Hit> {
|
|||
player.subtractEnergyCost(5 * targets.size());
|
||||
TrinketsDelegate.EquippedStack amulet = UItems.PEARL_NECKLACE.getForEntity(player.asEntity());
|
||||
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();
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.minelittlepony.unicopia.entity.player.Pony;
|
|||
import com.minelittlepony.unicopia.util.TraceHelper;
|
||||
import com.minelittlepony.unicopia.util.VecHelper;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
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.SheepEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
|
||||
/**
|
||||
|
@ -54,8 +56,8 @@ public class ChangelingFeedAbility implements Ability<Hit> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Hit.Serializer<Hit> getSerializer() {
|
||||
return Hit.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
|
||||
return Hit.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -18,6 +18,7 @@ import com.minelittlepony.unicopia.server.world.ModificationType;
|
|||
import com.minelittlepony.unicopia.util.TraceHelper;
|
||||
import com.minelittlepony.unicopia.util.VecHelper;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
|
@ -26,6 +27,7 @@ import net.minecraft.block.FarmlandBlock;
|
|||
import net.minecraft.item.BoneMealItem;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
@ -54,8 +56,8 @@ public class EarthPonyGrowAbility implements Ability<Pos> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Hit.Serializer<Pos> getSerializer() {
|
||||
return Pos.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Pos> getSerializer() {
|
||||
return Pos.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -6,7 +6,6 @@ import java.util.stream.Stream;
|
|||
import org.jetbrains.annotations.Nullable;
|
||||
|
||||
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.tree.TreeType;
|
||||
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.util.*;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.BeehiveBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
|
@ -30,6 +30,7 @@ import net.minecraft.entity.LivingEntity;
|
|||
import net.minecraft.entity.passive.BeeEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
@ -145,8 +146,8 @@ public class EarthPonyKickAbility implements Ability<Pos> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Hit.Serializer<Pos> getSerializer() {
|
||||
return Pos.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Pos> getSerializer() {
|
||||
return Pos.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -23,6 +23,7 @@ import com.minelittlepony.unicopia.server.world.ModificationType;
|
|||
import com.minelittlepony.unicopia.util.PosHelper;
|
||||
import com.minelittlepony.unicopia.util.VecHelper;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
|
@ -31,6 +32,7 @@ import net.minecraft.entity.LivingEntity;
|
|||
import net.minecraft.entity.attribute.EntityAttributes;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.particle.BlockStateParticleEffect;
|
||||
import net.minecraft.registry.tag.BlockTags;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
|
@ -69,7 +71,7 @@ public class EarthPonyStompAbility implements Ability<Hit> {
|
|||
public Identifier getIcon(Pony player) {
|
||||
Identifier id = Abilities.REGISTRY.getId(this);
|
||||
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()
|
||||
+ ".png");
|
||||
}
|
||||
|
@ -94,8 +96,8 @@ public class EarthPonyStompAbility implements Ability<Hit> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Hit.Serializer<Hit> getSerializer() {
|
||||
return Hit.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
|
||||
return Hit.CODEC;
|
||||
}
|
||||
|
||||
private void thrustDownwards(Pony player) {
|
||||
|
|
|
@ -7,6 +7,9 @@ import org.jetbrains.annotations.Nullable;
|
|||
import com.minelittlepony.unicopia.ability.data.Hit;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
|
||||
/**
|
||||
* Dashing ability for flying creatures.
|
||||
*/
|
||||
|
@ -29,8 +32,8 @@ public class FlyingDashAbility implements Ability<Hit> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Hit.Serializer<Hit> getSerializer() {
|
||||
return Hit.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
|
||||
return Hit.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,7 +34,7 @@ public class HugAbility extends CarryAbility {
|
|||
creeper.startRiding(player, true);
|
||||
Living.getOrEmpty(creeper).ifPresent(living -> living.setCarrier(player));
|
||||
} 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);
|
||||
|
||||
if (rider instanceof FriendlyCreeperEntity) {
|
||||
|
|
|
@ -11,6 +11,8 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
|
|||
import com.minelittlepony.unicopia.block.state.StateMaps;
|
||||
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.sound.SoundCategory;
|
||||
import net.minecraft.text.Text;
|
||||
|
@ -36,8 +38,8 @@ public class KirinRageAbility implements Ability<Hit> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Hit.Serializer<Hit> getSerializer() {
|
||||
return Hit.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
|
||||
return Hit.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,9 +11,11 @@ import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation.Recipient
|
|||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.util.ExplosionUtil;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.damage.DamageTypes;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
|
@ -42,8 +44,8 @@ public class NirikBlastAbility implements Ability<Hit> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Hit.Serializer<Hit> getSerializer() {
|
||||
return Hit.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
|
||||
return Hit.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -5,18 +5,19 @@ import java.util.Optional;
|
|||
import com.minelittlepony.unicopia.EquinePredicates;
|
||||
import com.minelittlepony.unicopia.USounds;
|
||||
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.damage.UDamageTypes;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.util.TraceHelper;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.registry.tag.BlockTags;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
|
@ -59,8 +60,8 @@ public class PeckAbility implements Ability<Hit> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Numeric.Serializer<Hit> getSerializer() {
|
||||
return Hit.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
|
||||
return Hit.CODEC;
|
||||
}
|
||||
|
||||
protected LivingEntity findTarget(PlayerEntity player, World w) {
|
||||
|
|
|
@ -9,7 +9,9 @@ import com.minelittlepony.unicopia.entity.player.Pony;
|
|||
import com.minelittlepony.unicopia.item.UItems;
|
||||
import com.minelittlepony.unicopia.particle.MagicParticleEffect;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.text.Text;
|
||||
|
@ -39,8 +41,8 @@ public class PegasusCaptureStormAbility implements Ability<Hit> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Hit.Serializer<Hit> getSerializer() {
|
||||
return Hit.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
|
||||
return Hit.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,6 +10,9 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
|
|||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.particle.MagicParticleEffect;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
|
||||
/**
|
||||
* Pegasus ability to perform rainbooms
|
||||
*/
|
||||
|
@ -32,8 +35,8 @@ public class PegasusRainboomAbility implements Ability<Hit> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Hit.Serializer<Hit> getSerializer() {
|
||||
return Hit.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
|
||||
return Hit.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -16,7 +16,9 @@ import com.minelittlepony.unicopia.entity.player.Pony;
|
|||
import com.minelittlepony.unicopia.util.RegistryUtils;
|
||||
import com.minelittlepony.unicopia.util.VecHelper;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
@ -58,8 +60,8 @@ public class ScreechAbility implements Ability<Numeric> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Numeric.Serializer<Numeric> getSerializer() {
|
||||
return Numeric.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Numeric> getSerializer() {
|
||||
return Numeric.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -13,11 +13,13 @@ import com.minelittlepony.unicopia.entity.player.Pony;
|
|||
import com.minelittlepony.unicopia.particle.ParticleUtils;
|
||||
import com.minelittlepony.unicopia.particle.UParticles;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.ChestBlock;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityGroup;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.SpawnGroup;
|
||||
import net.minecraft.entity.mob.HostileEntity;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.registry.tag.FluidTags;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
|
@ -44,8 +46,8 @@ public class SeaponySonarPulseAbility implements Ability<Hit> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Hit.Serializer<Hit> getSerializer() {
|
||||
return Hit.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
|
||||
return Hit.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -58,7 +60,7 @@ public class SeaponySonarPulseAbility implements Ability<Hit> {
|
|||
player.setAnimation(Animation.ARMS_UP, Animation.Recipient.ANYONE);
|
||||
|
||||
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()) {
|
||||
Vec3d offset = target.getPos().subtract(player.getOriginVector());
|
||||
float distance = target.distanceTo(player.asEntity());
|
||||
|
@ -105,4 +107,12 @@ public class SeaponySonarPulseAbility implements Ability<Hit> {
|
|||
@Override
|
||||
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;
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -3,13 +3,15 @@ package com.minelittlepony.unicopia.ability;
|
|||
import java.util.Optional;
|
||||
|
||||
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.magic.spell.CastingMethod;
|
||||
import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
|
||||
import com.minelittlepony.unicopia.entity.player.Pony;
|
||||
import com.minelittlepony.unicopia.server.world.UGameRules;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
|
||||
public class TimeChangeAbility implements Ability<Rot> {
|
||||
|
||||
@Override
|
||||
|
@ -33,8 +35,8 @@ public class TimeChangeAbility implements Ability<Rot> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Serializer<Rot> getSerializer() {
|
||||
return Rot.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Rot> getSerializer() {
|
||||
return Rot.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -10,6 +10,8 @@ import com.minelittlepony.unicopia.client.render.PlayerPoser.Animation;
|
|||
import com.minelittlepony.unicopia.entity.Living;
|
||||
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.math.Vec3d;
|
||||
|
||||
|
@ -32,15 +34,14 @@ public class ToggleFlightAbility implements Ability<Hit> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Hit.Serializer<Hit> getSerializer() {
|
||||
return Hit.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Hit> getSerializer() {
|
||||
return Hit.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Identifier getIcon(Pony player) {
|
||||
Identifier id = Abilities.REGISTRY.getId(this);
|
||||
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")
|
||||
+ "_" + (race.isHuman() ? Race.EARTH : race).getId().getPath()
|
||||
+ ".png");
|
||||
|
|
|
@ -14,6 +14,8 @@ import com.minelittlepony.unicopia.particle.MagicParticleEffect;
|
|||
import com.minelittlepony.unicopia.util.TraceHelper;
|
||||
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.util.Identifier;
|
||||
|
||||
|
@ -39,13 +41,12 @@ public class UnicornDispellAbility implements Ability<Pos> {
|
|||
|
||||
@Override
|
||||
public Identifier getIcon(Pony player) {
|
||||
Identifier id = Abilities.REGISTRY.getId(this);
|
||||
return new Identifier(id.getNamespace(), "textures/gui/ability/" + id.getPath() + (player.getSpecies() == Race.CHANGELING ? "_changeling" : "") + ".png");
|
||||
return Abilities.REGISTRY.getId(this).withPath(p -> "textures/gui/ability/" + p + (player.getSpecies() == Race.CHANGELING ? "_changeling" : "") + ".png");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Pos.Serializer<Pos> getSerializer() {
|
||||
return Pos.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Pos> getSerializer() {
|
||||
return Pos.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -3,7 +3,6 @@ package com.minelittlepony.unicopia.ability;
|
|||
import java.util.Optional;
|
||||
|
||||
import com.minelittlepony.unicopia.USounds;
|
||||
import com.minelittlepony.unicopia.ability.data.Hit;
|
||||
import com.minelittlepony.unicopia.ability.data.Pos;
|
||||
import com.minelittlepony.unicopia.ability.magic.Caster;
|
||||
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.util.Trace;
|
||||
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.LeavesBlock;
|
||||
|
@ -21,6 +21,7 @@ import net.minecraft.block.PowderSnowBlock;
|
|||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.text.Text;
|
||||
|
@ -131,8 +132,8 @@ public class UnicornTeleportAbility implements Ability<Pos> {
|
|||
}
|
||||
|
||||
@Override
|
||||
public Hit.Serializer<Pos> getSerializer() {
|
||||
return Pos.SERIALIZER;
|
||||
public PacketCodec<? extends ByteBuf, Pos> getSerializer() {
|
||||
return Pos.CODEC;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -177,10 +178,11 @@ public class UnicornTeleportAbility implements Ability<Pos> {
|
|||
yPos,
|
||||
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()) {
|
||||
dest = destination.vec();
|
||||
participant.teleport(dest.x, participant.getY(), dest.z);
|
||||
participant.requestTeleport(dest.x, participant.getY(), dest.z);
|
||||
}
|
||||
teleporter.subtractEnergyCost(distance);
|
||||
|
||||
|
|
|
@ -2,17 +2,13 @@ package com.minelittlepony.unicopia.ability.data;
|
|||
|
||||
import java.util.Optional;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
|
||||
public interface 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) {
|
||||
return value ? INSTANCE : Optional.empty();
|
||||
}
|
||||
|
||||
public record Serializer<T extends Hit> (
|
||||
PacketByteBuf.PacketReader<T> read,
|
||||
PacketByteBuf.PacketWriter<T> write) {
|
||||
}
|
||||
}
|
|
@ -1,14 +1,16 @@
|
|||
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;
|
||||
|
||||
public record Multi (Pos pos, int hitType) implements Hit {
|
||||
public static final Serializer<Multi> SERIALIZER = new Serializer<>(
|
||||
buf -> new Multi(Pos.SERIALIZER.read().apply(buf), buf.readInt()),
|
||||
(buf, t) -> {
|
||||
Pos.SERIALIZER.write().accept(buf, t.pos());
|
||||
buf.writeInt(t.hitType());
|
||||
});
|
||||
public static final PacketCodec<PacketByteBuf, Multi> CODEC = PacketCodec.tuple(
|
||||
Pos.CODEC, Multi::pos,
|
||||
PacketCodecs.INTEGER, Multi::hitType,
|
||||
Multi::new
|
||||
);
|
||||
|
||||
public Multi(Vec3i pos, int hit) {
|
||||
this(new Pos(pos), hit);
|
||||
|
|
|
@ -2,10 +2,12 @@ package com.minelittlepony.unicopia.ability.data;
|
|||
|
||||
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 static final Serializer<Numeric> SERIALIZER = new Serializer<>(
|
||||
buf -> new Numeric(buf.readInt()),
|
||||
(buf, t) -> buf.writeInt(t.type()));
|
||||
public static final PacketCodec<ByteBuf, Numeric> CODEC = PacketCodecs.INTEGER.xmap(Numeric::new, Numeric::type);
|
||||
|
||||
public static Optional<Numeric> of(int type) {
|
||||
return Optional.of(new Numeric(type));
|
||||
|
|
|
@ -2,16 +2,18 @@ package com.minelittlepony.unicopia.ability.data;
|
|||
|
||||
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.*;
|
||||
|
||||
public record Pos (int x, int y, int z) implements Hit {
|
||||
public static final Serializer<Pos> SERIALIZER = new Serializer<>(
|
||||
buf -> new Pos(buf.readInt(), buf.readInt(), buf.readInt()),
|
||||
(buf, t) -> {
|
||||
buf.writeInt(t.x());
|
||||
buf.writeInt(t.y());
|
||||
buf.writeInt(t.z());
|
||||
});
|
||||
public static final PacketCodec<PacketByteBuf, Pos> CODEC = PacketCodec.tuple(
|
||||
PacketCodecs.INTEGER, Pos::x,
|
||||
PacketCodecs.INTEGER, Pos::y,
|
||||
PacketCodecs.INTEGER, Pos::z,
|
||||
Pos::new
|
||||
);
|
||||
|
||||
public Pos(Vec3i pos) {
|
||||
this(pos.getX(), pos.getY(), pos.getZ());
|
||||
|
|
|
@ -2,15 +2,17 @@ package com.minelittlepony.unicopia.ability.data;
|
|||
|
||||
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;
|
||||
|
||||
public record Rot (float pitch, float yaw) implements Hit {
|
||||
public static final Serializer<Rot> SERIALIZER = new Serializer<>(
|
||||
buf -> new Rot(buf.readFloat(), buf.readFloat()),
|
||||
(buf, t) -> {
|
||||
buf.writeFloat(t.pitch());
|
||||
buf.writeFloat(t.yaw());
|
||||
});
|
||||
public static final PacketCodec<PacketByteBuf, Rot> CODEC = PacketCodec.tuple(
|
||||
PacketCodecs.FLOAT, Rot::pitch,
|
||||
PacketCodecs.FLOAT, Rot::yaw,
|
||||
Rot::new
|
||||
);
|
||||
|
||||
public Rot applyTo(EntityConvertable<?> target) {
|
||||
Vec3d pos = target.getOriginVector();
|
||||
|
|
|
@ -14,12 +14,14 @@ import com.minelittlepony.unicopia.network.track.MsgTrackedValues;
|
|||
import com.minelittlepony.unicopia.network.track.ObjectTracker;
|
||||
import com.minelittlepony.unicopia.network.track.Trackable;
|
||||
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.serialization.PacketCodec;
|
||||
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodecs;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
|
||||
/**
|
||||
* Container for multiple spells
|
||||
|
@ -68,12 +70,12 @@ class MultiSpellSlot implements SpellSlots, NbtSerialisable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
compound.put("spells", NbtSerialisable.writeMap(tracker.entries(), UUID::toString, entry -> entry.spell.toNBT()));
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
compound.put("spells", NbtSerialisable.writeMap(tracker.entries(), UUID::toString, entry -> entry.spell.toNBT(lookup)));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
tracker.load(NbtSerialisable.readMap(compound.getCompound("spells"), key -> {
|
||||
try {
|
||||
return UUID.fromString(key);
|
||||
|
@ -82,7 +84,7 @@ class MultiSpellSlot implements SpellSlots, NbtSerialisable {
|
|||
}, (key, nbt) -> {
|
||||
try {
|
||||
Entry<Spell> entry = new Entry<>(owner);
|
||||
entry.spell.fromNBT((NbtCompound)nbt);
|
||||
entry.spell.fromNBT((NbtCompound)nbt, lookup);
|
||||
return entry;
|
||||
} catch (Throwable t) {
|
||||
Unicopia.LOGGER.warn("Exception loading tracked object: {}", t.getMessage());
|
||||
|
@ -135,34 +137,34 @@ class MultiSpellSlot implements SpellSlots, NbtSerialisable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void readTrackedNbt(NbtCompound nbt) {
|
||||
spell.fromNBT(nbt);
|
||||
public void readTrackedNbt(NbtCompound nbt, WrapperLookup lookup) {
|
||||
spell.fromNBT(nbt, lookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public NbtCompound writeTrackedNbt() {
|
||||
return spell.toNBT();
|
||||
public NbtCompound writeTrackedNbt(WrapperLookup lookup) {
|
||||
return spell.toNBT(lookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(PacketByteBuf buffer) {
|
||||
public void read(PacketByteBuf buffer, WrapperLookup lookup) {
|
||||
byte contentType = buffer.readByte();
|
||||
if (contentType == 1) {
|
||||
readTrackedNbt(PacketCodec.COMPRESSED_NBT.read(buffer));
|
||||
readTrackedNbt(PacketCodecs.NBT_COMPOUND.decode(buffer), lookup);
|
||||
} else {
|
||||
T spell = this.spell.get();
|
||||
if (spell != null) {
|
||||
spell.getDataTracker().load(new MsgTrackedValues.TrackerEntries(buffer));
|
||||
spell.getDataTracker().load(MsgTrackedValues.TrackerEntries.PACKET_CODEC.decode(buffer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Optional<PacketByteBuf> write(Status status) {
|
||||
public Optional<PacketByteBuf> write(Status status, WrapperLookup lookup) {
|
||||
if (status != Status.DEFAULT) {
|
||||
PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer());
|
||||
buffer.writeByte(1);
|
||||
PacketCodec.COMPRESSED_NBT.write(buffer, spell.toNBT());
|
||||
PacketCodecs.NBT_COMPOUND.encode(buffer, spell.toNBT(lookup));
|
||||
return Optional.of(buffer);
|
||||
}
|
||||
@Nullable T spell = this.spell.get();
|
||||
|
@ -172,7 +174,7 @@ class MultiSpellSlot implements SpellSlots, NbtSerialisable {
|
|||
return spell.getDataTracker().getDirtyPairs().map(entries -> {
|
||||
PacketByteBuf buffer = new PacketByteBuf(Unpooled.buffer());
|
||||
buffer.writeByte(0);
|
||||
entries.write(buffer);
|
||||
TrackerEntries.PACKET_CODEC.encode(buffer, entries);
|
||||
return buffer;
|
||||
});
|
||||
}
|
||||
|
|
|
@ -9,6 +9,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.Spell;
|
|||
import com.minelittlepony.unicopia.network.track.Trackable;
|
||||
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
|
||||
/**
|
||||
* Container for a single spell
|
||||
|
@ -57,13 +58,13 @@ class SingleSpellSlot implements SpellSlots, NbtSerialisable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
compound.put("effect", entry.spell.toNBT());
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
compound.put("effect", entry.spell.toNBT(lookup));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
entry.spell.fromNBT(compound.getCompound("effect"));
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
entry.spell.fromNBT(compound.getCompound("effect"), lookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.minelittlepony.unicopia.network.track.DataTracker;
|
|||
import com.minelittlepony.unicopia.server.world.Ether;
|
||||
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
|
||||
public abstract class AbstractDelegatingSpell implements Spell {
|
||||
private UUID uuid = UUID.randomUUID();
|
||||
|
@ -109,17 +110,17 @@ public abstract class AbstractDelegatingSpell implements Spell {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
compound.putUuid("uuid", uuid);
|
||||
compound.put("spell", delegate.toNBT());
|
||||
compound.put("spell", delegate.toNBT(lookup));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
if (compound.contains("uuid")) {
|
||||
uuid = compound.getUuid("uuid");
|
||||
}
|
||||
delegate.fromNBT(compound.getCompound("spell"));
|
||||
delegate.fromNBT(compound.getCompound("spell"), lookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -14,6 +14,7 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.entity.projectile.ProjectileEntity;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
|
||||
/**
|
||||
* Base implementation for a spell that changes the player's appearance.
|
||||
|
@ -53,14 +54,14 @@ public abstract class AbstractDisguiseSpell extends AbstractSpell implements Dis
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
disguise.toNBT(compound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
disguise.fromNBT(compound);
|
||||
}
|
||||
|
||||
|
|
|
@ -23,6 +23,7 @@ import net.minecraft.entity.effect.StatusEffects;
|
|||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
public class ChangelingFeedingSpell extends AbstractSpell {
|
||||
|
@ -141,22 +142,22 @@ public class ChangelingFeedingSpell extends AbstractSpell {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
compound.putFloat("healthToDrain", healthToDrain);
|
||||
compound.putInt("foodToDrain", foodToDrain);
|
||||
compound.putFloat("damageThisTick", damageThisTick);
|
||||
compound.put("targets", EntityReference.<LivingEntity>getSerializer().writeAll(targets));
|
||||
compound.put("targets", EntityReference.<LivingEntity>getSerializer().writeAll(targets, lookup));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
healthToDrain = compound.getFloat("healthToDrain");
|
||||
foodToDrain = compound.getInt("foodToDrain");
|
||||
damageThisTick = compound.getFloat("damageThisTick");
|
||||
targets = compound.contains("targets", NbtElement.LIST_TYPE)
|
||||
? EntityReference.<LivingEntity>getSerializer().readAll(compound.getList("targets", NbtElement.COMPOUND_TYPE)).toList()
|
||||
? EntityReference.<LivingEntity>getSerializer().readAll(compound.getList("targets", NbtElement.COMPOUND_TYPE), lookup).toList()
|
||||
: List.of();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.minelittlepony.unicopia.particle.MagicParticleEffect;
|
|||
import com.minelittlepony.unicopia.particle.UParticles;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
|
||||
/**
|
||||
* Shapeshifts the player.
|
||||
|
@ -95,15 +96,15 @@ public class DispersableDisguiseSpell extends AbstractDisguiseSpell implements I
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
compound.putInt("suppressionCounter", suppressionCounter);
|
||||
compound.putBoolean("forced", forced);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
suppressionCounter = compound.getInt("suppressionCounter");
|
||||
forced = compound.getBoolean("forced");
|
||||
if (suppressionCounter > 0) {
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.effect.SpellType;
|
|||
import com.minelittlepony.unicopia.network.track.DataTracker;
|
||||
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.util.Util;
|
||||
|
||||
public final class EmptySpell implements Spell {
|
||||
|
@ -16,10 +17,10 @@ public final class EmptySpell implements Spell {
|
|||
private EmptySpell() {}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) { }
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) { }
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) { }
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) { }
|
||||
|
||||
@Override
|
||||
public CustomisedSpellType<?> getTypeAndTraits() {
|
||||
|
|
|
@ -18,6 +18,7 @@ import net.minecraft.nbt.NbtCompound;
|
|||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.registry.RegistryKey;
|
||||
import net.minecraft.registry.RegistryKeys;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -120,9 +121,9 @@ public class PlacementControlSpell extends AbstractSpell implements OrientedSpel
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
compound.put("spell", Spell.writeNbt(delegate));
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
compound.put("spell", Spell.writeNbt(delegate, lookup));
|
||||
position.get().ifPresent(pos -> compound.put("position", NbtSerialisable.writeVector(pos)));
|
||||
orientation.get().ifPresent(o -> compound.put("orientation", NbtSerialisable.writeVector(o)));
|
||||
dimension.get().ifPresent(d -> compound.putString("dimension", d.getValue().toString()));
|
||||
|
@ -132,9 +133,9 @@ public class PlacementControlSpell extends AbstractSpell implements OrientedSpel
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
delegate = Spell.readNbt(compound.getCompound("spell"));
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
delegate = Spell.readNbt(compound.getCompound("spell"), lookup);
|
||||
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());
|
||||
orientation.set(compound.contains("orientation") ? Optional.of(NbtSerialisable.readVector(compound.getList("orientation", NbtElement.DOUBLE_TYPE))) : Optional.empty());
|
||||
|
|
|
@ -15,6 +15,7 @@ import net.minecraft.entity.LivingEntity;
|
|||
import net.minecraft.entity.damage.DamageTypes;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.world.BlockView;
|
||||
|
@ -130,14 +131,14 @@ public class RageAbilitySpell extends AbstractSpell {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
compound.putInt("age", age);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
age = compound.getInt("age");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.minelittlepony.unicopia.util.shape.Sphere;
|
|||
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
/**
|
||||
|
@ -85,14 +86,14 @@ public class RainboomAbilitySpell extends AbstractSpell {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
compound.putInt("age", age);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
age = compound.getInt("age");
|
||||
boundParticle = null;
|
||||
}
|
||||
|
|
|
@ -18,13 +18,15 @@ import com.minelittlepony.unicopia.server.world.Ether;
|
|||
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
||||
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.util.Util;
|
||||
|
||||
/**
|
||||
* Interface for a magic spells
|
||||
*/
|
||||
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.
|
||||
|
@ -133,7 +135,7 @@ public interface Spell extends NbtSerialisable, Affine {
|
|||
}
|
||||
|
||||
@Nullable
|
||||
static <T extends Spell> T readNbt(@Nullable NbtCompound compound) {
|
||||
static <T extends Spell> T readNbt(@Nullable NbtCompound compound, WrapperLookup lookup) {
|
||||
try {
|
||||
if (compound != null) {
|
||||
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");
|
||||
}
|
||||
|
||||
static NbtCompound writeNbt(@Nullable Spell effect) {
|
||||
static NbtCompound writeNbt(@Nullable Spell effect, WrapperLookup lookup) {
|
||||
if (effect == null) {
|
||||
return new NbtCompound();
|
||||
}
|
||||
NbtCompound compound = effect.toNBT();
|
||||
NbtCompound compound = effect.toNBT(lookup);
|
||||
effect.getTypeAndTraits().toNbt(compound);
|
||||
return compound;
|
||||
}
|
||||
|
||||
static <T extends Spell> Spell copy(T spell) {
|
||||
return readNbt(writeNbt(spell));
|
||||
static <T extends Spell> Spell copy(T spell, WrapperLookup lookup) {
|
||||
return readNbt(writeNbt(spell, lookup), lookup);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -11,6 +11,7 @@ import com.minelittlepony.unicopia.ability.magic.SpellPredicate;
|
|||
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
||||
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
|
||||
public final class SpellReference<T extends Spell> implements NbtSerialisable {
|
||||
@Nullable
|
||||
|
@ -50,19 +51,19 @@ public final class SpellReference<T extends Spell> implements NbtSerialisable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
if (spell != null && !spell.isDead()) {
|
||||
spell.toNBT(compound);
|
||||
spell.toNBT(compound, lookup);
|
||||
spell.getTypeAndTraits().toNbt(compound);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
if (spell == null || !Objects.equals(Spell.getUuid(compound), spell.getUuid())) {
|
||||
spell = Spell.readNbt(compound);
|
||||
spell = Spell.readNbt(compound, lookup);
|
||||
} else {
|
||||
spell.fromNBT(compound);
|
||||
spell.fromNBT(compound, lookup);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.minelittlepony.unicopia.server.world.UGameRules;
|
|||
import com.minelittlepony.unicopia.server.world.UnicopiaWorldProperties;
|
||||
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
|
||||
/**
|
||||
|
@ -75,16 +76,16 @@ public class TimeControlAbilitySpell extends AbstractSpell {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
compound.putBoolean("initilized", initilized);
|
||||
compound.putLong("timeOffset", timeOffset);
|
||||
compound.putFloat("angleOffset", angleOffset);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
initilized = compound.getBoolean("initilized");
|
||||
timeOffset = compound.getLong("timeOffset");
|
||||
angleOffset = compound.getFloat("angleOffset");
|
||||
|
|
|
@ -8,6 +8,7 @@ import com.minelittlepony.unicopia.util.NbtSerialisable;
|
|||
import com.minelittlepony.unicopia.util.Tickable;
|
||||
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
/**
|
||||
|
@ -44,13 +45,13 @@ public interface TimedSpell extends Spell {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
compound.putInt("duration", duration);
|
||||
compound.putInt("maxDuration", maxDuration);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
duration = compound.getInt("duration");
|
||||
maxDuration = compound.getInt("maxDuration");
|
||||
}
|
||||
|
|
|
@ -5,7 +5,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.trait.Trait;
|
|||
import com.minelittlepony.unicopia.client.UnicopiaClient;
|
||||
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.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
@ -15,7 +15,7 @@ public enum AttributeFormat {
|
|||
REGULAR {
|
||||
@Override
|
||||
public String formatValue(float value) {
|
||||
return ItemStack.MODIFIER_FORMAT.format(value);
|
||||
return AttributeModifiersComponent.DECIMAL_FORMAT.format(value);
|
||||
}
|
||||
},
|
||||
TIME {
|
||||
|
@ -27,7 +27,7 @@ public enum AttributeFormat {
|
|||
PERCENTAGE {
|
||||
@Override
|
||||
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()
|
||||
: Text.translatable("spell_attribute.unicopia.added_trait.unknown").formatted(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);
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,6 @@ public record AltarRecipeMatch(
|
|||
|
||||
public void craft() {
|
||||
ItemStack clockStack = result.copyWithCount(target.getStack().getCount());
|
||||
clockStack.setNbt(target.getStack().getNbt());
|
||||
target.setStack(clockStack);
|
||||
target.setInvulnerable(true);
|
||||
ingredients.forEach(Entity::discard);
|
||||
|
|
|
@ -15,8 +15,11 @@ import com.mojang.serialization.Codec;
|
|||
|
||||
import net.minecraft.item.ItemConvertible;
|
||||
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.util.Identifier;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
|
||||
public class IngredientWithSpell implements Predicate<ItemStack> {
|
||||
|
@ -27,6 +30,11 @@ public class IngredientWithSpell implements Predicate<ItemStack> {
|
|||
pair -> new IngredientWithSpell(pair.getFirst(), pair.getSecond()),
|
||||
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(
|
||||
list -> DefaultedList.<IngredientWithSpell>copyOf(EMPTY, list.toArray(IngredientWithSpell[]::new)),
|
||||
|
@ -75,16 +83,4 @@ public class IngredientWithSpell implements Predicate<ItemStack> {
|
|||
public boolean 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)
|
||||
);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -14,19 +14,40 @@ import com.minelittlepony.unicopia.util.CodecUtils;
|
|||
import com.minelittlepony.unicopia.util.InventoryUtil;
|
||||
import com.mojang.datafixers.util.Pair;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
||||
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.registry.DynamicRegistryManager;
|
||||
import net.minecraft.util.collection.DefaultedList;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* A recipe for creating a new spell from input traits and items.
|
||||
*/
|
||||
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
|
||||
*/
|
||||
|
@ -104,7 +125,7 @@ public class SpellCraftingRecipe implements SpellbookRecipe {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack craft(SpellbookInventory inventory, DynamicRegistryManager registries) {
|
||||
public ItemStack craft(SpellbookInventory inventory, WrapperLookup registries) {
|
||||
return getResult(registries).copy();
|
||||
}
|
||||
|
||||
|
@ -114,7 +135,7 @@ public class SpellCraftingRecipe implements SpellbookRecipe {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getResult(DynamicRegistryManager registries) {
|
||||
public ItemStack getResult(WrapperLookup registries) {
|
||||
return output;
|
||||
}
|
||||
|
||||
|
@ -122,41 +143,4 @@ public class SpellCraftingRecipe implements SpellbookRecipe {
|
|||
public RecipeSerializer<?> getSerializer() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -5,22 +5,24 @@ import com.minelittlepony.unicopia.container.inventory.SpellbookInventory;
|
|||
import com.minelittlepony.unicopia.item.*;
|
||||
import com.minelittlepony.unicopia.recipe.URecipes;
|
||||
import com.minelittlepony.unicopia.util.InventoryUtil;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
||||
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.registry.DynamicRegistryManager;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* A recipe for creating a new spell from input traits and items.
|
||||
*/
|
||||
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)
|
||||
).apply(instance, SpellDuplicatingRecipe::new));
|
||||
public static final PacketCodec<RegistryByteBuf, SpellDuplicatingRecipe> PACKET_CODEC = IngredientWithSpell.PACKET_CODEC.xmap(SpellDuplicatingRecipe::new, SpellDuplicatingRecipe::material);
|
||||
|
||||
@Override
|
||||
public void buildCraftingTree(CraftingTreeBuilder builder) {
|
||||
|
@ -50,7 +52,7 @@ public record SpellDuplicatingRecipe (IngredientWithSpell material) implements S
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack craft(SpellbookInventory inventory, DynamicRegistryManager registries) {
|
||||
public ItemStack craft(SpellbookInventory inventory, WrapperLookup registries) {
|
||||
return InventoryUtil.stream(inventory)
|
||||
.filter(i -> i.isOf(UItems.GEMSTONE))
|
||||
.filter(EnchantableItem::isEnchanted)
|
||||
|
@ -68,7 +70,7 @@ public record SpellDuplicatingRecipe (IngredientWithSpell material) implements S
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getResult(DynamicRegistryManager registries) {
|
||||
public ItemStack getResult(WrapperLookup registries) {
|
||||
ItemStack stack = UItems.GEMSTONE.getDefaultStack();
|
||||
stack.setCount(2);
|
||||
return stack;
|
||||
|
@ -78,21 +80,4 @@ public record SpellDuplicatingRecipe (IngredientWithSpell material) implements S
|
|||
public RecipeSerializer<?> getSerializer() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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.container.inventory.SpellbookInventory;
|
||||
import com.minelittlepony.unicopia.item.*;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import com.minelittlepony.unicopia.recipe.URecipes;
|
||||
|
||||
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.registry.DynamicRegistryManager;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* Recipe for adding traits to an existing spell.
|
||||
*/
|
||||
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)
|
||||
).apply(instance, SpellEnhancingRecipe::new));
|
||||
public static final PacketCodec<RegistryByteBuf, SpellEnhancingRecipe> PACKET_CODEC = IngredientWithSpell.PACKET_CODEC.xmap(SpellEnhancingRecipe::new, SpellEnhancingRecipe::material);
|
||||
|
||||
public IngredientWithSpell getBaseMaterial() {
|
||||
return material;
|
||||
|
@ -42,7 +44,7 @@ public record SpellEnhancingRecipe (IngredientWithSpell material) implements Spe
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack craft(SpellbookInventory inventory, DynamicRegistryManager registries) {
|
||||
public ItemStack craft(SpellbookInventory inventory, WrapperLookup registries) {
|
||||
return SpellTraits.of(inventory.getItemToModify())
|
||||
.add(inventory.getTraits())
|
||||
.applyTo(inventory.getItemToModify());
|
||||
|
@ -54,7 +56,7 @@ public record SpellEnhancingRecipe (IngredientWithSpell material) implements Spe
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getResult(DynamicRegistryManager registries) {
|
||||
public ItemStack getResult(WrapperLookup registries) {
|
||||
return UItems.GEMSTONE.getDefaultStack();
|
||||
}
|
||||
|
||||
|
@ -62,21 +64,4 @@ public record SpellEnhancingRecipe (IngredientWithSpell material) implements Spe
|
|||
public RecipeSerializer<?> getSerializer() {
|
||||
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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2,21 +2,37 @@ package com.minelittlepony.unicopia.ability.magic.spell.crafting;
|
|||
|
||||
import com.minelittlepony.unicopia.item.EnchantableItem;
|
||||
import com.minelittlepony.unicopia.recipe.URecipes;
|
||||
import com.minelittlepony.unicopia.util.InventoryUtil;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.MapCodec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
||||
import net.minecraft.inventory.RecipeInputInventory;
|
||||
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.RecipeSerializer;
|
||||
import net.minecraft.recipe.ShapedRecipe;
|
||||
import net.minecraft.recipe.book.CraftingRecipeCategory;
|
||||
import net.minecraft.registry.DynamicRegistryManager;
|
||||
import net.minecraft.util.dynamic.Codecs;
|
||||
import net.minecraft.recipe.input.CraftingRecipeInput;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
|
||||
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 ItemStack result;
|
||||
|
||||
|
@ -27,8 +43,8 @@ public class SpellShapedCraftingRecipe extends ShapedRecipe {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ItemStack craft(RecipeInputInventory inventory, DynamicRegistryManager registries) {
|
||||
return InventoryUtil.stream(inventory)
|
||||
public ItemStack craft(CraftingRecipeInput inventory, WrapperLookup registries) {
|
||||
return inventory.getStacks().stream()
|
||||
.filter(stack -> stack.getItem() instanceof EnchantableItem)
|
||||
.filter(EnchantableItem::isEnchanted)
|
||||
.map(stack -> ((EnchantableItem)stack.getItem()).getSpellEffect(stack))
|
||||
|
@ -41,38 +57,4 @@ public class SpellShapedCraftingRecipe extends ShapedRecipe {
|
|||
public RecipeSerializer<?> getSerializer() {
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,7 +10,8 @@ import com.mojang.serialization.DataResult;
|
|||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
||||
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 (
|
||||
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"),
|
||||
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")),
|
||||
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) {
|
||||
if (minTraits.isEmpty()) {
|
||||
|
@ -60,13 +66,4 @@ public record TraitIngredient (
|
|||
boolean maxMatch = max.map(m -> m.includes(t)).orElse(true);
|
||||
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));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -10,6 +10,7 @@ import com.minelittlepony.unicopia.network.track.TrackableDataType;
|
|||
import com.minelittlepony.unicopia.server.world.Ether;
|
||||
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
|
||||
public abstract class AbstractSpell implements Spell {
|
||||
|
||||
|
@ -97,7 +98,7 @@ public abstract class AbstractSpell implements Spell {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
compound.putBoolean("dying", dying.get());
|
||||
compound.putBoolean("dead", dead.get());
|
||||
compound.putBoolean("hidden", hidden.get());
|
||||
|
@ -106,7 +107,7 @@ public abstract class AbstractSpell implements Spell {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
if (compound.containsUuid("uuid")) {
|
||||
uuid = compound.getUuid("uuid");
|
||||
}
|
||||
|
|
|
@ -17,6 +17,7 @@ import com.minelittlepony.unicopia.entity.effect.EffectUtils;
|
|||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.text.MutableText;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Formatting;
|
||||
|
@ -51,10 +52,10 @@ public record CustomisedSpellType<T extends Spell> (
|
|||
}
|
||||
|
||||
@Nullable
|
||||
public T create(NbtCompound compound) {
|
||||
public T create(NbtCompound compound, WrapperLookup lookup) {
|
||||
T spell = create();
|
||||
if (spell != null) {
|
||||
spell.fromNBT(compound);
|
||||
spell.fromNBT(compound, lookup);
|
||||
}
|
||||
return spell;
|
||||
}
|
||||
|
|
|
@ -40,6 +40,7 @@ import net.minecraft.item.Items;
|
|||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
|
@ -303,14 +304,14 @@ public class DarkVortexSpell extends AbstractSpell implements ProjectileDelegate
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
compound.putFloat("accumulatedMass", accumulatedMass.get());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
accumulatedMass.set(compound.getFloat("accumulatedMass"));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,6 +15,7 @@ import com.minelittlepony.unicopia.projectile.ProjectileDelegate;
|
|||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
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) {
|
||||
entity.teleport(pos.x, pos.y, pos.z);
|
||||
// TODO: teleport -> requestTeleport
|
||||
entity.requestTeleport(pos.x, pos.y, pos.z);
|
||||
entity.setVelocity(vel);
|
||||
entity.setGlowing(false);
|
||||
entity.playSound(USounds.SPELL_DISPLACEMENT_TELEPORT, 1, 1);
|
||||
|
@ -124,16 +126,16 @@ public class DisplacementSpell extends AbstractSpell implements HomingSpell, Pro
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
compound.putInt("ticks", ticks);
|
||||
compound.put("target", target.toNBT());
|
||||
compound.put("target", target.toNBT(lookup));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
ticks = compound.getInt("ticks");
|
||||
target.fromNBT(compound.getCompound("target"));
|
||||
target.fromNBT(compound.getCompound("target"), lookup);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,6 +19,7 @@ import com.minelittlepony.unicopia.particle.ParticleUtils;
|
|||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
|
||||
|
@ -124,14 +125,14 @@ public class FeatherFallSpell extends AbstractSpell implements TimedSpell {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
timer.toNBT(compound);
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
timer.toNBT(compound, lookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
timer.fromNBT(compound);
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
timer.fromNBT(compound, lookup);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -18,6 +18,7 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.item.Items;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.predicate.entity.EntityPredicates;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
|
||||
public class FireBoltSpell extends AbstractSpell implements HomingSpell,
|
||||
|
@ -112,14 +113,14 @@ public class FireBoltSpell extends AbstractSpell implements HomingSpell,
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
compound.put("target", target.toNBT());
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
compound.put("target", target.toNBT(lookup));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
target.fromNBT(compound.getCompound("target"));
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
target.fromNBT(compound.getCompound("target"), lookup);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,13 +17,17 @@ import com.minelittlepony.unicopia.entity.player.Pony;
|
|||
import com.minelittlepony.unicopia.particle.UParticles;
|
||||
import com.minelittlepony.unicopia.projectile.MagicProjectileEntity;
|
||||
import com.minelittlepony.unicopia.server.world.Ether;
|
||||
import com.minelittlepony.unicopia.util.CodecUtils;
|
||||
import com.minelittlepony.unicopia.util.NbtSerialisable;
|
||||
import com.minelittlepony.unicopia.util.shape.*;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.fluid.*;
|
||||
import net.minecraft.nbt.*;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.registry.tag.TagKey;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -129,16 +133,16 @@ public class HydrophobicSpell extends AbstractSpell {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
compound.put("storedFluidPositions", Entry.SERIALIZER.writeAll(storedFluidPositions));
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
compound.put("storedFluidPositions", NbtSerialisable.encode(Entry.SET_CODEC, storedFluidPositions));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
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.
|
||||
|
@ -152,15 +156,11 @@ public class HydrophobicSpell extends AbstractSpell {
|
|||
}
|
||||
|
||||
record Entry (BlockPos pos, BlockState blockState) {
|
||||
public static final Serializer<Entry> SERIALIZER = Serializer.of(compound -> new Entry(
|
||||
NbtSerialisable.BLOCK_POS.read(compound.getCompound("pos")),
|
||||
NbtSerialisable.decode(BlockState.CODEC, compound.get("blockState")).orElse(Blocks.AIR.getDefaultState())
|
||||
), entry -> {
|
||||
NbtCompound compound = new NbtCompound();
|
||||
compound.put("pos", NbtSerialisable.BLOCK_POS.write(entry.pos));
|
||||
compound.put("blockState", NbtSerialisable.encode(BlockState.CODEC, entry.blockState));
|
||||
return compound;
|
||||
});
|
||||
public static final Codec<Entry> CODEC = RecordCodecBuilder.create(instance -> instance.group(
|
||||
BlockPos.CODEC.fieldOf("pos").forGetter(Entry::pos),
|
||||
BlockState.CODEC.optionalFieldOf("blockState", Blocks.AIR.getDefaultState()).forGetter(Entry::blockState)
|
||||
).apply(instance, Entry::new));
|
||||
public static final Codec<Set<Entry>> SET_CODEC = CodecUtils.setOf(CODEC);
|
||||
|
||||
void restore(World world) {
|
||||
BlockState state = world.getBlockState(pos);
|
||||
|
|
|
@ -24,6 +24,7 @@ import com.minelittlepony.unicopia.util.VecHelper;
|
|||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
|
||||
public class LightSpell extends AbstractSpell implements TimedSpell, ProjectileDelegate.HitListener {
|
||||
|
@ -109,26 +110,26 @@ public class LightSpell extends AbstractSpell implements TimedSpell, ProjectileD
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
timer.toNBT(compound);
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
timer.toNBT(compound, lookup);
|
||||
if (!lights.isEmpty()) {
|
||||
NbtList list = new NbtList();
|
||||
lights.forEach(light -> {
|
||||
list.add(light.toNBT());
|
||||
list.add(light.toNBT(lookup));
|
||||
});
|
||||
compound.put("lights", list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
timer.fromNBT(compound);
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
timer.fromNBT(compound, lookup);
|
||||
lights.clear();
|
||||
if (compound.contains("lights", NbtElement.LIST_TYPE)) {
|
||||
compound.getList("lights", NbtElement.COMPOUND_TYPE).forEach(nbt -> {
|
||||
lights.add(new EntityReference<>((NbtCompound)nbt));
|
||||
lights.add(new EntityReference<>((NbtCompound)nbt, lookup));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,6 +6,7 @@ import com.minelittlepony.unicopia.ability.magic.spell.attribute.TooltipFactory;
|
|||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
|
||||
public class MimicSpell extends AbstractDisguiseSpell implements HomingSpell, TimedSpell {
|
||||
|
||||
|
@ -40,14 +41,14 @@ public class MimicSpell extends AbstractDisguiseSpell implements HomingSpell, Ti
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
timer.toNBT(compound);
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
timer.toNBT(compound, lookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
timer.fromNBT(compound);
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
timer.fromNBT(compound, lookup);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -25,6 +25,7 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.world.GameMode;
|
||||
|
@ -192,18 +193,18 @@ public class MindSwapSpell extends MimicSpell implements ProjectileDelegate.Enti
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
compound.put("counterpart", counterpart.toNBT());
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
compound.put("counterpart", counterpart.toNBT(lookup));
|
||||
compound.putBoolean("initialized", initialized);
|
||||
myStoredInventory.ifPresent(mine -> compound.put("myStoredInventory", mine.toNBT(new NbtCompound())));
|
||||
theirStoredInventory.ifPresent(mine -> compound.put("theirStoredInventory", mine.toNBT(new NbtCompound())));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
counterpart.fromNBT(compound.getCompound("counterpart"));
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
counterpart.fromNBT(compound.getCompound("counterpart"), lookup);
|
||||
initialized = compound.getBoolean("initialized");
|
||||
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);
|
||||
|
|
|
@ -35,6 +35,7 @@ import net.minecraft.nbt.NbtCompound;
|
|||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.nbt.NbtList;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.hit.EntityHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -217,24 +218,24 @@ public class NecromancySpell extends AbstractAreaEffectSpell implements Projecti
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
compound.putInt("spawnCountdown", spawnCountdown);
|
||||
if (summonedEntities.size() > 0) {
|
||||
NbtList list = new NbtList();
|
||||
summonedEntities.forEach(ref -> list.add(ref.toNBT()));
|
||||
summonedEntities.forEach(ref -> list.add(ref.toNBT(lookup)));
|
||||
compound.put("summonedEntities", list);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
spawnCountdown = compound.getInt("spawnCountdown");
|
||||
summonedEntities.clear();
|
||||
if (compound.contains("summonedEntities")) {
|
||||
compound.getList("summonedEntities", NbtElement.COMPOUND_TYPE).forEach(tag -> {
|
||||
summonedEntities.add(new EntityReference<>((NbtCompound)tag));
|
||||
summonedEntities.add(new EntityReference<>((NbtCompound)tag, lookup));
|
||||
});
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,6 +26,7 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.network.packet.s2c.play.PositionFlag;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.Util;
|
||||
|
@ -226,10 +227,10 @@ public class PortalSpell extends AbstractSpell implements PlacementControlSpell.
|
|||
}
|
||||
|
||||
@Override
|
||||
public void toNBT(NbtCompound compound) {
|
||||
super.toNBT(compound);
|
||||
public void toNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.toNBT(compound, lookup);
|
||||
compound.putUuid("targetPortalId", targetPortalId.get());
|
||||
compound.put("teleportationTarget", teleportationTarget.toNBT());
|
||||
compound.put("teleportationTarget", teleportationTarget.toNBT(lookup));
|
||||
compound.putFloat("pitch", getPitch());
|
||||
compound.putFloat("yaw", getYaw());
|
||||
compound.putFloat("targetPortalPitch", getTargetPitch());
|
||||
|
@ -237,10 +238,10 @@ public class PortalSpell extends AbstractSpell implements PlacementControlSpell.
|
|||
}
|
||||
|
||||
@Override
|
||||
public void fromNBT(NbtCompound compound) {
|
||||
super.fromNBT(compound);
|
||||
public void fromNBT(NbtCompound compound, WrapperLookup lookup) {
|
||||
super.fromNBT(compound, lookup);
|
||||
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"));
|
||||
yaw.set(compound.getFloat("yaw"));
|
||||
targetPortalPitch.set(compound.getFloat("targetPortalPitch"));
|
||||
|
|
|
@ -35,6 +35,8 @@ import net.minecraft.nbt.NbtCompound;
|
|||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.nbt.NbtOps;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.network.RegistryByteBuf;
|
||||
import net.minecraft.network.codec.PacketCodec;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
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)),
|
||||
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) {
|
||||
REGISTRY = newRegistry;
|
||||
|
@ -169,6 +172,7 @@ public final class SpellTraits implements Iterable<Map.Entry<Trait, Float>> {
|
|||
return nbt;
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public void write(PacketByteBuf buf) {
|
||||
buf.writeInt(traits.size());
|
||||
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);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static Optional<SpellTraits> fromPacketOrEmpty(PacketByteBuf buf) {
|
||||
return buf.readOptional(SpellTraits::fromPacket).filter(SpellTraits::isPresent);
|
||||
}
|
||||
|
||||
@Deprecated
|
||||
public static SpellTraits fromPacket(PacketByteBuf buf) {
|
||||
Map<Trait, Float> entries = new HashMap<>();
|
||||
int count = buf.readInt();
|
||||
|
|
|
@ -16,7 +16,6 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.predicate.entity.EntityPredicate;
|
||||
import net.minecraft.predicate.entity.LootContextPredicate;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.dynamic.Codecs;
|
||||
|
||||
public class CustomEventCriterion extends AbstractCriterion<CustomEventCriterion.Conditions> {
|
||||
@Override
|
||||
|
@ -61,7 +60,7 @@ public class CustomEventCriterion extends AbstractCriterion<CustomEventCriterion
|
|||
TriState flying,
|
||||
int repeatCount) implements AbstractCriterion.Conditions {
|
||||
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),
|
||||
RacePredicate.CODEC.optionalFieldOf("races", RacePredicate.EMPTY).forGetter(Conditions::races),
|
||||
CodecUtils.tristateOf("flying").forGetter(Conditions::flying),
|
||||
|
|
|
@ -12,7 +12,6 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||
import net.minecraft.predicate.entity.EntityPredicate;
|
||||
import net.minecraft.predicate.entity.LootContextPredicate;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.dynamic.Codecs;
|
||||
|
||||
public class RaceChangeCriterion extends AbstractCriterion<RaceChangeCriterion.Conditions> {
|
||||
@Override
|
||||
|
@ -31,7 +30,7 @@ public class RaceChangeCriterion extends AbstractCriterion<RaceChangeCriterion.C
|
|||
Race race
|
||||
) implements AbstractCriterion.Conditions {
|
||||
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)
|
||||
).apply(instance, Conditions::new));
|
||||
|
||||
|
|
|
@ -19,7 +19,6 @@ import net.minecraft.predicate.item.ItemPredicate;
|
|||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.TypeFilter;
|
||||
import net.minecraft.util.dynamic.Codecs;
|
||||
|
||||
public class SendViaDragonBreathScrollCriterion extends AbstractCriterion<SendViaDragonBreathScrollCriterion.Conditions> {
|
||||
@Override
|
||||
|
@ -57,7 +56,7 @@ public class SendViaDragonBreathScrollCriterion extends AbstractCriterion<SendVi
|
|||
RacePredicate races
|
||||
) implements AbstractCriterion.Conditions {
|
||||
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),
|
||||
Codec.BOOL.optionalFieldOf("is_receiving_end", false).forGetter(Conditions::isReceivingEnd),
|
||||
Codec.STRING.optionalFieldOf("recipient_name").forGetter(Conditions::recipientName),
|
||||
|
|
|
@ -14,7 +14,6 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||
import net.minecraft.predicate.entity.EntityPredicate;
|
||||
import net.minecraft.predicate.entity.LootContextPredicate;
|
||||
import net.minecraft.server.network.ServerPlayerEntity;
|
||||
import net.minecraft.util.dynamic.Codecs;
|
||||
|
||||
public class TraitDiscoveredCriterion extends AbstractCriterion<TraitDiscoveredCriterion.Conditions> {
|
||||
@Override
|
||||
|
@ -34,7 +33,7 @@ public class TraitDiscoveredCriterion extends AbstractCriterion<TraitDiscoveredC
|
|||
|
||||
public record Conditions(Optional<LootContextPredicate> player, Set<Trait> traits) implements AbstractCriterion.Conditions {
|
||||
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)
|
||||
).apply(instance, Conditions::new));
|
||||
|
||||
|
|
|
@ -7,7 +7,7 @@ import net.minecraft.block.ButtonBlock;
|
|||
import net.minecraft.block.LeavesBlock;
|
||||
import net.minecraft.block.MapColor;
|
||||
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.entity.EntityType;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
|
@ -29,11 +29,11 @@ public interface BlockConstructionUtils {
|
|||
}
|
||||
|
||||
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) {
|
||||
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) {
|
||||
|
|
|
@ -24,13 +24,14 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.property.Properties;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ItemActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
@ -98,33 +99,32 @@ public class CrystalDoorBlock extends DoorBlock implements BlockEntityProvider {
|
|||
}
|
||||
|
||||
@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 (isLocked(world, pos) || !player.getStackInHand(hand).isOf(UItems.MEADOWBROOKS_STAFF)) {
|
||||
if (isLocked(world, pos) || !stack.isOf(UItems.MEADOWBROOKS_STAFF)) {
|
||||
playOpenCloseSound(player, world, pos, false);
|
||||
setOnGuard(state, world, pos, true);
|
||||
return ActionResult.CONSUME;
|
||||
return ItemActionResult.CONSUME;
|
||||
} else {
|
||||
world.playSound(player, pos, USounds.ENTITY_CRYSTAL_SHARDS_AMBIENT, SoundCategory.BLOCKS, 1, world.getRandom().nextFloat() * 0.1F + 0.9F);
|
||||
}
|
||||
} else if (!isLocked(world, pos)) {
|
||||
ItemStack heldStack = player.getStackInHand(hand);
|
||||
if (heldStack.isOf(UItems.FRIENDSHIP_BRACELET)) {
|
||||
if (stack.isOf(UItems.FRIENDSHIP_BRACELET)) {
|
||||
@Nullable
|
||||
UUID signator = FriendshipBraceletItem.getSignatorId(heldStack);
|
||||
UUID signator = FriendshipBraceletItem.getSignatorId(stack);
|
||||
if (signator != null) {
|
||||
BlockEntityUtil.getOrCreateBlockEntity(world, state.get(HALF) == DoubleBlockHalf.LOWER ? pos.up() : pos, UBlockEntities.CRYSTAL_DOOR).ifPresent(data -> {
|
||||
data.setSignator(signator);
|
||||
setOnGuard(state, world, pos, true);
|
||||
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 {
|
||||
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) {
|
||||
|
@ -178,12 +178,12 @@ public class CrystalDoorBlock extends DoorBlock implements BlockEntityProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void readNbt(NbtCompound nbt) {
|
||||
public void readNbt(NbtCompound nbt, WrapperLookup lookup) {
|
||||
signator = nbt.containsUuid("signator") ? nbt.getUuid("signator") : null;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeNbt(NbtCompound nbt) {
|
||||
protected void writeNbt(NbtCompound nbt, WrapperLookup lookup) {
|
||||
if (signator != null) {
|
||||
nbt.putUuid("signator", signator);
|
||||
}
|
||||
|
|
|
@ -1,7 +1,5 @@
|
|||
package com.minelittlepony.unicopia.block;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import com.minelittlepony.unicopia.ability.EarthPonyGrowAbility.Growable;
|
||||
import com.minelittlepony.unicopia.entity.mob.IgnominiousBulbEntity;
|
||||
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.FlowerBlock;
|
||||
import net.minecraft.block.SuspiciousStewIngredient;
|
||||
import net.minecraft.client.util.ParticleUtil;
|
||||
import net.minecraft.component.type.SuspiciousStewEffectsComponent;
|
||||
import net.minecraft.particle.ParticleUtil;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.entity.Dismounting;
|
||||
import net.minecraft.entity.effect.StatusEffect;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -24,11 +23,11 @@ public class CuringJokeBlock extends FlowerBlock implements Growable {
|
|||
FlowerBlock.createSettingsCodec()
|
||||
).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);
|
||||
}
|
||||
|
||||
protected CuringJokeBlock(List<SuspiciousStewIngredient.StewEffect> effects, Settings settings) {
|
||||
protected CuringJokeBlock(SuspiciousStewEffectsComponent effects, Settings settings) {
|
||||
super(effects, settings);
|
||||
}
|
||||
|
||||
|
|
|
@ -17,6 +17,7 @@ import net.minecraft.block.BlockState;
|
|||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.block.HayBlock;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.registry.Registries;
|
||||
|
@ -27,6 +28,7 @@ import net.minecraft.state.property.BooleanProperty;
|
|||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.ItemActionResult;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -94,10 +96,18 @@ public class EdibleBlock extends HayBlock {
|
|||
for (EdibleBlock edibleBlock : REGISTRY) {
|
||||
Block match = edibleBlock.getBaseBlock();
|
||||
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()) {
|
||||
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
|
||||
@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()) {
|
||||
return ActionResult.FAIL;
|
||||
return ItemActionResult.FAIL;
|
||||
}
|
||||
|
||||
ItemStack stack = player.getStackInHand(hand);
|
||||
|
||||
if (!stack.isEmpty() && stack.isOf(Registries.ITEM.get(material))) {
|
||||
BooleanProperty segment = getHitCorner(hit, 1);
|
||||
|
||||
|
@ -167,23 +175,23 @@ public class EdibleBlock extends HayBlock {
|
|||
}
|
||||
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);
|
||||
|
||||
if (!state.get(corner)) {
|
||||
return ActionResult.PASS;
|
||||
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
|
||||
}
|
||||
|
||||
boolean usingHoe = stack.isIn(ItemTags.HOES);
|
||||
|
||||
if (!usingHoe) {
|
||||
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) {
|
||||
stack.damage(1, player, p -> p.sendToolBreakStatus(hand));
|
||||
stack.damage(1, player, LivingEntity.getSlotForHand(hand));
|
||||
dropStack(world, pos, Registries.ITEM.get(material).getDefaultStack());
|
||||
player.playSound(USounds.Vanilla.ITEM_HOE_TILL, 1, 1);
|
||||
} else {
|
||||
|
@ -207,7 +215,7 @@ public class EdibleBlock extends HayBlock {
|
|||
}
|
||||
player.getHungerManager().add(2, 1.3F);
|
||||
}
|
||||
return ActionResult.SUCCESS;
|
||||
return ItemActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
static BooleanProperty getHitCorner(BlockHitResult hit, int direction) {
|
||||
|
|
|
@ -24,6 +24,7 @@ import net.minecraft.entity.mob.PiglinBrain;
|
|||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.registry.tag.BlockTags;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.DyeColor;
|
||||
|
@ -150,18 +151,18 @@ public class FancyBedBlock extends BedBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void readNbt(NbtCompound nbt) {
|
||||
public void readNbt(NbtCompound nbt, WrapperLookup lookup) {
|
||||
pattern = SheetPattern.byId(nbt.getString("pattern"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeNbt(NbtCompound nbt) {
|
||||
protected void writeNbt(NbtCompound nbt, WrapperLookup lookup) {
|
||||
nbt.putString("pattern", pattern.asString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public NbtCompound toInitialChunkDataNbt() {
|
||||
return createNbt();
|
||||
public NbtCompound toInitialChunkDataNbt(WrapperLookup lookup) {
|
||||
return createNbt(lookup);
|
||||
}
|
||||
|
||||
public String getBase() {
|
||||
|
|
|
@ -34,13 +34,14 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||
import net.minecraft.nbt.NbtCompound;
|
||||
import net.minecraft.nbt.NbtElement;
|
||||
import net.minecraft.particle.ParticleTypes;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.registry.entry.RegistryEntry;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.property.Property;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Direction;
|
||||
|
@ -142,7 +143,7 @@ public class HiveBlock extends ConnectingBlock implements BlockEntityProvider {
|
|||
}
|
||||
|
||||
@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)) {
|
||||
world.setBlockState(pos, state.with(CONSUMING, true));
|
||||
if (!world.isClient) {
|
||||
|
@ -214,22 +215,22 @@ public class HiveBlock extends ConnectingBlock implements BlockEntityProvider {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void readNbt(NbtCompound nbt) {
|
||||
public void readNbt(NbtCompound nbt, WrapperLookup lookup) {
|
||||
opening = nbt.getBoolean("opening");
|
||||
closing = nbt.getBoolean("closing");
|
||||
storedBlocks.clear();
|
||||
if (nbt.contains("storedBlocks", NbtElement.LIST_TYPE)) {
|
||||
Entry.SERIALIZER.readAll(nbt.getList("storedBlocks", NbtElement.COMPOUND_TYPE)).forEach(entry -> {
|
||||
Entry.SERIALIZER.readAll(nbt.getList("storedBlocks", NbtElement.COMPOUND_TYPE), lookup).forEach(entry -> {
|
||||
storedBlocks.put(entry.pos(), entry);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeNbt(NbtCompound nbt) {
|
||||
protected void writeNbt(NbtCompound nbt, WrapperLookup lookup) {
|
||||
nbt.putBoolean("opening", opening);
|
||||
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) {
|
||||
|
@ -312,22 +313,23 @@ public class HiveBlock extends ConnectingBlock implements BlockEntityProvider {
|
|||
}
|
||||
|
||||
record Entry (BlockPos pos, BlockState state, @Nullable BlockEntity data) {
|
||||
public static final Serializer<Entry> SERIALIZER = Serializer.of(compound -> new Entry(
|
||||
NbtSerialisable.BLOCK_POS.read(compound.getCompound("pos")),
|
||||
public static final Serializer<NbtCompound, Entry> SERIALIZER = Serializer.of((compound, lookup) -> new Entry(
|
||||
NbtSerialisable.BLOCK_POS.read(compound.getCompound("pos"), lookup),
|
||||
NbtSerialisable.decode(BlockState.CODEC, compound.get("state")).orElse(Blocks.AIR.getDefaultState()),
|
||||
compound.getCompound("data")
|
||||
), entry -> {
|
||||
compound.getCompound("data"),
|
||||
lookup
|
||||
), (entry, lookup) -> {
|
||||
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()));
|
||||
if (entry.data() != null) {
|
||||
compound.put("data", entry.data().createNbtWithId());
|
||||
compound.put("data", entry.data().createNbtWithId(lookup));
|
||||
}
|
||||
return compound;
|
||||
});
|
||||
|
||||
Entry(BlockPos pos, BlockState state, NbtCompound nbt) {
|
||||
this(pos, state, BlockEntity.createFromNbt(pos, state, nbt));
|
||||
Entry(BlockPos pos, BlockState state, NbtCompound nbt, WrapperLookup lookup) {
|
||||
this(pos, state, BlockEntity.createFromNbt(pos, state, nbt, lookup));
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
|
@ -365,7 +367,7 @@ public class HiveBlock extends ConnectingBlock implements BlockEntityProvider {
|
|||
}
|
||||
|
||||
@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()))) {
|
||||
closing = true;
|
||||
markDirty();
|
||||
|
@ -374,7 +376,7 @@ public class HiveBlock extends ConnectingBlock implements BlockEntityProvider {
|
|||
return false;
|
||||
}
|
||||
|
||||
private boolean isImportant(GameEvent event) {
|
||||
private boolean isImportant(RegistryEntry<GameEvent> event) {
|
||||
return event == GameEvent.EXPLODE
|
||||
|| event == GameEvent.PRIME_FUSE
|
||||
|| event == GameEvent.SHRIEK;
|
||||
|
|
|
@ -25,9 +25,11 @@ import net.minecraft.nbt.NbtElement;
|
|||
import net.minecraft.network.listener.ClientPlayPacketListener;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ItemActionResult;
|
||||
import net.minecraft.util.TypedActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -52,11 +54,11 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven
|
|||
}
|
||||
|
||||
@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) {
|
||||
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
|
||||
|
@ -110,10 +112,10 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven
|
|||
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);
|
||||
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() {
|
||||
|
@ -146,8 +148,8 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven
|
|||
}
|
||||
|
||||
@Override
|
||||
public NbtCompound toInitialChunkDataNbt() {
|
||||
return createNbt();
|
||||
public NbtCompound toInitialChunkDataNbt(WrapperLookup lookup) {
|
||||
return createNbt(lookup);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -159,9 +161,9 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven
|
|||
}
|
||||
|
||||
@Override
|
||||
public void readNbt(NbtCompound nbt) {
|
||||
public void readNbt(NbtCompound nbt, WrapperLookup lookup) {
|
||||
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)) {
|
||||
contents = new EntityJarContents(this, nbt.getCompound("entity"));
|
||||
} else if (nbt.contains("fluid", NbtElement.COMPOUND_TYPE)) {
|
||||
|
@ -172,14 +174,14 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven
|
|||
}
|
||||
|
||||
@Override
|
||||
protected void writeNbt(NbtCompound nbt) {
|
||||
protected void writeNbt(NbtCompound nbt, WrapperLookup lookup) {
|
||||
var items = getItems();
|
||||
if (items != null) {
|
||||
nbt.put("items", items.toNBT(new NbtCompound()));
|
||||
nbt.put("items", items.toNBT(new NbtCompound(), lookup));
|
||||
} else if (getEntity() != null) {
|
||||
nbt.put("entity", getEntity().toNBT(new NbtCompound()));
|
||||
nbt.put("entity", getEntity().toNBT(new NbtCompound(), lookup));
|
||||
} else if (getFluid() != null) {
|
||||
nbt.put("fluid", getFluid().toNBT(new NbtCompound()));
|
||||
nbt.put("fluid", getFluid().toNBT(new NbtCompound(), lookup));
|
||||
} else if (getFakeFluid() != null) {
|
||||
nbt.put("fakeFluid", getFakeFluid().toNBT(new NbtCompound()));
|
||||
}
|
||||
|
@ -191,7 +193,7 @@ public class ItemJarBlock extends JarBlock implements BlockEntityProvider, Inven
|
|||
|
||||
void onDestroyed();
|
||||
|
||||
NbtCompound toNBT(NbtCompound compound);
|
||||
NbtCompound toNBT(NbtCompound compound, WrapperLookup lookup);
|
||||
|
||||
default void consumeAndSwap(PlayerEntity player, Hand hand, ItemStack output) {
|
||||
player.setStackInHand(hand, ItemUsage.exchangeStack(player.getStackInHand(hand), player, output.copy()));
|
||||
|
|
|
@ -20,8 +20,8 @@ import net.minecraft.sound.SoundCategory;
|
|||
import net.minecraft.stat.Stats;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.*;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ItemActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.*;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
|
@ -80,39 +80,38 @@ public class PieBlock extends Block implements Waterloggable {
|
|||
|
||||
@Deprecated
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||
ItemStack itemStack = player.getStackInHand(hand);
|
||||
public ItemActionResult onUseWithItem(ItemStack itemStack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||
|
||||
if (world.isClient) {
|
||||
|
||||
if (itemStack.isIn(UTags.Items.CAN_CUT_PIE)) {
|
||||
return ActionResult.SUCCESS;
|
||||
return ItemActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
if (tryEat(world, pos, state, player).isAccepted()) {
|
||||
return ActionResult.SUCCESS;
|
||||
return ItemActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
if (itemStack.isEmpty()) {
|
||||
return ActionResult.CONSUME;
|
||||
return ItemActionResult.CONSUME;
|
||||
}
|
||||
}
|
||||
|
||||
if (itemStack.isIn(UTags.Items.CAN_CUT_PIE)) {
|
||||
SoundEmitter.playSoundAt(player, USounds.BLOCK_PIE_SLICE, SoundCategory.NEUTRAL, 1, 1);
|
||||
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);
|
||||
Block.dropStack(world, pos, sliceItem.asItem().getDefaultStack());
|
||||
return ActionResult.SUCCESS;
|
||||
return ItemActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
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)) {
|
||||
return ActionResult.PASS;
|
||||
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
|
||||
}
|
||||
player.incrementStat(Stats.EAT_CAKE_SLICE);
|
||||
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);
|
||||
return ActionResult.SUCCESS;
|
||||
return ItemActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
protected void removeSlice(WorldAccess world, BlockPos pos, BlockState state, PlayerEntity player) {
|
||||
|
@ -232,7 +231,7 @@ public class PieBlock extends Block implements Waterloggable {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
|
||||
public boolean canPathfindThrough(BlockState state, NavigationType type) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,7 +17,6 @@ import net.minecraft.util.math.BlockPos;
|
|||
import net.minecraft.util.math.Box;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
import net.minecraft.world.WorldView;
|
||||
|
@ -95,7 +94,7 @@ public class SpikesBlock extends OrientedBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
|
||||
public boolean canPathfindThrough(BlockState state, NavigationType type) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,7 +35,6 @@ import com.minelittlepony.unicopia.item.UItems;
|
|||
import com.minelittlepony.unicopia.item.cloud.CloudBlockItem;
|
||||
import com.minelittlepony.unicopia.item.group.ItemGroupRegistry;
|
||||
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.FlammableBlockRegistry;
|
||||
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.AbstractBlock.Settings;
|
||||
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.item.*;
|
||||
import net.minecraft.sound.BlockSoundGroup;
|
||||
|
@ -69,7 +68,7 @@ public interface UBlocks {
|
|||
.strength(2)
|
||||
.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_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_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_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_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_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(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_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_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_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_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_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(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(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(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 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,
|
||||
() -> UBlocks.MANGO,
|
||||
() -> UItems.MANGO.getDefaultStack(),
|
||||
FabricBlockSettings.copy(Blocks.JUNGLE_LEAVES)
|
||||
Block.Settings.copy(Blocks.JUNGLE_LEAVES)
|
||||
), ItemGroups.NATURAL);
|
||||
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,
|
||||
() -> UBlocks.GREEN_APPLE,
|
||||
() -> UItems.GREEN_APPLE.getDefaultStack(),
|
||||
FabricBlockSettings.copy(Blocks.OAK_LEAVES)
|
||||
Block.Settings.copy(Blocks.OAK_LEAVES)
|
||||
), 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_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,
|
||||
() -> UBlocks.SWEET_APPLE,
|
||||
() -> UItems.SWEET_APPLE.getDefaultStack(),
|
||||
FabricBlockSettings.copy(Blocks.OAK_LEAVES)
|
||||
Block.Settings.copy(Blocks.OAK_LEAVES)
|
||||
), 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_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,
|
||||
() -> UBlocks.SOUR_APPLE,
|
||||
() -> UItems.SOUR_APPLE.getDefaultStack(),
|
||||
FabricBlockSettings.copy(Blocks.OAK_LEAVES)
|
||||
Block.Settings.copy(Blocks.OAK_LEAVES)
|
||||
), 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_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,
|
||||
() -> UBlocks.GOLDEN_APPLE,
|
||||
() -> Items.GOLDEN_APPLE.getDefaultStack(),
|
||||
FabricBlockSettings.copy(Blocks.OAK_LEAVES)
|
||||
Block.Settings.copy(Blocks.OAK_LEAVES)
|
||||
), 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_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 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_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 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 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) {
|
||||
return register(Unicopia.id(name), item);
|
||||
|
@ -290,8 +289,8 @@ public interface UBlocks {
|
|||
|
||||
static void bootstrap() {
|
||||
if (FabricLoader.getInstance().isModLoaded("farmersdelight")) {
|
||||
register("rice_block", new EdibleBlock(new Identifier("farmersdelight", "rice_bale"), new Identifier("farmersdelight", "rice_panicle"), true));
|
||||
register("straw_block", new EdibleBlock(new Identifier("farmersdelight", "straw_bale"), new Identifier("farmersdelight", "straw"), true));
|
||||
register("rice_block", new EdibleBlock(Identifier.of("farmersdelight", "rice_bale"), Identifier.of("farmersdelight", "rice_panicle"), 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.HANGING_SIGN).addSupportedBlocks(PALM_HANGING_SIGN, PALM_WALL_HANGING_SIGN);
|
||||
|
|
|
@ -14,6 +14,7 @@ import net.minecraft.nbt.NbtCompound;
|
|||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.listener.ClientPlayPacketListener;
|
||||
import net.minecraft.network.packet.s2c.play.BlockEntityUpdateS2CPacket;
|
||||
import net.minecraft.registry.RegistryWrapper.WrapperLookup;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.util.math.*;
|
||||
|
@ -73,13 +74,13 @@ public class WeatherVaneBlock extends BlockWithEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void readNbt(NbtCompound nbt) {
|
||||
public void readNbt(NbtCompound nbt, WrapperLookup lookup) {
|
||||
angle = nbt.getFloat("angle");
|
||||
airflow = new Vec3d(nbt.getDouble("windX"), 0, nbt.getDouble("windZ"));
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void writeNbt(NbtCompound nbt) {
|
||||
protected void writeNbt(NbtCompound nbt, WrapperLookup lookup) {
|
||||
nbt.putFloat("angle", angle);
|
||||
nbt.putDouble("windX", airflow.x);
|
||||
nbt.putDouble("windZ", airflow.z);
|
||||
|
@ -91,8 +92,8 @@ public class WeatherVaneBlock extends BlockWithEntity {
|
|||
}
|
||||
|
||||
@Override
|
||||
public NbtCompound toInitialChunkDataNbt() {
|
||||
return createNbt();
|
||||
public NbtCompound toInitialChunkDataNbt(WrapperLookup lookup) {
|
||||
return createNbt(lookup);
|
||||
}
|
||||
|
||||
public static void serverTick(World world, BlockPos pos, BlockState state, WeatherVane entity) {
|
||||
|
|
|
@ -15,8 +15,9 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.ai.pathing.NavigationType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ItemActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
|
@ -76,11 +77,11 @@ public class CloudBedBlock extends FancyBedBlock implements CloudLike {
|
|||
}
|
||||
|
||||
@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))) {
|
||||
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
|
||||
|
@ -91,7 +92,7 @@ public class CloudBedBlock extends FancyBedBlock implements CloudLike {
|
|||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
|
||||
return baseState.canPathfindThrough(world, pos, type);
|
||||
public boolean canPathfindThrough(BlockState state, NavigationType type) {
|
||||
return baseState.canPathfindThrough(type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -187,7 +187,7 @@ public class CloudBlock extends Block implements CloudLike {
|
|||
|
||||
@Override
|
||||
@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());
|
||||
return type != NavigationType.LAND || !InteractionManager.getInstance().getPathingEquineContext().collidesWithClouds();
|
||||
}
|
||||
|
@ -200,7 +200,6 @@ public class CloudBlock extends Block implements CloudLike {
|
|||
return context.collidesWithClouds() || context.hasFeatherTouch();
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
protected boolean canReplace(BlockState state, ItemPlacementContext context, EquineContext equineContext) {
|
||||
return super.canReplace(state, context);
|
||||
}
|
||||
|
|
|
@ -24,12 +24,13 @@ import net.minecraft.entity.player.PlayerEntity;
|
|||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.inventory.DoubleInventory;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.screen.GenericContainerScreenHandler;
|
||||
import net.minecraft.screen.NamedScreenHandlerFactory;
|
||||
import net.minecraft.screen.ScreenHandler;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ItemActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
|
@ -137,11 +138,11 @@ public class CloudChestBlock extends ChestBlock implements CloudLike {
|
|||
}
|
||||
|
||||
@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))) {
|
||||
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
|
||||
|
@ -152,7 +153,7 @@ public class CloudChestBlock extends ChestBlock implements CloudLike {
|
|||
|
||||
@Override
|
||||
@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();
|
||||
}
|
||||
|
||||
|
|
|
@ -16,8 +16,9 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.ai.pathing.NavigationType;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemPlacementContext;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ItemActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
|
@ -79,11 +80,11 @@ public class CloudDoorBlock extends DoorBlock implements CloudLike {
|
|||
}
|
||||
|
||||
@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))) {
|
||||
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
|
||||
|
@ -100,7 +101,7 @@ public class CloudDoorBlock extends DoorBlock implements CloudLike {
|
|||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
|
||||
return !InteractionManager.getInstance().getPathingEquineContext().collidesWithClouds() || super.canPathfindThrough(state, world, pos, type);
|
||||
public boolean canPathfindThrough(BlockState state, NavigationType type) {
|
||||
return !InteractionManager.getInstance().getPathingEquineContext().collidesWithClouds() || super.canPathfindThrough(state, type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -108,7 +108,7 @@ public class CloudStairsBlock extends StairsBlock implements CloudLike {
|
|||
|
||||
@Override
|
||||
@Deprecated
|
||||
public boolean canPathfindThrough(BlockState state, BlockView world, BlockPos pos, NavigationType type) {
|
||||
return baseBlock.canPathfindThrough(state, world, pos, type);
|
||||
public boolean canPathfindThrough(BlockState state, NavigationType type) {
|
||||
return baseBlock.canPathfindThrough(state, type);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,6 +12,7 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.block.ConnectingBlock;
|
||||
import net.minecraft.block.ShapeContext;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.registry.tag.ItemTags;
|
||||
|
@ -20,10 +21,10 @@ import net.minecraft.sound.SoundEvents;
|
|||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.state.property.Property;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.BlockMirror;
|
||||
import net.minecraft.util.BlockRotation;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ItemActionResult;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -82,20 +83,19 @@ public class CompactedCloudBlock extends CloudBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||
ItemStack stack = player.getStackInHand(hand);
|
||||
public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||
|
||||
if (stack.isIn(ItemTags.SHOVELS)) {
|
||||
BooleanProperty property = FACING_PROPERTIES.get(hit.getSide());
|
||||
if (state.get(property)) {
|
||||
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);
|
||||
return ActionResult.SUCCESS;
|
||||
return ItemActionResult.SUCCESS;
|
||||
}
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -12,6 +12,7 @@ import com.mojang.serialization.codecs.RecordCodecBuilder;
|
|||
import net.minecraft.block.BedBlock;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockState;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.registry.Registries;
|
||||
|
@ -19,8 +20,8 @@ import net.minecraft.registry.tag.ItemTags;
|
|||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.state.property.BooleanProperty;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ItemActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
@ -49,17 +50,15 @@ public class NaturalCloudBlock extends PoreousCloudBlock {
|
|||
}
|
||||
|
||||
@Override
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||
ItemStack stack = player.getStackInHand(hand);
|
||||
|
||||
public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||
if (stack.isIn(ItemTags.SHOVELS)) {
|
||||
BooleanProperty property = CompactedCloudBlock.FACING_PROPERTIES.get(hit.getSide());
|
||||
world.setBlockState(pos, compactedBlock.get().getDefaultState().with(property, false));
|
||||
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);
|
||||
return ActionResult.SUCCESS;
|
||||
return ItemActionResult.SUCCESS;
|
||||
}
|
||||
|
||||
return ActionResult.PASS;
|
||||
return ItemActionResult.PASS_TO_DEFAULT_BLOCK_INTERACTION;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -15,7 +15,6 @@ import net.minecraft.screen.ScreenHandlerContext;
|
|||
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
|
||||
import net.minecraft.stat.Stats;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.shape.VoxelShape;
|
||||
|
@ -50,7 +49,7 @@ public class ShapingBenchBlock extends CloudBlock {
|
|||
}
|
||||
|
||||
@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) {
|
||||
return ActionResult.SUCCESS;
|
||||
}
|
||||
|
|
|
@ -17,8 +17,8 @@ import net.minecraft.server.world.ServerWorld;
|
|||
import net.minecraft.sound.SoundCategory;
|
||||
import net.minecraft.sound.SoundEvents;
|
||||
import net.minecraft.state.property.IntProperty;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ItemActionResult;
|
||||
import net.minecraft.util.Util;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
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) {
|
||||
ItemStack stack = player.getStackInHand(hand);
|
||||
if (stack.getItem() == Items.GLASS_BOTTLE) {
|
||||
if (!player.isCreative()) {
|
||||
stack.split(1);
|
||||
|
@ -67,11 +66,11 @@ public interface Soakable {
|
|||
world.emitGameEvent(player, GameEvent.FLUID_PICKUP, pos);
|
||||
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) {
|
||||
|
|
|
@ -17,8 +17,8 @@ import net.minecraft.item.ItemStack;
|
|||
import net.minecraft.registry.Registries;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.state.StateManager;
|
||||
import net.minecraft.util.ActionResult;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.ItemActionResult;
|
||||
import net.minecraft.util.hit.BlockHitResult;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.random.Random;
|
||||
|
@ -66,8 +66,8 @@ public class SoggyCloudBlock extends CloudBlock implements Soakable {
|
|||
|
||||
@Override
|
||||
@Deprecated
|
||||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||
return Soakable.tryCollectMoisture(state, world, pos, player, hand, hit);
|
||||
public ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
|
||||
return Soakable.tryCollectMoisture(stack, state, world, pos, player, hand, hit);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue