mirror of
https://github.com/Ellpeck/NaturesAura.git
synced 2024-12-22 06:59:22 +01:00
IT COMPILES!!
This commit is contained in:
parent
e50d3fc69a
commit
32baa1194b
23 changed files with 312 additions and 248 deletions
|
@ -125,6 +125,7 @@ tasks.withType(ProcessResources).configureEach {
|
|||
loader_version_range: loader_version_range,
|
||||
mod_id : mod_id, mod_name: mod_name, mod_license: mod_license, mod_version: mod_version,
|
||||
mod_authors : mod_authors, mod_description: mod_description,
|
||||
patchouli_version : patchouli_version
|
||||
]
|
||||
inputs.properties replaceProperties
|
||||
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package de.ellpeck.naturesaura;
|
||||
|
||||
import com.mojang.blaze3d.vertex.VertexConsumer;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import de.ellpeck.naturesaura.api.aura.container.IAuraContainer;
|
||||
import de.ellpeck.naturesaura.api.aura.item.IAuraRecharge;
|
||||
import de.ellpeck.naturesaura.api.misc.ILevelData;
|
||||
|
@ -13,6 +15,7 @@ import net.minecraft.client.Minecraft;
|
|||
import net.minecraft.client.gui.GuiGraphics;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.nbt.IntArrayTag;
|
||||
import net.minecraft.nbt.Tag;
|
||||
|
@ -356,14 +359,13 @@ public final class Helper {
|
|||
}
|
||||
|
||||
public static boolean isToolEnabled(ItemStack stack) {
|
||||
return stack.hasTag() && !stack.getTag().getBoolean(NaturesAura.MOD_ID + ":disabled");
|
||||
return stack.has(DisableableToolData.TYPE) && !stack.get(DisableableToolData.TYPE).disabled;
|
||||
}
|
||||
|
||||
public static boolean toggleToolEnabled(Player player, ItemStack stack) {
|
||||
if (!player.isShiftKeyDown())
|
||||
return false;
|
||||
var disabled = !Helper.isToolEnabled(stack);
|
||||
stack.getOrCreateTag().putBoolean(NaturesAura.MOD_ID + ":disabled", !disabled);
|
||||
stack.set(DisableableToolData.TYPE, new DisableableToolData(Helper.isToolEnabled(stack)));
|
||||
player.level().playSound(null, player.getX() + 0.5, player.getY() + 0.5, player.getZ() + 0.5, SoundEvents.ARROW_HIT_PLAYER, SoundSource.PLAYERS, 0.65F, 1F);
|
||||
return true;
|
||||
}
|
||||
|
@ -377,4 +379,13 @@ public final class Helper {
|
|||
return null;
|
||||
}
|
||||
|
||||
public record DisableableToolData(boolean disabled) {
|
||||
|
||||
public static final Codec<DisableableToolData> CODEC = RecordCodecBuilder.create(i -> i.group(
|
||||
Codec.BOOL.fieldOf("disabled").forGetter(d -> d.disabled)
|
||||
).apply(i, DisableableToolData::new));
|
||||
public static final DataComponentType<DisableableToolData> TYPE = DataComponentType.<DisableableToolData>builder().persistent(DisableableToolData.CODEC).cacheEncoding().build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,9 @@
|
|||
package de.ellpeck.naturesaura.api.aura.container;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
|
||||
public class ItemAuraContainer implements IAuraContainer {
|
||||
|
@ -37,16 +39,13 @@ public class ItemAuraContainer implements IAuraContainer {
|
|||
}
|
||||
|
||||
private void setAura(int amount) {
|
||||
if (!this.stack.hasTag()) {
|
||||
this.stack.setTag(new CompoundTag());
|
||||
}
|
||||
this.stack.getTag().putInt("aura", amount);
|
||||
this.stack.set(Data.TYPE, new Data(amount));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getStoredAura() {
|
||||
if (this.stack.hasTag()) {
|
||||
return this.stack.getTag().getInt("aura");
|
||||
if (this.stack.has(Data.TYPE)) {
|
||||
return this.stack.get(Data.TYPE).auraAmount;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
|
@ -66,4 +65,14 @@ public class ItemAuraContainer implements IAuraContainer {
|
|||
public boolean isAcceptableType(IAuraType type) {
|
||||
return this.type == null || this.type == type;
|
||||
}
|
||||
|
||||
public record Data(int auraAmount) {
|
||||
|
||||
public static final Codec<Data> CODEC = RecordCodecBuilder.create(i -> i.group(
|
||||
Codec.INT.fieldOf("aura_amount").forGetter(d -> d.auraAmount)
|
||||
).apply(i, Data::new));
|
||||
public static final DataComponentType<Data> TYPE = DataComponentType.<Data>builder().persistent(Data.CODEC).cacheEncoding().build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package de.ellpeck.naturesaura.blocks;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import de.ellpeck.naturesaura.api.misc.ILevelData;
|
||||
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEnderCrate;
|
||||
|
@ -13,29 +15,26 @@ import net.minecraft.ChatFormatting;
|
|||
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
|
||||
import net.minecraft.client.resources.language.I18n;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.RandomSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Items;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.BlockGetter;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.level.block.SoundType;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.BlockHitResult;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.event.AnvilUpdateEvent;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.List;
|
||||
|
||||
public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider<BlockEntityEnderCrate>, ICustomBlockState {
|
||||
|
@ -47,9 +46,9 @@ public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider
|
|||
}
|
||||
|
||||
public static String getEnderName(ItemStack stack) {
|
||||
if (!stack.hasTag())
|
||||
if (!stack.has(Data.TYPE))
|
||||
return "";
|
||||
return stack.getTag().getString(NaturesAura.MOD_ID + ":ender_name");
|
||||
return stack.get(Data.TYPE).enderName;
|
||||
}
|
||||
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
|
@ -79,7 +78,7 @@ public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider
|
|||
if (ILevelData.getOverworldData(player.level()).isEnderStorageLocked(name))
|
||||
return;
|
||||
var output = stack.copy();
|
||||
output.getOrCreateTag().putString(NaturesAura.MOD_ID + ":ender_name", name);
|
||||
output.set(Data.TYPE, new Data(name));
|
||||
event.setOutput(output);
|
||||
event.setMaterialCost(stack.getCount());
|
||||
event.setCost(1);
|
||||
|
@ -131,4 +130,13 @@ public class BlockEnderCrate extends BlockContainerImpl implements ITESRProvider
|
|||
BlockEntityRenderers.register(ModBlockEntities.ENDER_CRATE, RenderEnderCrate::new);
|
||||
}
|
||||
|
||||
public record Data(String enderName) {
|
||||
|
||||
public static final Codec<Data> CODEC = RecordCodecBuilder.create(i -> i.group(
|
||||
Codec.STRING.fieldOf("name").forGetter(d -> d.enderName)
|
||||
).apply(i, Data::new));
|
||||
public static final DataComponentType<Data> TYPE = DataComponentType.<Data>builder().persistent(Data.CODEC).cacheEncoding().build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -93,11 +93,8 @@ public class BlockEntityEnderCrate extends BlockEntityImpl implements MenuProvid
|
|||
|
||||
@Override
|
||||
public void modifyDrop(ItemStack regularItem) {
|
||||
if (this.name != null) {
|
||||
if (!regularItem.hasTag())
|
||||
regularItem.setTag(new CompoundTag());
|
||||
regularItem.getTag().putString(NaturesAura.MOD_ID + ":ender_name", this.name);
|
||||
}
|
||||
if (this.name != null)
|
||||
regularItem.set(BlockEnderCrate.Data.TYPE, new BlockEnderCrate.Data(this.name));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -4,7 +4,7 @@ import com.google.common.primitives.Ints;
|
|||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.core.component.DataComponents;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.item.ItemEntity;
|
||||
|
@ -57,35 +57,33 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
|
|||
}
|
||||
|
||||
if (this.trackedEntity != null && !this.trackedEntity.isAlive()) {
|
||||
if (this.trackedItem.hasTag()) {
|
||||
if (this.trackedItem.has(DataComponents.FIREWORKS)) {
|
||||
float generateFactor = 0;
|
||||
Set<Integer> usedColors = new HashSet<>();
|
||||
|
||||
var compound = this.trackedItem.getTag();
|
||||
var fireworks = compound.getCompound("Fireworks");
|
||||
var fireworks = this.trackedItem.get(DataComponents.FIREWORKS);
|
||||
|
||||
var flightTime = fireworks.getInt("Flight");
|
||||
var explosions = fireworks.getList("Explosions", 10);
|
||||
var flightTime = fireworks.flightDuration();
|
||||
var explosions = fireworks.explosions();
|
||||
if (!explosions.isEmpty()) {
|
||||
generateFactor += flightTime;
|
||||
|
||||
for (var base : explosions) {
|
||||
var explosion = (CompoundTag) base;
|
||||
for (var explosion : explosions) {
|
||||
generateFactor += 1.5F;
|
||||
|
||||
var flicker = explosion.getBoolean("Flicker");
|
||||
var flicker = explosion.hasTwinkle();
|
||||
if (flicker)
|
||||
generateFactor += 1;
|
||||
|
||||
var trail = explosion.getBoolean("Trail");
|
||||
var trail = explosion.hasTrail();
|
||||
if (trail)
|
||||
generateFactor += 8;
|
||||
|
||||
var type = explosion.getByte("Type");
|
||||
generateFactor += new float[]{0, 1, 0.5F, 20, 0.5F}[type];
|
||||
var type = explosion.shape();
|
||||
generateFactor += new float[]{0, 1, 0.5F, 20, 0.5F}[type.getId()];
|
||||
|
||||
Set<Integer> colors = new HashSet<>();
|
||||
for (var color : explosion.getIntArray("Colors")) {
|
||||
for (var color : explosion.colors()) {
|
||||
usedColors.add(color);
|
||||
colors.add(color);
|
||||
}
|
||||
|
@ -106,8 +104,8 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
|
|||
data.add(this.worldPosition.getZ());
|
||||
data.addAll(usedColors);
|
||||
PacketHandler.sendToAllLoaded(this.level, this.worldPosition, new PacketParticles(
|
||||
(float) this.trackedEntity.getX(), (float) this.trackedEntity.getY(), (float) this.trackedEntity.getZ(),
|
||||
PacketParticles.Type.FIREWORK_GEN, Ints.toArray(data)));
|
||||
(float) this.trackedEntity.getX(), (float) this.trackedEntity.getY(), (float) this.trackedEntity.getZ(),
|
||||
PacketParticles.Type.FIREWORK_GEN, Ints.toArray(data)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -122,7 +120,7 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
|
|||
this.toRelease = 0;
|
||||
|
||||
PacketHandler.sendToAllLoaded(this.level, this.worldPosition,
|
||||
new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.FLOWER_GEN_AURA_CREATION));
|
||||
new PacketParticles(this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), PacketParticles.Type.FLOWER_GEN_AURA_CREATION));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -132,4 +130,5 @@ public class BlockEntityFireworkGenerator extends BlockEntityImpl implements ITi
|
|||
public boolean wantsLimitRemover() {
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package de.ellpeck.naturesaura.blocks.tiles;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.blocks.ModBlocks;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.Connection;
|
||||
import net.minecraft.network.protocol.game.ClientboundBlockEntityDataPacket;
|
||||
|
@ -103,16 +106,13 @@ public class BlockEntityImpl extends BlockEntity {
|
|||
public void modifyDrop(ItemStack regularItem) {
|
||||
var compound = new CompoundTag();
|
||||
this.writeNBT(compound, SaveType.BLOCK, this.getLevel().registryAccess());
|
||||
if (!compound.isEmpty()) {
|
||||
if (!regularItem.hasTag())
|
||||
regularItem.setTag(new CompoundTag());
|
||||
regularItem.getTag().put("data", compound);
|
||||
}
|
||||
if (!compound.isEmpty())
|
||||
regularItem.set(DroppedItemData.TYPE, new DroppedItemData(compound));
|
||||
}
|
||||
|
||||
public void loadDataOnPlace(ItemStack stack) {
|
||||
if (stack.hasTag()) {
|
||||
var compound = stack.getTag().getCompound("data");
|
||||
if (stack.has(DroppedItemData.TYPE)) {
|
||||
var compound = stack.get(DroppedItemData.TYPE).data;
|
||||
if (compound != null)
|
||||
this.readNBT(compound, SaveType.BLOCK, this.level.registryAccess());
|
||||
}
|
||||
|
@ -161,4 +161,13 @@ public class BlockEntityImpl extends BlockEntity {
|
|||
TILE, SYNC, BLOCK
|
||||
}
|
||||
|
||||
public record DroppedItemData(CompoundTag data) {
|
||||
|
||||
public static final Codec<DroppedItemData> CODEC = RecordCodecBuilder.create(i -> i.group(
|
||||
CompoundTag.CODEC.fieldOf("data").forGetter(d -> d.data)
|
||||
).apply(i, DroppedItemData::new));
|
||||
public static final DataComponentType<DroppedItemData> TYPE = DataComponentType.<DroppedItemData>builder().persistent(DroppedItemData.CODEC).cacheEncoding().build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -13,6 +13,7 @@ import de.ellpeck.naturesaura.misc.LevelData;
|
|||
import de.ellpeck.naturesaura.packet.PacketAuraChunk;
|
||||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.HolderLookup;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.nbt.ListTag;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -168,15 +169,15 @@ public class AuraChunk implements IAuraChunk {
|
|||
if (this.needsSync) {
|
||||
var pos = this.chunk.getPos();
|
||||
PacketHandler.sendToAllLoaded(level,
|
||||
new BlockPos(pos.x * 16, 0, pos.z * 16),
|
||||
this.makePacket());
|
||||
new BlockPos(pos.x * 16, 0, pos.z * 16),
|
||||
this.makePacket());
|
||||
this.needsSync = false;
|
||||
}
|
||||
}
|
||||
|
||||
public PacketAuraChunk makePacket() {
|
||||
var pos = this.chunk.getPos();
|
||||
return new PacketAuraChunk(pos.x, pos.z, this.drainSpots.values());
|
||||
return new PacketAuraChunk(pos.x, pos.z, this.drainSpots.values().stream().map(DrainSpot::serializeNBT).toList());
|
||||
}
|
||||
|
||||
public void getSpots(BlockPos pos, int radius, BiConsumer<BlockPos, Integer> consumer) {
|
||||
|
@ -222,8 +223,8 @@ public class AuraChunk implements IAuraChunk {
|
|||
}
|
||||
});
|
||||
ret = new Pair[]{
|
||||
Pair.of(lowestSpot.getValue(), lowestAmount.intValue()),
|
||||
Pair.of(highestSpot.getValue(), highestAmount.intValue())};
|
||||
Pair.of(lowestSpot.getValue(), lowestAmount.intValue()),
|
||||
Pair.of(highestSpot.getValue(), highestAmount.intValue())};
|
||||
this.limitSpotCache.put(pos, radius, ret);
|
||||
}
|
||||
return ret;
|
||||
|
@ -249,7 +250,7 @@ public class AuraChunk implements IAuraChunk {
|
|||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag serializeNBT() {
|
||||
public CompoundTag serializeNBT(HolderLookup.Provider registries) {
|
||||
var list = new ListTag();
|
||||
for (var spot : this.drainSpots.values())
|
||||
list.add(spot.serializeNBT());
|
||||
|
@ -259,7 +260,7 @@ public class AuraChunk implements IAuraChunk {
|
|||
}
|
||||
|
||||
@Override
|
||||
public void deserializeNBT(CompoundTag compound) {
|
||||
public void deserializeNBT(HolderLookup.Provider registries, CompoundTag compound) {
|
||||
this.drainSpots.clear();
|
||||
var list = compound.getList("drain_spots", 10);
|
||||
for (var base : list)
|
||||
|
|
|
@ -1,30 +0,0 @@
|
|||
package de.ellpeck.naturesaura.enchant;
|
||||
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.Enchantments;
|
||||
|
||||
public class AuraMendingEnchantment extends ModEnchantment {
|
||||
|
||||
public AuraMendingEnchantment() {
|
||||
super("aura_mending", Rarity.RARE, EnchantmentCategory.BREAKABLE, EquipmentSlot.values());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean checkCompatibility(Enchantment ench) {
|
||||
return super.checkCompatibility(ench) && ench != Enchantments.MENDING;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canEnchant(ItemStack stack) {
|
||||
return super.canEnchant(stack) && stack.getCapability(NaturesAuraAPI.AURA_RECHARGE_CAPABILITY) == null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canApplyAtEnchantingTable(ItemStack stack) {
|
||||
return super.canApplyAtEnchantingTable(stack) && stack.getCapability(NaturesAuraAPI.AURA_RECHARGE_CAPABILITY) == null;
|
||||
}
|
||||
}
|
|
@ -1,23 +0,0 @@
|
|||
package de.ellpeck.naturesaura.enchant;
|
||||
|
||||
import de.ellpeck.naturesaura.reg.IModItem;
|
||||
import de.ellpeck.naturesaura.reg.ModRegistry;
|
||||
import net.minecraft.world.entity.EquipmentSlot;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
import net.minecraft.world.item.enchantment.EnchantmentCategory;
|
||||
|
||||
public class ModEnchantment extends Enchantment implements IModItem {
|
||||
|
||||
private final String name;
|
||||
|
||||
protected ModEnchantment(String name, Rarity rarityIn, EnchantmentCategory typeIn, EquipmentSlot[] slots) {
|
||||
super(rarityIn, typeIn, slots);
|
||||
this.name = name;
|
||||
ModRegistry.ALL_ITEMS.add(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getBaseName() {
|
||||
return this.name;
|
||||
}
|
||||
}
|
|
@ -1,10 +1,21 @@
|
|||
package de.ellpeck.naturesaura.enchant;
|
||||
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import net.minecraft.core.HolderSet;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.entity.EquipmentSlotGroup;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.enchantment.Enchantment;
|
||||
|
||||
@SuppressWarnings("NonConstantFieldWithUpperCaseName")
|
||||
public final class ModEnchantments {
|
||||
|
||||
public static Enchantment AURA_MENDING;
|
||||
public static final Enchantment AURA_MENDING = Enchantment.enchantment(
|
||||
Enchantment.definition(
|
||||
HolderSet.direct(BuiltInRegistries.ITEM.holders().filter(i -> new ItemStack(i).getCapability(NaturesAuraAPI.AURA_RECHARGE_CAPABILITY) == null).toList()),
|
||||
// same values as unbreaking, except for the max level
|
||||
5, 1, Enchantment.dynamicCost(5, 8), Enchantment.dynamicCost(55, 8), 2, EquipmentSlotGroup.ANY)
|
||||
).build(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "aura_mending"));
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package de.ellpeck.naturesaura.items;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
||||
import de.ellpeck.naturesaura.api.aura.type.IAuraType;
|
||||
|
@ -9,6 +11,7 @@ import de.ellpeck.naturesaura.reg.ICustomCreativeTab;
|
|||
import de.ellpeck.naturesaura.reg.ICustomItemModel;
|
||||
import net.minecraft.client.color.item.ItemColor;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.core.dispenser.DefaultDispenseItemBehavior;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
|
@ -23,9 +26,9 @@ import net.minecraft.world.level.block.DispenserBlock;
|
|||
import net.minecraft.world.phys.HitResult;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -72,21 +75,21 @@ public class ItemAuraBottle extends ItemImpl implements IColorProvidingItem, ICu
|
|||
@Override
|
||||
public void generateCustomItemModel(ItemModelGenerator generator) {
|
||||
generator.withExistingParent(this.getBaseName(), "item/generated")
|
||||
.texture("layer0", "item/" + this.getBaseName())
|
||||
.texture("layer1", "item/" + this.getBaseName() + "_overlay");
|
||||
.texture("layer0", "item/" + this.getBaseName())
|
||||
.texture("layer1", "item/" + this.getBaseName() + "_overlay");
|
||||
}
|
||||
|
||||
public static IAuraType getType(ItemStack stack) {
|
||||
if (!stack.hasTag())
|
||||
if (!stack.has(Data.TYPE))
|
||||
return NaturesAuraAPI.TYPE_OTHER;
|
||||
var type = stack.getTag().getString("stored_type");
|
||||
var type = stack.get(Data.TYPE).auraType;
|
||||
if (type.isEmpty())
|
||||
return NaturesAuraAPI.TYPE_OTHER;
|
||||
return NaturesAuraAPI.AURA_TYPES.get(new ResourceLocation(type));
|
||||
return NaturesAuraAPI.AURA_TYPES.get(ResourceLocation.parse(type));
|
||||
}
|
||||
|
||||
public static ItemStack setType(ItemStack stack, IAuraType type) {
|
||||
stack.getOrCreateTag().putString("stored_type", type.getName().toString());
|
||||
stack.set(Data.TYPE, new Data(type.getName().toString()));
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
@ -124,11 +127,21 @@ public class ItemAuraBottle extends ItemImpl implements IColorProvidingItem, ICu
|
|||
player.level().addFreshEntity(new ItemEntity(player.level(), player.getX(), player.getY(), player.getZ(), bottle));
|
||||
|
||||
player.level().playSound(null, player.getX(), player.getY(), player.getZ(),
|
||||
SoundEvents.BOTTLE_FILL_DRAGONBREATH, SoundSource.PLAYERS, 1F, 1F);
|
||||
SoundEvents.BOTTLE_FILL_DRAGONBREATH, SoundSource.PLAYERS, 1F, 1F);
|
||||
}
|
||||
|
||||
player.swing(event.getHand());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public record Data(String auraType) {
|
||||
|
||||
public static final Codec<Data> CODEC = RecordCodecBuilder.create(i -> i.group(
|
||||
Codec.STRING.fieldOf("aura_type").forGetter(d -> d.auraType)
|
||||
).apply(i, Data::new));
|
||||
public static final DataComponentType<Data> TYPE = DataComponentType.<Data>builder().persistent(Data.CODEC).cacheEncoding().build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package de.ellpeck.naturesaura.items;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.network.chat.Style;
|
||||
|
@ -32,7 +35,7 @@ public class ItemBreakPrevention extends ItemImpl {
|
|||
if (second.getItem() != ModItems.BREAK_PREVENTION)
|
||||
return;
|
||||
var output = stack.copy();
|
||||
output.getOrCreateTag().putBoolean(NaturesAura.MOD_ID + ":break_prevention", true);
|
||||
output.set(Data.TYPE, new Data(true));
|
||||
event.setOutput(output);
|
||||
event.setMaterialCost(1);
|
||||
event.setCost(1);
|
||||
|
@ -44,7 +47,7 @@ public class ItemBreakPrevention extends ItemImpl {
|
|||
if (player == null)
|
||||
return;
|
||||
var stack = player.getMainHandItem();
|
||||
if (!stack.hasTag() || !stack.getTag().getBoolean(NaturesAura.MOD_ID + ":break_prevention"))
|
||||
if (!stack.has(Data.TYPE) || !stack.get(Data.TYPE).enabled)
|
||||
return;
|
||||
if (ElytraItem.isFlyEnabled(stack))
|
||||
return;
|
||||
|
@ -55,17 +58,28 @@ public class ItemBreakPrevention extends ItemImpl {
|
|||
@OnlyIn(Dist.CLIENT)
|
||||
public void onTooltip(ItemTooltipEvent event) {
|
||||
var stack = event.getItemStack();
|
||||
if (!stack.hasTag() || !stack.getTag().getBoolean(NaturesAura.MOD_ID + ":break_prevention"))
|
||||
if (!stack.has(Data.TYPE) || !stack.get(Data.TYPE).enabled)
|
||||
return;
|
||||
var tooltip = event.getToolTip();
|
||||
tooltip.add(Component.translatable("info." + NaturesAura.MOD_ID + ".break_prevention").setStyle(Style.EMPTY.applyFormat(ChatFormatting.GRAY)));
|
||||
if (ElytraItem.isFlyEnabled(stack))
|
||||
return;
|
||||
if (tooltip.size() < 1)
|
||||
if (tooltip.isEmpty())
|
||||
return;
|
||||
var head = tooltip.get(0);
|
||||
var head = tooltip.getFirst();
|
||||
if (head instanceof MutableComponent)
|
||||
((MutableComponent) head).append(Component.translatable("info." + NaturesAura.MOD_ID + ".broken").setStyle(Style.EMPTY.applyFormat(ChatFormatting.GRAY)));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public record Data(boolean enabled) {
|
||||
|
||||
public static final Codec<Data> CODEC = RecordCodecBuilder.create(i -> i.group(
|
||||
Codec.BOOL.fieldOf("enabled").forGetter(d -> d.enabled)
|
||||
).apply(i, Data::new));
|
||||
public static final DataComponentType<Data> TYPE = DataComponentType.<Data>builder().persistent(Data.CODEC).cacheEncoding().build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
package de.ellpeck.naturesaura.items;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import de.ellpeck.naturesaura.data.ItemModelGenerator;
|
||||
import de.ellpeck.naturesaura.misc.ColoredBlockHelper;
|
||||
|
@ -8,6 +10,7 @@ import de.ellpeck.naturesaura.reg.ICustomItemModel;
|
|||
import net.minecraft.client.color.item.ItemColor;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.Direction;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
|
@ -38,7 +41,7 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
|
|||
if (player.isShiftKeyDown()) {
|
||||
if (stored != color) {
|
||||
level.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
|
||||
SoundEvents.BUCKET_FILL, SoundSource.PLAYERS, 0.65F, 1F);
|
||||
SoundEvents.BUCKET_FILL, SoundSource.PLAYERS, 0.65F, 1F);
|
||||
if (!level.isClientSide)
|
||||
ItemColorChanger.storeColor(stack, color);
|
||||
return true;
|
||||
|
@ -48,7 +51,7 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
|
|||
if (NaturesAuraAPI.instance().extractAuraFromPlayer(player, 1000, level.isClientSide)) {
|
||||
if (firstColor == null) {
|
||||
level.playSound(player, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5,
|
||||
SoundEvents.BUCKET_EMPTY, SoundSource.PLAYERS, 0.65F, 1F);
|
||||
SoundEvents.BUCKET_EMPTY, SoundSource.PLAYERS, 0.65F, 1F);
|
||||
}
|
||||
if (!level.isClientSide) {
|
||||
level.setBlockAndUpdate(pos, blocks.get(stored.getId()).defaultBlockState());
|
||||
|
@ -68,28 +71,21 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
|
|||
}
|
||||
|
||||
public static DyeColor getStoredColor(ItemStack stack) {
|
||||
if (!stack.hasTag()) {
|
||||
return null;
|
||||
} else {
|
||||
var color = stack.getTag().getInt("color");
|
||||
return DyeColor.byId(color);
|
||||
}
|
||||
return stack.has(Data.TYPE) ? DyeColor.byId(stack.get(Data.TYPE).color) : null;
|
||||
}
|
||||
|
||||
private static void storeColor(ItemStack stack, DyeColor color) {
|
||||
stack.getOrCreateTag().putInt("color", color.getId());
|
||||
var previous = stack.getOrDefault(Data.TYPE, new Data(0, false));
|
||||
stack.set(Data.TYPE, new Data(color.getId(), previous.fill));
|
||||
}
|
||||
|
||||
public static boolean isFillMode(ItemStack stack) {
|
||||
if (!stack.hasTag()) {
|
||||
return false;
|
||||
} else {
|
||||
return stack.getTag().getBoolean("fill");
|
||||
}
|
||||
return stack.has(Data.TYPE) && stack.get(Data.TYPE).fill;
|
||||
}
|
||||
|
||||
private static void setFillMode(ItemStack stack, boolean fill) {
|
||||
stack.getOrCreateTag().putBoolean("fill", fill);
|
||||
var previous = stack.getOrDefault(Data.TYPE, new Data(0, false));
|
||||
stack.set(Data.TYPE, new Data(previous.color, fill));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -134,4 +130,15 @@ public class ItemColorChanger extends ItemImpl implements IColorProvidingItem, I
|
|||
public void generateCustomItemModel(ItemModelGenerator generator) {
|
||||
// noop
|
||||
}
|
||||
|
||||
public record Data(int color, boolean fill) {
|
||||
|
||||
public static final Codec<Data> CODEC = RecordCodecBuilder.create(i -> i.group(
|
||||
Codec.INT.fieldOf("color").forGetter(d -> d.color),
|
||||
Codec.BOOL.fieldOf("fill").forGetter(d -> d.fill)
|
||||
).apply(i, Data::new));
|
||||
public static final DataComponentType<Data> TYPE = DataComponentType.<Data>builder().persistent(Data.CODEC).cacheEncoding().build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package de.ellpeck.naturesaura.items;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import de.ellpeck.naturesaura.entities.EntityEffectInhibitor;
|
||||
import de.ellpeck.naturesaura.reg.IColorProvidingItem;
|
||||
import de.ellpeck.naturesaura.reg.ICustomCreativeTab;
|
||||
import net.minecraft.client.color.item.ItemColor;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
|
@ -22,16 +25,16 @@ public class ItemEffectPowder extends ItemImpl implements IColorProvidingItem, I
|
|||
}
|
||||
|
||||
public static ResourceLocation getEffect(ItemStack stack) {
|
||||
if (!stack.hasTag())
|
||||
if (!stack.has(Data.TYPE))
|
||||
return null;
|
||||
var effect = stack.getTag().getString("effect");
|
||||
var effect = stack.get(Data.TYPE).effect;
|
||||
if (effect.isEmpty())
|
||||
return null;
|
||||
return new ResourceLocation(effect);
|
||||
return ResourceLocation.parse(effect);
|
||||
}
|
||||
|
||||
public static ItemStack setEffect(ItemStack stack, ResourceLocation effect) {
|
||||
stack.getOrCreateTag().putString("effect", effect != null ? effect.toString() : "");
|
||||
stack.set(Data.TYPE, new Data(effect != null ? effect.toString() : ""));
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
@ -63,4 +66,13 @@ public class ItemEffectPowder extends ItemImpl implements IColorProvidingItem, I
|
|||
return (stack, tintIndex) -> NaturesAuraAPI.EFFECT_POWDERS.getOrDefault(ItemEffectPowder.getEffect(stack), 0xFFFFFF);
|
||||
}
|
||||
|
||||
public record Data(String effect) {
|
||||
|
||||
public static final Codec<Data> CODEC = RecordCodecBuilder.create(i -> i.group(
|
||||
Codec.STRING.fieldOf("effect").forGetter(d -> d.effect)
|
||||
).apply(i, Data::new));
|
||||
public static final DataComponentType<Data> TYPE = DataComponentType.<Data>builder().persistent(Data.CODEC).cacheEncoding().build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -19,8 +19,6 @@ import net.minecraft.world.inventory.AbstractContainerMenu;
|
|||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.TooltipFlag;
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.neoforge.items.IItemHandler;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
@ -60,9 +58,8 @@ public class ItemEnderAccess extends ItemImpl {
|
|||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public void appendHoverText(ItemStack stack, @Nullable Level levelIn, List<Component> tooltip, TooltipFlag flagIn) {
|
||||
BlockEnderCrate.addEnderNameInfo(stack, tooltip);
|
||||
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
|
||||
BlockEnderCrate.addEnderNameInfo(stack, tooltipComponents);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,10 @@
|
|||
package de.ellpeck.naturesaura.items;
|
||||
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import de.ellpeck.naturesaura.api.multiblock.IMultiblock;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.chat.MutableComponent;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
|
@ -20,7 +23,7 @@ public class ItemMultiblockMaker extends ItemImpl {
|
|||
private static List<IMultiblock> multiblocks;
|
||||
|
||||
public ItemMultiblockMaker() {
|
||||
super("multiblock_maker");
|
||||
super("multiblock_maker", new Properties().component(Data.TYPE, new Data(0)));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -29,7 +32,7 @@ public class ItemMultiblockMaker extends ItemImpl {
|
|||
if (!levelIn.isClientSide && playerIn.isCreative()) {
|
||||
var curr = ItemMultiblockMaker.getMultiblockId(stack);
|
||||
var next = (curr + 1) % ItemMultiblockMaker.multiblocks().size();
|
||||
stack.getOrCreateTag().putInt("multiblock", next);
|
||||
stack.set(Data.TYPE, new Data(next));
|
||||
}
|
||||
return new InteractionResultHolder<>(InteractionResult.SUCCESS, stack);
|
||||
}
|
||||
|
@ -72,9 +75,7 @@ public class ItemMultiblockMaker extends ItemImpl {
|
|||
}
|
||||
|
||||
private static int getMultiblockId(ItemStack stack) {
|
||||
if (!stack.hasTag())
|
||||
return -1;
|
||||
return stack.getTag().getInt("multiblock");
|
||||
return stack.get(Data.TYPE).multiblockId();
|
||||
}
|
||||
|
||||
private static IMultiblock getMultiblock(ItemStack stack) {
|
||||
|
@ -86,4 +87,14 @@ public class ItemMultiblockMaker extends ItemImpl {
|
|||
return null;
|
||||
return multiblocks.get(id);
|
||||
}
|
||||
|
||||
public record Data(int multiblockId) {
|
||||
|
||||
public static final Codec<Data> CODEC = RecordCodecBuilder.create(i -> i.group(
|
||||
Codec.INT.fieldOf("multiblock_id").forGetter(d -> d.multiblockId)
|
||||
).apply(i, Data::new));
|
||||
public static final DataComponentType<Data> TYPE = DataComponentType.<Data>builder().persistent(Data.CODEC).cacheEncoding().build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -5,23 +5,30 @@ import de.ellpeck.naturesaura.api.aura.chunk.IAuraChunk;
|
|||
import de.ellpeck.naturesaura.packet.PacketHandler;
|
||||
import de.ellpeck.naturesaura.packet.PacketParticles;
|
||||
import net.minecraft.ChatFormatting;
|
||||
import net.minecraft.core.BlockPos;
|
||||
import net.minecraft.core.particles.ParticleTypes;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.server.level.ServerLevel;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.world.InteractionResult;
|
||||
import net.minecraft.world.entity.Entity;
|
||||
import net.minecraft.world.entity.EntityType;
|
||||
import net.minecraft.world.entity.TamableAnimal;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.level.block.BedBlock;
|
||||
import net.minecraft.world.level.block.Block;
|
||||
import net.minecraft.world.level.block.RespawnAnchorBlock;
|
||||
import net.minecraft.world.level.block.state.BlockState;
|
||||
import net.minecraft.world.phys.Vec3;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.event.entity.living.LivingDeathEvent;
|
||||
import net.neoforged.neoforge.event.entity.living.LivingEvent;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.neoforged.bus.api.EventPriority;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.neoforge.common.NeoForge;
|
||||
import net.neoforged.neoforge.event.entity.living.LivingDeathEvent;
|
||||
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.neoforged.neoforge.event.tick.EntityTickEvent;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public class ItemPetReviver extends ItemImpl {
|
||||
|
||||
public ItemPetReviver() {
|
||||
|
@ -88,10 +95,10 @@ public class ItemPetReviver extends ItemImpl {
|
|||
if (pos != null) {
|
||||
var f = player.getRespawnAngle();
|
||||
var b = player.isRespawnForced();
|
||||
var bed = Player.findRespawnPositionAndUseSpawnBlock((ServerLevel) player.level(), pos, f, b, false);
|
||||
var bed = ItemPetReviver.findRespawnAndUseSpawnBlock((ServerLevel) player.level(), pos, f, b, false);
|
||||
if (bed.isPresent()) {
|
||||
spawnLevel = (ServerLevel) player.level();
|
||||
spawn = bed.get();
|
||||
spawn = bed.get().position();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -133,4 +140,38 @@ public class ItemPetReviver extends ItemImpl {
|
|||
|
||||
}
|
||||
|
||||
// copy of private ServerPlayer.findRespawnAndUseSpawnBlock
|
||||
private static Optional<ServerPlayer.RespawnPosAngle> findRespawnAndUseSpawnBlock(ServerLevel level, BlockPos pos, float angle, boolean forced, boolean keepInventory) {
|
||||
BlockState blockstate = level.getBlockState(pos);
|
||||
Block block = blockstate.getBlock();
|
||||
if (block instanceof RespawnAnchorBlock
|
||||
&& (forced || blockstate.getValue(RespawnAnchorBlock.CHARGE) > 0)
|
||||
&& RespawnAnchorBlock.canSetSpawn(level)) {
|
||||
Optional<Vec3> optional = RespawnAnchorBlock.findStandUpPosition(EntityType.PLAYER, level, pos);
|
||||
if (!forced && !keepInventory && optional.isPresent()) {
|
||||
level.setBlock(
|
||||
pos, blockstate.setValue(RespawnAnchorBlock.CHARGE, Integer.valueOf(blockstate.getValue(RespawnAnchorBlock.CHARGE) - 1)), 3
|
||||
);
|
||||
}
|
||||
|
||||
return optional.map(p_348139_ -> ServerPlayer.RespawnPosAngle.of(p_348139_, pos));
|
||||
} else if (block instanceof BedBlock && BedBlock.canSetSpawn(level)) {
|
||||
return BedBlock.findStandUpPosition(EntityType.PLAYER, level, pos, blockstate.getValue(BedBlock.FACING), angle)
|
||||
.map(p_348148_ -> ServerPlayer.RespawnPosAngle.of(p_348148_, pos));
|
||||
} else if (!forced) {
|
||||
return blockstate.getRespawnPosition(EntityType.PLAYER, level, pos, angle);
|
||||
} else {
|
||||
boolean flag = block.isPossibleToRespawnInThis(blockstate);
|
||||
BlockState blockstate1 = level.getBlockState(pos.above());
|
||||
boolean flag1 = blockstate1.getBlock().isPossibleToRespawnInThis(blockstate1);
|
||||
return flag && flag1
|
||||
? Optional.of(
|
||||
new ServerPlayer.RespawnPosAngle(
|
||||
new Vec3((double) pos.getX() + 0.5, (double) pos.getY() + 0.1, (double) pos.getZ() + 0.5), angle
|
||||
)
|
||||
)
|
||||
: Optional.empty();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -2,6 +2,8 @@ package de.ellpeck.naturesaura.items;
|
|||
|
||||
import com.mojang.blaze3d.vertex.PoseStack;
|
||||
import com.mojang.math.Axis;
|
||||
import com.mojang.serialization.Codec;
|
||||
import com.mojang.serialization.codecs.RecordCodecBuilder;
|
||||
import de.ellpeck.naturesaura.api.NaturesAuraAPI;
|
||||
import de.ellpeck.naturesaura.api.render.ITrinketItem;
|
||||
import de.ellpeck.naturesaura.items.tools.ItemArmor;
|
||||
|
@ -11,6 +13,7 @@ import de.ellpeck.naturesaura.reg.ModArmorMaterial;
|
|||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.MultiBufferSource;
|
||||
import net.minecraft.client.renderer.texture.OverlayTexture;
|
||||
import net.minecraft.core.component.DataComponentType;
|
||||
import net.minecraft.sounds.SoundSource;
|
||||
import net.minecraft.world.damagesource.DamageSource;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
|
@ -37,35 +40,29 @@ public class ItemShockwaveCreator extends ItemImpl implements ITrinketItem {
|
|||
if (levelIn.isClientSide || !(entityIn instanceof LivingEntity living))
|
||||
return;
|
||||
if (!living.onGround()) {
|
||||
var compound = stack.getOrCreateTag();
|
||||
if (compound.getBoolean("air"))
|
||||
if (stack.has(Data.TYPE) && stack.get(Data.TYPE).air)
|
||||
return;
|
||||
|
||||
compound.putBoolean("air", true);
|
||||
compound.putDouble("x", living.getX());
|
||||
compound.putDouble("y", living.getY());
|
||||
compound.putDouble("z", living.getZ());
|
||||
stack.set(Data.TYPE, new Data(true, living.getX(), living.getY(), living.getZ()));
|
||||
} else {
|
||||
if (!stack.hasTag())
|
||||
if (!stack.has(Data.TYPE))
|
||||
return;
|
||||
var compound = stack.getTag();
|
||||
if (!compound.getBoolean("air"))
|
||||
var data = stack.get(Data.TYPE);
|
||||
if (!data.air)
|
||||
return;
|
||||
|
||||
compound.putBoolean("air", false);
|
||||
stack.remove(Data.TYPE);
|
||||
|
||||
if (!living.isShiftKeyDown())
|
||||
return;
|
||||
if (living.distanceToSqr(compound.getDouble("x"), compound.getDouble("y"), compound.getDouble("z")) > 0.75F)
|
||||
if (living.distanceToSqr(data.x, data.y, data.z) > 0.75F)
|
||||
return;
|
||||
if (living instanceof Player && !NaturesAuraAPI.instance().extractAuraFromPlayer((Player) living, 1000, false))
|
||||
return;
|
||||
|
||||
var infusedSet = ItemArmor.isFullSetEquipped(living, ModArmorMaterial.INFUSED);
|
||||
var infusedSet = ItemArmor.isFullSetEquipped(living, ModArmorMaterial.INFUSED.material.value());
|
||||
var range = 5;
|
||||
var mobs = levelIn.getEntitiesOfClass(LivingEntity.class, new AABB(
|
||||
living.getX() - range, living.getY() - 0.5, living.getZ() - range,
|
||||
living.getX() + range, living.getY() + 0.5, living.getZ() + range));
|
||||
living.getX() - range, living.getY() - 0.5, living.getZ() - range,
|
||||
living.getX() + range, living.getY() + 0.5, living.getZ() + range));
|
||||
for (var mob : mobs) {
|
||||
if (!mob.isAlive() || mob == living)
|
||||
continue;
|
||||
|
@ -109,4 +106,17 @@ public class ItemShockwaveCreator extends ItemImpl implements ITrinketItem {
|
|||
Minecraft.getInstance().getItemRenderer().renderStatic(stack, ItemDisplayContext.GROUND, packedLight, OverlayTexture.NO_OVERLAY, matrices, buffer, player.level(), 0);
|
||||
}
|
||||
}
|
||||
|
||||
public record Data(boolean air, double x, double y, double z) {
|
||||
|
||||
public static final Codec<Data> CODEC = RecordCodecBuilder.create(i -> i.group(
|
||||
Codec.BOOL.fieldOf("air").forGetter(d -> d.air),
|
||||
Codec.DOUBLE.fieldOf("x").forGetter(d -> d.x),
|
||||
Codec.DOUBLE.fieldOf("y").forGetter(d -> d.y),
|
||||
Codec.DOUBLE.fieldOf("z").forGetter(d -> d.z)
|
||||
).apply(i, Data::new));
|
||||
public static final DataComponentType<Data> TYPE = DataComponentType.<Data>builder().persistent(Data.CODEC).cacheEncoding().build();
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -4,7 +4,6 @@ import de.ellpeck.naturesaura.NaturesAura;
|
|||
import de.ellpeck.naturesaura.reg.IModItem;
|
||||
import de.ellpeck.naturesaura.reg.ModArmorMaterial;
|
||||
import de.ellpeck.naturesaura.reg.ModRegistry;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
|
@ -35,8 +34,8 @@ public class ItemArmor extends ArmorItem implements IModItem {
|
|||
private static final Map<ArmorMaterial, Item[]> SETS = new ConcurrentHashMap<>();
|
||||
private final String baseName;
|
||||
|
||||
public ItemArmor(String baseName, Holder<ArmorMaterial> materialIn, ArmorItem.Type equipmentSlotIn) {
|
||||
super(materialIn, equipmentSlotIn, new Properties());
|
||||
public ItemArmor(String baseName, ModArmorMaterial materialIn, ArmorItem.Type equipmentSlotIn) {
|
||||
super(materialIn.material, equipmentSlotIn, new Properties());
|
||||
this.baseName = baseName;
|
||||
ModRegistry.ALL_ITEMS.add(this);
|
||||
}
|
||||
|
@ -67,11 +66,11 @@ public class ItemArmor extends ArmorItem implements IModItem {
|
|||
public static void onAttack(LivingIncomingDamageEvent event) {
|
||||
var entity = event.getEntity();
|
||||
if (!entity.level().isClientSide) {
|
||||
if (ItemArmor.isFullSetEquipped(entity, ModArmorMaterial.INFUSED)) {
|
||||
if (ItemArmor.isFullSetEquipped(entity, ModArmorMaterial.INFUSED.material.value())) {
|
||||
var source = event.getSource().getEntity();
|
||||
if (source instanceof LivingEntity)
|
||||
((LivingEntity) source).addEffect(new MobEffectInstance(MobEffects.WITHER, 40));
|
||||
} else if (ItemArmor.isFullSetEquipped(entity, ModArmorMaterial.DEPTH)) {
|
||||
} else if (ItemArmor.isFullSetEquipped(entity, ModArmorMaterial.DEPTH.material.value())) {
|
||||
for (var other : entity.level().getEntitiesOfClass(LivingEntity.class, new AABB(entity.position(), entity.position()).inflate(2))) {
|
||||
if (other != entity && (!(entity instanceof Player player) || !player.isAlliedTo(other)))
|
||||
other.addEffect(new MobEffectInstance(MobEffects.MOVEMENT_SLOWDOWN, 60, 255));
|
||||
|
@ -87,7 +86,7 @@ public class ItemArmor extends ArmorItem implements IModItem {
|
|||
var step = player.getAttribute(Attributes.STEP_HEIGHT);
|
||||
var key = NaturesAura.MOD_ID + ":sky_equipped";
|
||||
var nbt = player.getPersistentData();
|
||||
var equipped = ItemArmor.isFullSetEquipped(player, ModArmorMaterial.SKY);
|
||||
var equipped = ItemArmor.isFullSetEquipped(player, ModArmorMaterial.SKY.material.value());
|
||||
if (equipped && !nbt.getBoolean(key)) {
|
||||
// we just equipped it
|
||||
nbt.putBoolean(key, true);
|
||||
|
|
|
@ -5,6 +5,7 @@ import de.ellpeck.naturesaura.items.ModItems;
|
|||
import de.ellpeck.naturesaura.reg.ICustomItemModel;
|
||||
import de.ellpeck.naturesaura.reg.IModItem;
|
||||
import de.ellpeck.naturesaura.reg.ModRegistry;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.util.Mth;
|
||||
import net.minecraft.world.effect.MobEffectInstance;
|
||||
import net.minecraft.world.effect.MobEffects;
|
||||
|
@ -44,7 +45,7 @@ public class ItemSword extends SwordItem implements IModItem, ICustomItemModel {
|
|||
// this is just a modified copy of Player.attack's sweeping damage code
|
||||
var damage = (float) player.getAttributeValue(Attributes.ATTACK_DAMAGE) * 0.75F;
|
||||
for (var other : player.level().getEntitiesOfClass(LivingEntity.class, stack.getSweepHitBox(player, target))) {
|
||||
if (other != player && other != target && !player.isAlliedTo(other) && (!(other instanceof ArmorStand stand) || !stand.isMarker()) && player.distanceToSqr(other) < Mth.square(player.getEntityReach())) {
|
||||
if (other != player && other != target && !player.isAlliedTo(other) && (!(other instanceof ArmorStand stand) || !stand.isMarker()) && player.distanceToSqr(other) < Mth.square(player.entityInteractionRange())) {
|
||||
other.knockback(0.4F, Mth.sin(player.getYRot() * (Mth.PI / 180)), -Mth.cos(player.getYRot() * (Mth.PI / 180)));
|
||||
other.hurt(other.damageSources().playerAttack(player), damage);
|
||||
}
|
||||
|
|
|
@ -2,82 +2,37 @@ package de.ellpeck.naturesaura.reg;
|
|||
|
||||
import de.ellpeck.naturesaura.NaturesAura;
|
||||
import de.ellpeck.naturesaura.items.ModItems;
|
||||
import net.minecraft.core.Holder;
|
||||
import net.minecraft.core.Registry;
|
||||
import net.minecraft.core.registries.BuiltInRegistries;
|
||||
import net.minecraft.resources.ResourceLocation;
|
||||
import net.minecraft.sounds.SoundEvent;
|
||||
import net.minecraft.sounds.SoundEvents;
|
||||
import net.minecraft.world.item.ArmorItem;
|
||||
import net.minecraft.world.item.ArmorMaterial;
|
||||
import net.minecraft.world.item.crafting.Ingredient;
|
||||
import net.neoforged.api.distmarker.Dist;
|
||||
import net.neoforged.api.distmarker.OnlyIn;
|
||||
import net.neoforged.neoforge.common.util.Lazy;
|
||||
|
||||
import java.util.EnumMap;
|
||||
import java.util.List;
|
||||
import java.util.function.Supplier;
|
||||
|
||||
public enum ModArmorMaterial implements ArmorMaterial {
|
||||
public enum ModArmorMaterial {
|
||||
|
||||
INFUSED(NaturesAura.MOD_ID + ":infused_iron", 19, new int[]{2, 5, 6, 2}, 16, SoundEvents.ARMOR_EQUIP_IRON, 0, 0, () -> Ingredient.of(ModItems.INFUSED_IRON)),
|
||||
SKY(NaturesAura.MOD_ID + ":sky", 33, new int[]{3, 6, 8, 3}, 12, SoundEvents.ARMOR_EQUIP_DIAMOND, 2, 0, () -> Ingredient.of(ModItems.SKY_INGOT)),
|
||||
DEPTH(NaturesAura.MOD_ID + ":depth", 37, new int[]{3, 6, 8, 3}, 18, SoundEvents.ARMOR_EQUIP_NETHERITE, 3, 1, () -> Ingredient.of(ModItems.DEPTH_INGOT));
|
||||
INFUSED(NaturesAura.MOD_ID + ":infused_iron", new int[]{2, 5, 6, 2}, 16, SoundEvents.ARMOR_EQUIP_IRON, 0, 0, () -> Ingredient.of(ModItems.INFUSED_IRON)),
|
||||
SKY(NaturesAura.MOD_ID + ":sky", new int[]{3, 6, 8, 3}, 12, SoundEvents.ARMOR_EQUIP_DIAMOND, 2, 0, () -> Ingredient.of(ModItems.SKY_INGOT)),
|
||||
DEPTH(NaturesAura.MOD_ID + ":depth", new int[]{3, 6, 8, 3}, 18, SoundEvents.ARMOR_EQUIP_NETHERITE, 3, 1, () -> Ingredient.of(ModItems.DEPTH_INGOT));
|
||||
|
||||
private static final int[] MAX_DAMAGE_ARRAY = {13, 15, 16, 11};
|
||||
private final String name;
|
||||
private final int maxDamageFactor;
|
||||
private final int[] damageReductionAmountArray;
|
||||
private final int enchantability;
|
||||
private final SoundEvent soundEvent;
|
||||
private final float toughness;
|
||||
private final float knockbackResistance;
|
||||
private final Lazy<Ingredient> repairMaterial;
|
||||
public final Holder<ArmorMaterial> material;
|
||||
|
||||
ModArmorMaterial(String nameIn, int maxDamageFactorIn, int[] damageReductionAmountsIn, int enchantabilityIn, SoundEvent equipSoundIn, float toughness, float knockbackResistance, Supplier<Ingredient> repairMaterialSupplier) {
|
||||
this.name = nameIn;
|
||||
this.maxDamageFactor = maxDamageFactorIn;
|
||||
this.damageReductionAmountArray = damageReductionAmountsIn;
|
||||
this.enchantability = enchantabilityIn;
|
||||
this.soundEvent = equipSoundIn;
|
||||
this.toughness = toughness;
|
||||
this.knockbackResistance = knockbackResistance;
|
||||
this.repairMaterial = Lazy.of(repairMaterialSupplier);
|
||||
ModArmorMaterial(String nameIn, int[] damageReductionAmountsIn, int enchantabilityIn, Holder<SoundEvent> equipSoundIn, float toughness, float knockbackResistance, Supplier<Ingredient> repairMaterialSupplier) {
|
||||
var res = ResourceLocation.parse(nameIn);
|
||||
var defense = new EnumMap<ArmorItem.Type, Integer>(ArmorItem.Type.class);
|
||||
defense.put(ArmorItem.Type.BOOTS, damageReductionAmountsIn[0]);
|
||||
defense.put(ArmorItem.Type.LEGGINGS, damageReductionAmountsIn[1]);
|
||||
defense.put(ArmorItem.Type.CHESTPLATE, damageReductionAmountsIn[2]);
|
||||
defense.put(ArmorItem.Type.HELMET, damageReductionAmountsIn[3]);
|
||||
var layers = List.of(new ArmorMaterial.Layer(res));
|
||||
this.material = Registry.registerForHolder(BuiltInRegistries.ARMOR_MATERIAL, res, new ArmorMaterial(defense, enchantabilityIn, equipSoundIn, repairMaterialSupplier, layers, toughness, knockbackResistance));
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDurabilityForType(ArmorItem.Type p_266807_) {
|
||||
return ModArmorMaterial.MAX_DAMAGE_ARRAY[p_266807_.getSlot().getIndex()] * this.maxDamageFactor;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getDefenseForType(ArmorItem.Type p_266807_) {
|
||||
return this.damageReductionAmountArray[p_266807_.getSlot().getIndex()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getEnchantmentValue() {
|
||||
return this.enchantability;
|
||||
}
|
||||
|
||||
@Override
|
||||
public SoundEvent getEquipSound() {
|
||||
return this.soundEvent;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Ingredient getRepairIngredient() {
|
||||
return this.repairMaterial.get();
|
||||
}
|
||||
|
||||
@Override
|
||||
@OnlyIn(Dist.CLIENT)
|
||||
public String getName() {
|
||||
return this.name;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getToughness() {
|
||||
return this.toughness;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getKnockbackResistance() {
|
||||
return this.knockbackResistance;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,10 +8,10 @@ import de.ellpeck.naturesaura.api.misc.ILevelData;
|
|||
import de.ellpeck.naturesaura.blocks.*;
|
||||
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityAuraBloom;
|
||||
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityEnderCrate;
|
||||
import de.ellpeck.naturesaura.blocks.tiles.BlockEntityImpl;
|
||||
import de.ellpeck.naturesaura.blocks.tiles.ModBlockEntities;
|
||||
import de.ellpeck.naturesaura.compat.Compat;
|
||||
import de.ellpeck.naturesaura.compat.patchouli.PatchouliCompat;
|
||||
import de.ellpeck.naturesaura.enchant.AuraMendingEnchantment;
|
||||
import de.ellpeck.naturesaura.enchant.ModEnchantments;
|
||||
import de.ellpeck.naturesaura.entities.*;
|
||||
import de.ellpeck.naturesaura.gen.LevelGenAncientTree;
|
||||
|
@ -41,7 +41,6 @@ import net.minecraft.world.level.block.SoundType;
|
|||
import net.minecraft.world.level.levelgen.structure.BuiltinStructures;
|
||||
import net.neoforged.bus.api.SubscribeEvent;
|
||||
import net.neoforged.fml.common.EventBusSubscriber;
|
||||
import net.neoforged.fml.common.Mod;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities.EnergyStorage;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities.FluidHandler;
|
||||
import net.neoforged.neoforge.capabilities.Capabilities.ItemHandler;
|
||||
|
@ -265,8 +264,7 @@ public final class ModRegistry {
|
|||
});
|
||||
|
||||
event.register(Registries.ENCHANTMENT, h -> {
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "aura_mending"), new AuraMendingEnchantment());
|
||||
Helper.populateObjectHolders(ModEnchantments.class, BuiltInRegistries.ENCHANTMENT);
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "aura_mending"), ModEnchantments.AURA_MENDING);
|
||||
});
|
||||
|
||||
event.register(Registries.ENTITY_TYPE, h -> {
|
||||
|
@ -336,6 +334,19 @@ public final class ModRegistry {
|
|||
event.register(NeoForgeRegistries.Keys.ATTACHMENT_TYPES, h -> {
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "aura_chunk"), NaturesAuraAPI.AURA_CHUNK_ATTACHMENT);
|
||||
});
|
||||
|
||||
event.register(Registries.DATA_COMPONENT_TYPE, h -> {
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "multiblock_maker_data"), ItemMultiblockMaker.Data.TYPE);
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "aura_data"), ItemAuraContainer.Data.TYPE);
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "dropped_item_data"), BlockEntityImpl.DroppedItemData.TYPE);
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "ender_crate_data"), BlockEnderCrate.Data.TYPE);
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "aura_bottle_data"), ItemAuraBottle.Data.TYPE);
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "break_prevention_data"), ItemBreakPrevention.Data.TYPE);
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "color_changer_data"), ItemColorChanger.Data.TYPE);
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "effect_powder_data"), ItemEffectPowder.Data.TYPE);
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "shockwave_creator_data"), ItemShockwaveCreator.Data.TYPE);
|
||||
h.register(ResourceLocation.fromNamespaceAndPath(NaturesAura.MOD_ID, "disableable_tool_data"), Helper.DisableableToolData.TYPE);
|
||||
});
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
|
Loading…
Reference in a new issue