mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-10-30 14:20:49 +01:00
even more brr...
This commit is contained in:
parent
cbf7135fbd
commit
f4fa79d8cc
8 changed files with 56 additions and 25 deletions
|
@ -18,6 +18,8 @@ import de.ellpeck.actuallyadditions.mod.sack.SackData;
|
||||||
import de.ellpeck.actuallyadditions.mod.sack.SackManager;
|
import de.ellpeck.actuallyadditions.mod.sack.SackManager;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.core.component.DataComponents;
|
||||||
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.server.level.ServerPlayer;
|
import net.minecraft.server.level.ServerPlayer;
|
||||||
import net.minecraft.world.InteractionHand;
|
import net.minecraft.world.InteractionHand;
|
||||||
import net.minecraft.world.InteractionResult;
|
import net.minecraft.world.InteractionResult;
|
||||||
|
@ -25,6 +27,7 @@ import net.minecraft.world.InteractionResultHolder;
|
||||||
import net.minecraft.world.SimpleMenuProvider;
|
import net.minecraft.world.SimpleMenuProvider;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
import net.minecraft.world.item.component.CustomData;
|
||||||
import net.minecraft.world.item.context.UseOnContext;
|
import net.minecraft.world.item.context.UseOnContext;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.entity.BlockEntity;
|
||||||
|
@ -116,8 +119,27 @@ public class Sack extends ItemBase {
|
||||||
public static SackData getData(ItemStack stack) {
|
public static SackData getData(ItemStack stack) {
|
||||||
if (!(stack.getItem() instanceof Sack))
|
if (!(stack.getItem() instanceof Sack))
|
||||||
return null;
|
return null;
|
||||||
UUID uuid = stack.getOrDefault(ActuallyComponents.UUID.get(), UUID.randomUUID());
|
|
||||||
stack.set(ActuallyComponents.UUID.get(), uuid);
|
UUID uuid;
|
||||||
|
|
||||||
|
if (stack.has(ActuallyComponents.UUID))
|
||||||
|
uuid = stack.get(ActuallyComponents.UUID);
|
||||||
|
else if(stack.has(DataComponents.CUSTOM_DATA)) {
|
||||||
|
CompoundTag tag = stack.get(DataComponents.CUSTOM_DATA).copyTag();
|
||||||
|
if (tag.contains("UUID")) {
|
||||||
|
uuid = tag.getUUID("UUID");
|
||||||
|
stack.set(ActuallyComponents.UUID, uuid);
|
||||||
|
stack.update(DataComponents.CUSTOM_DATA, CustomData.EMPTY, $ -> $.update(compoundTag -> compoundTag.remove("UUID")));
|
||||||
|
} else {
|
||||||
|
uuid = UUID.randomUUID();
|
||||||
|
stack.set(ActuallyComponents.UUID, uuid);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
uuid = UUID.randomUUID();
|
||||||
|
stack.set(ActuallyComponents.UUID, uuid);
|
||||||
|
}
|
||||||
|
|
||||||
return SackManager.get().getOrCreateSack(uuid);
|
return SackManager.get().getOrCreateSack(uuid);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -26,6 +26,7 @@ import net.minecraft.core.Vec3i;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
import net.minecraft.core.registries.BuiltInRegistries;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.world.effect.MobEffect;
|
import net.minecraft.world.effect.MobEffect;
|
||||||
import net.minecraft.world.effect.MobEffectInstance;
|
import net.minecraft.world.effect.MobEffectInstance;
|
||||||
import net.minecraft.world.effect.MobEffects;
|
import net.minecraft.world.effect.MobEffects;
|
||||||
|
@ -274,7 +275,8 @@ public class MethodHandler implements IMethodHandler {
|
||||||
BlockPos hitBlock = tile.getPosition().relative(sideToManipulate, i + 1);
|
BlockPos hitBlock = tile.getPosition().relative(sideToManipulate, i + 1);
|
||||||
|
|
||||||
if (currentLens.invoke(tile.getWorldObject().getBlockState(hitBlock), hitBlock, tile) || i >= distance - 1) {
|
if (currentLens.invoke(tile.getWorldObject().getBlockState(hitBlock), hitBlock, tile) || i >= distance - 1) {
|
||||||
TileEntityAtomicReconstructor.shootLaser(tile, tile.getWorldObject(), tile.getX(), tile.getY(), tile.getZ(), hitBlock.getX(), hitBlock.getY(), hitBlock.getZ(), currentLens);
|
if (tile.getWorldObject() instanceof ServerLevel level)
|
||||||
|
TileEntityAtomicReconstructor.shootLaser(tile, level, tile.getX(), tile.getY(), tile.getZ(), hitBlock.getX(), hitBlock.getY(), hitBlock.getZ(), currentLens);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,12 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.sack;
|
package de.ellpeck.actuallyadditions.mod.sack;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||||
|
import net.minecraft.core.HolderLookup;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.neoforged.neoforge.common.util.INBTSerializable;
|
import net.neoforged.neoforge.common.util.INBTSerializable;
|
||||||
import net.neoforged.neoforge.items.IItemHandler;
|
import net.neoforged.neoforge.items.IItemHandler;
|
||||||
|
|
||||||
|
import javax.annotation.Nonnull;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@ -53,7 +55,7 @@ public class SackData {
|
||||||
optional = Optional.ofNullable(inventory);
|
optional = Optional.ofNullable(inventory);
|
||||||
}
|
}
|
||||||
|
|
||||||
public SackData(UUID uuid, CompoundTag incoming) {
|
public SackData(UUID uuid, CompoundTag incoming, HolderLookup.Provider provider) {
|
||||||
this.uuid = uuid;
|
this.uuid = uuid;
|
||||||
|
|
||||||
inventory = new ItemStackHandlerAA(SIZE){
|
inventory = new ItemStackHandlerAA(SIZE){
|
||||||
|
@ -65,34 +67,34 @@ public class SackData {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
inventory.deserializeNBT(incoming.getCompound("Inventory"));
|
inventory.deserializeNBT(provider, incoming.getCompound("Inventory"));
|
||||||
|
|
||||||
optional = Optional.ofNullable(inventory);
|
optional = Optional.ofNullable(inventory);
|
||||||
|
|
||||||
if (incoming.contains("Metadata"))
|
if (incoming.contains("Metadata"))
|
||||||
meta.deserializeNBT(incoming.getCompound("Metadata"));
|
meta.deserializeNBT(provider, incoming.getCompound("Metadata"));
|
||||||
}
|
}
|
||||||
|
|
||||||
public UUID getUuid() {
|
public UUID getUuid() {
|
||||||
return uuid;
|
return uuid;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Optional<SackData> fromNBT(CompoundTag nbt) {
|
public static Optional<SackData> fromNBT(CompoundTag nbt, HolderLookup.Provider provider) {
|
||||||
if (nbt.contains("UUID")) {
|
if (nbt.contains("UUID")) {
|
||||||
UUID uuid = nbt.getUUID("UUID");
|
UUID uuid = nbt.getUUID("UUID");
|
||||||
return Optional.of(new SackData(uuid, nbt));
|
return Optional.of(new SackData(uuid, nbt, provider));
|
||||||
}
|
}
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public CompoundTag toNBT() {
|
public CompoundTag toNBT(HolderLookup.Provider provider) {
|
||||||
CompoundTag nbt = new CompoundTag();
|
CompoundTag nbt = new CompoundTag();
|
||||||
|
|
||||||
nbt.putUUID("UUID", uuid);
|
nbt.putUUID("UUID", uuid);
|
||||||
|
|
||||||
nbt.put("Inventory", inventory.serializeNBT());
|
nbt.put("Inventory", inventory.serializeNBT(provider));
|
||||||
|
|
||||||
nbt.put("Metadata", meta.serializeNBT());
|
nbt.put("Metadata", meta.serializeNBT(provider));
|
||||||
|
|
||||||
return nbt;
|
return nbt;
|
||||||
}
|
}
|
||||||
|
@ -128,7 +130,7 @@ public class SackData {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompoundTag serializeNBT() {
|
public CompoundTag serializeNBT(@Nonnull HolderLookup.Provider provider) {
|
||||||
CompoundTag nbt = new CompoundTag();
|
CompoundTag nbt = new CompoundTag();
|
||||||
|
|
||||||
nbt.putString("firstPlayer", firstAccessedPlayer);
|
nbt.putString("firstPlayer", firstAccessedPlayer);
|
||||||
|
@ -140,7 +142,7 @@ public class SackData {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void deserializeNBT(CompoundTag nbt) {
|
public void deserializeNBT(@Nonnull HolderLookup.Provider provider, CompoundTag nbt) {
|
||||||
firstAccessedPlayer = nbt.getString("firstPlayer");
|
firstAccessedPlayer = nbt.getString("firstPlayer");
|
||||||
firstAccessedTime = nbt.getLong("firstTime");
|
firstAccessedTime = nbt.getLong("firstTime");
|
||||||
lastAccessedPlayer = nbt.getString("lastPlayer");
|
lastAccessedPlayer = nbt.getString("lastPlayer");
|
||||||
|
|
|
@ -1,7 +1,9 @@
|
||||||
package de.ellpeck.actuallyadditions.mod.sack;
|
package de.ellpeck.actuallyadditions.mod.sack;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||||
|
import de.ellpeck.actuallyadditions.mod.components.ActuallyComponents;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
import de.ellpeck.actuallyadditions.mod.util.ItemStackHandlerAA;
|
||||||
|
import net.minecraft.core.HolderLookup;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
import net.minecraft.nbt.ListTag;
|
import net.minecraft.nbt.ListTag;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
@ -62,8 +64,8 @@ public class SackManager extends SavedData {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<IItemHandler> getCapability(ItemStack stack) {
|
public Optional<IItemHandler> getCapability(ItemStack stack) {
|
||||||
if (stack.getOrCreateTag().contains("UUID")) {
|
if (stack.has(ActuallyComponents.UUID)) {
|
||||||
UUID uuid = stack.getTag().getUUID("UUID");
|
UUID uuid = stack.get(ActuallyComponents.UUID);
|
||||||
if (data.containsKey(uuid))
|
if (data.containsKey(uuid))
|
||||||
return data.get(uuid).getOptional();
|
return data.get(uuid).getOptional();
|
||||||
}
|
}
|
||||||
|
@ -72,8 +74,8 @@ public class SackManager extends SavedData {
|
||||||
}
|
}
|
||||||
|
|
||||||
public Optional<ItemStackHandlerAA> getHandler(ItemStack stack) {
|
public Optional<ItemStackHandlerAA> getHandler(ItemStack stack) {
|
||||||
if (stack.getOrCreateTag().contains("UUID")) {
|
if (stack.has(ActuallyComponents.UUID)) {
|
||||||
UUID uuid = stack.getTag().getUUID("UUID");
|
UUID uuid = stack.get(ActuallyComponents.UUID);
|
||||||
if (data.containsKey(uuid))
|
if (data.containsKey(uuid))
|
||||||
return Optional.of(data.get(uuid).getSpecialHandler());
|
return Optional.of(data.get(uuid).getSpecialHandler());
|
||||||
}
|
}
|
||||||
|
@ -81,19 +83,19 @@ public class SackManager extends SavedData {
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
public static SackManager load(CompoundTag nbt) {
|
public static SackManager load(CompoundTag nbt, HolderLookup.Provider provider) {
|
||||||
if (nbt.contains("Sacks")) {
|
if (nbt.contains("Sacks")) {
|
||||||
ListTag list = nbt.getList("Sacks", CompoundTag.TAG_COMPOUND);
|
ListTag list = nbt.getList("Sacks", CompoundTag.TAG_COMPOUND);
|
||||||
list.forEach((sackNBT) -> SackData.fromNBT((CompoundTag) sackNBT).ifPresent((sack) -> data.put(sack.getUuid(), sack)));
|
list.forEach((sackNBT) -> SackData.fromNBT((CompoundTag) sackNBT, provider).ifPresent((sack) -> data.put(sack.getUuid(), sack)));
|
||||||
}
|
}
|
||||||
return new SackManager();
|
return new SackManager();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@Nonnull
|
@Nonnull
|
||||||
public CompoundTag save(CompoundTag compound) {
|
public CompoundTag save(CompoundTag compound, HolderLookup.Provider provider) {
|
||||||
ListTag sacks = new ListTag();
|
ListTag sacks = new ListTag();
|
||||||
data.forEach(((uuid, sackData) -> sacks.add(sackData.toNBT())));
|
data.forEach(((uuid, sackData) -> sacks.add(sackData.toNBT(provider))));
|
||||||
compound.put("Sacks", sacks);
|
compound.put("Sacks", sacks);
|
||||||
return compound;
|
return compound;
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,6 +24,7 @@ import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.HolderLookup;
|
import net.minecraft.core.HolderLookup;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
import net.minecraft.util.Mth;
|
import net.minecraft.util.Mth;
|
||||||
import net.minecraft.world.item.Item;
|
import net.minecraft.world.item.Item;
|
||||||
|
@ -50,7 +51,7 @@ public class TileEntityAtomicReconstructor extends TileEntityInventoryBase imple
|
||||||
this.storage = new CustomEnergyStorage(power, recieve, 0);
|
this.storage = new CustomEnergyStorage(power, recieve, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void shootLaser(IAtomicReconstructor tile, Level world, double startX, double startY, double startZ, double endX, double endY, double endZ, Lens currentLens) {
|
public static void shootLaser(IAtomicReconstructor tile, ServerLevel world, double startX, double startY, double startZ, double endX, double endY, double endZ, Lens currentLens) {
|
||||||
world.playSound(null, startX, startY, startZ, AASounds.RECONSTRUCTOR.get(), SoundSource.BLOCKS, 0.35F, 1.0F);
|
world.playSound(null, startX, startY, startZ, AASounds.RECONSTRUCTOR.get(), SoundSource.BLOCKS, 0.35F, 1.0F);
|
||||||
AssetUtil.spawnLaserWithTimeServer(world, startX, startY, startZ, endX, endY, endZ, currentLens.getColor(), 25, 0, 0.2F, 0.8F);
|
AssetUtil.spawnLaserWithTimeServer(world, startX, startY, startZ, endX, endY, endZ, currentLens.getColor(), 25, 0, 0.2F, 0.8F);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,6 +17,7 @@ import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.Direction;
|
import net.minecraft.core.Direction;
|
||||||
import net.minecraft.core.HolderLookup;
|
import net.minecraft.core.HolderLookup;
|
||||||
import net.minecraft.nbt.CompoundTag;
|
import net.minecraft.nbt.CompoundTag;
|
||||||
|
import net.minecraft.server.level.ServerLevel;
|
||||||
import net.minecraft.tags.BlockTags;
|
import net.minecraft.tags.BlockTags;
|
||||||
import net.minecraft.world.level.Level;
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
|
@ -88,7 +89,7 @@ public class TileEntityLeafGenerator extends TileEntityBase implements ISharingE
|
||||||
|
|
||||||
tile.storage.receiveEnergy(energyProduced, false);
|
tile.storage.receiveEnergy(energyProduced, false);
|
||||||
|
|
||||||
AssetUtil.spawnLaserWithTimeServer(level, pos.getX(), pos.getY(), pos.getZ(), theCoord.getX(), theCoord.getY(), theCoord.getZ(), 0x3EA34A, 25, 0, 0.075F, 0.8F);
|
AssetUtil.spawnLaserWithTimeServer((ServerLevel) level, pos.getX(), pos.getY(), pos.getZ(), theCoord.getX(), theCoord.getY(), theCoord.getZ(), 0x3EA34A, 25, 0, 0.075F, 0.8F);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -197,7 +197,7 @@ public class TileEntityVerticalDigger extends TileEntityInventoryBase implements
|
||||||
}
|
}
|
||||||
|
|
||||||
private void shootParticles(int endX, int endY, int endZ) {
|
private void shootParticles(int endX, int endY, int endZ) {
|
||||||
AssetUtil.spawnLaserWithTimeServer(this.level, this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), endX, endY, endZ, 0x429602, 10, 120, 0.1F, 0.8F);
|
AssetUtil.spawnLaserWithTimeServer((ServerLevel) this.level, this.worldPosition.getX(), this.worldPosition.getY(), this.worldPosition.getZ(), endX, endY, endZ, 0x429602, 10, 120, 0.1F, 0.8F);
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean isBlacklisted(Block block) {
|
private boolean isBlacklisted(Block block) {
|
||||||
|
|
|
@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.util;
|
||||||
|
|
||||||
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
|
||||||
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
import net.minecraft.world.entity.ai.attributes.AttributeInstance;
|
||||||
|
import net.minecraft.world.entity.ai.attributes.Attributes;
|
||||||
import net.minecraft.world.entity.player.Player;
|
import net.minecraft.world.entity.player.Player;
|
||||||
import net.neoforged.fml.loading.FMLLoader;
|
import net.neoforged.fml.loading.FMLLoader;
|
||||||
import net.neoforged.neoforge.common.NeoForgeMod;
|
import net.neoforged.neoforge.common.NeoForgeMod;
|
||||||
|
@ -45,7 +46,7 @@ public final class Util {
|
||||||
}
|
}
|
||||||
|
|
||||||
public static double getReachDistance(Player player) {
|
public static double getReachDistance(Player player) {
|
||||||
AttributeInstance attribute = player.getAttribute(NeoForgeMod.BLOCK_REACH.value());
|
AttributeInstance attribute = player.getAttribute(Attributes.BLOCK_INTERACTION_RANGE);
|
||||||
return attribute == null ? 4.5d : attribute.getValue();
|
return attribute == null ? 4.5d : attribute.getValue();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue