mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-10-30 14:20:49 +01:00
Just filler things lol.
This commit is contained in:
parent
2e394d9230
commit
d0b7e95ed5
3 changed files with 43 additions and 31 deletions
|
@ -12,6 +12,8 @@ import net.minecraft.resources.ResourceKey;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.item.component.ItemContainerContents;
|
import net.minecraft.world.item.component.ItemContainerContents;
|
||||||
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.state.BlockState;
|
||||||
import net.neoforged.bus.api.IEventBus;
|
import net.neoforged.bus.api.IEventBus;
|
||||||
import net.neoforged.neoforge.registries.DeferredRegister;
|
import net.neoforged.neoforge.registries.DeferredRegister;
|
||||||
|
|
||||||
|
@ -115,6 +117,28 @@ public class ActuallyComponents {
|
||||||
.networkSynchronized(ByteBufCodecs.INT)
|
.networkSynchronized(ByteBufCodecs.INT)
|
||||||
.build());
|
.build());
|
||||||
|
|
||||||
|
public static final Supplier<DataComponentType<BlockState>> BLOCKSTATE = DATA_COMPONENT_TYPES.register("blockstate", () ->
|
||||||
|
DataComponentType.<BlockState>builder()
|
||||||
|
.persistent(BlockState.CODEC)
|
||||||
|
.networkSynchronized(ByteBufCodecs.idMapper(Block.BLOCK_STATE_REGISTRY))
|
||||||
|
.build());
|
||||||
|
|
||||||
|
public static final Supplier<DataComponentType<BlockPos>> FILLER_FIRST = DATA_COMPONENT_TYPES.register("filler_first", () ->
|
||||||
|
DataComponentType.<BlockPos>builder()
|
||||||
|
.persistent(BlockPos.CODEC)
|
||||||
|
.networkSynchronized(BlockPos.STREAM_CODEC)
|
||||||
|
.build());
|
||||||
|
public static final Supplier<DataComponentType<BlockPos>> FILLER_SECOND = DATA_COMPONENT_TYPES.register("filler_second", () ->
|
||||||
|
DataComponentType.<BlockPos>builder()
|
||||||
|
.persistent(BlockPos.CODEC)
|
||||||
|
.networkSynchronized(BlockPos.STREAM_CODEC)
|
||||||
|
.build());
|
||||||
|
public static final Supplier<DataComponentType<BlockPos>> FILLER_CURRENT = DATA_COMPONENT_TYPES.register("filler_current", () ->
|
||||||
|
DataComponentType.<BlockPos>builder()
|
||||||
|
.persistent(BlockPos.CODEC)
|
||||||
|
.networkSynchronized(BlockPos.STREAM_CODEC)
|
||||||
|
.build());
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* This is a supplier for an attachment type that can be used to attach an energy storage to an item.
|
* This is a supplier for an attachment type that can be used to attach an energy storage to an item.
|
||||||
|
|
|
@ -10,13 +10,11 @@
|
||||||
|
|
||||||
package de.ellpeck.actuallyadditions.mod.items;
|
package de.ellpeck.actuallyadditions.mod.items;
|
||||||
|
|
||||||
|
import de.ellpeck.actuallyadditions.mod.components.ActuallyComponents;
|
||||||
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
|
import de.ellpeck.actuallyadditions.mod.items.base.ItemEnergy;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
import de.ellpeck.actuallyadditions.mod.util.StackUtil;
|
||||||
import de.ellpeck.actuallyadditions.mod.util.Util;
|
import de.ellpeck.actuallyadditions.mod.util.Util;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
import net.minecraft.core.registries.BuiltInRegistries;
|
|
||||||
import net.minecraft.nbt.CompoundTag;
|
|
||||||
import net.minecraft.nbt.NbtUtils;
|
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.network.chat.MutableComponent;
|
import net.minecraft.network.chat.MutableComponent;
|
||||||
import net.minecraft.sounds.SoundSource;
|
import net.minecraft.sounds.SoundSource;
|
||||||
|
@ -66,14 +64,13 @@ public class Filler extends ItemEnergy {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void saveData(BlockState state, ItemStack wand) {
|
private static void saveData(BlockState state, ItemStack wand) {
|
||||||
wand.getOrCreateTag().put("state", NbtUtils.writeBlockState(state));
|
wand.set(ActuallyComponents.BLOCKSTATE, state);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Optional<BlockState> loadData(ItemStack stack) {
|
private static Optional<BlockState> loadData(ItemStack stack) {
|
||||||
if (stack.getOrCreateTag().contains("state")) {
|
if (stack.has(ActuallyComponents.BLOCKSTATE)) {
|
||||||
return Optional.of(NbtUtils.readBlockState(BuiltInRegistries.BLOCK.asLookup(), stack.getOrCreateTag().getCompound("state")));
|
return Optional.ofNullable(stack.get(ActuallyComponents.BLOCKSTATE));
|
||||||
}
|
}
|
||||||
|
|
||||||
return Optional.empty();
|
return Optional.empty();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -90,12 +87,9 @@ public class Filler extends ItemEnergy {
|
||||||
saveData(state, stack);
|
saveData(state, stack);
|
||||||
return InteractionResult.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
} else if (loadData(stack).isPresent()) {
|
} else if (loadData(stack).isPresent()) {
|
||||||
CompoundTag compound = stack.getOrCreateTag();
|
if (stack.getOrDefault(ActuallyComponents.FILLER_CURRENT, BlockPos.ZERO).equals(BlockPos.ZERO)) {
|
||||||
|
|
||||||
if (compound.getInt("CurrX") == 0 && compound.getInt("CurrY") == 0 && compound.getInt("CurrZ") == 0) {
|
stack.set(ActuallyComponents.FILLER_FIRST, new BlockPos(context.getClickedPos()));
|
||||||
compound.putInt("FirstX", context.getClickedPos().getX());
|
|
||||||
compound.putInt("FirstY", context.getClickedPos().getY());
|
|
||||||
compound.putInt("FirstZ", context.getClickedPos().getZ());
|
|
||||||
|
|
||||||
context.getPlayer().startUsingItem(context.getHand());
|
context.getPlayer().startUsingItem(context.getHand());
|
||||||
return InteractionResult.SUCCESS;
|
return InteractionResult.SUCCESS;
|
||||||
|
@ -112,19 +106,16 @@ public class Filler extends ItemEnergy {
|
||||||
if (entity instanceof Player player) {
|
if (entity instanceof Player player) {
|
||||||
HitResult result = player.pick(Util.getReachDistance(player), 1f, false);
|
HitResult result = player.pick(Util.getReachDistance(player), 1f, false);
|
||||||
if (result instanceof BlockHitResult) {
|
if (result instanceof BlockHitResult) {
|
||||||
CompoundTag compound = stack.getOrCreateTag();
|
|
||||||
|
|
||||||
BlockPos pos = ((BlockHitResult) result).getBlockPos();
|
BlockPos pos = ((BlockHitResult) result).getBlockPos();
|
||||||
compound.putInt("SecondX", pos.getX());
|
|
||||||
compound.putInt("SecondY", pos.getY());
|
stack.set(ActuallyComponents.FILLER_SECOND, new BlockPos(pos));
|
||||||
compound.putInt("SecondZ", pos.getZ());
|
|
||||||
|
|
||||||
clear = false;
|
clear = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (clear) {
|
if (clear) {
|
||||||
ItemPhantomConnector.clearStorage(stack, "FirstX", "FirstY", "FirstZ");
|
ItemPhantomConnector.clearStorage(stack, ActuallyComponents.FILLER_FIRST.get(), ActuallyComponents.FILLER_SECOND.get(), ActuallyComponents.FILLER_CURRENT.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -140,13 +131,12 @@ public class Filler extends ItemEnergy {
|
||||||
boolean shouldClear = false;
|
boolean shouldClear = false;
|
||||||
|
|
||||||
if (isSelected) {
|
if (isSelected) {
|
||||||
if (entity instanceof Player player && stack.hasTag()) {
|
if (entity instanceof Player player) {
|
||||||
boolean creative = player.isCreative();
|
boolean creative = player.isCreative();
|
||||||
|
|
||||||
CompoundTag compound = stack.getOrCreateTag();
|
BlockPos firstPos = stack.getOrDefault(ActuallyComponents.FILLER_FIRST, BlockPos.ZERO);
|
||||||
|
BlockPos secondPos = stack.getOrDefault(ActuallyComponents.FILLER_SECOND, BlockPos.ZERO);
|
||||||
BlockPos firstPos = new BlockPos(compound.getInt("FirstX"), compound.getInt("FirstY"), compound.getInt("FirstZ"));
|
BlockPos currentPos = stack.getOrDefault(ActuallyComponents.FILLER_CURRENT, BlockPos.ZERO);
|
||||||
BlockPos secondPos = new BlockPos(compound.getInt("SecondX"), compound.getInt("SecondY"), compound.getInt("SecondZ"));
|
|
||||||
|
|
||||||
if (!BlockPos.ZERO.equals(firstPos) && !BlockPos.ZERO.equals(secondPos)) {
|
if (!BlockPos.ZERO.equals(firstPos) && !BlockPos.ZERO.equals(secondPos)) {
|
||||||
int energyUse = 1500;
|
int energyUse = 1500;
|
||||||
|
@ -158,9 +148,9 @@ public class Filler extends ItemEnergy {
|
||||||
int lowestY = Math.min(firstPos.getY(), secondPos.getY());
|
int lowestY = Math.min(firstPos.getY(), secondPos.getY());
|
||||||
int lowestZ = Math.min(firstPos.getZ(), secondPos.getZ());
|
int lowestZ = Math.min(firstPos.getZ(), secondPos.getZ());
|
||||||
|
|
||||||
int currX = compound.getInt("CurrX");
|
int currX = currentPos.getX();
|
||||||
int currY = compound.getInt("CurrY");
|
int currY = currentPos.getY();
|
||||||
int currZ = compound.getInt("CurrZ");
|
int currZ = currentPos.getZ();
|
||||||
|
|
||||||
BlockPos pos = new BlockPos(lowestX + currX, lowestY + currY, lowestZ + currZ);
|
BlockPos pos = new BlockPos(lowestX + currX, lowestY + currY, lowestZ + currZ);
|
||||||
BlockState state = world.getBlockState(pos);
|
BlockState state = world.getBlockState(pos);
|
||||||
|
@ -198,9 +188,7 @@ public class Filler extends ItemEnergy {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!shouldClear) {
|
if (!shouldClear) {
|
||||||
compound.putInt("CurrX", currX);
|
stack.set(ActuallyComponents.FILLER_CURRENT, new BlockPos(currX, currY, currZ));
|
||||||
compound.putInt("CurrY", currY);
|
|
||||||
compound.putInt("CurrZ", currZ);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
shouldClear = true;
|
shouldClear = true;
|
||||||
|
@ -212,7 +200,7 @@ public class Filler extends ItemEnergy {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (shouldClear) {
|
if (shouldClear) {
|
||||||
ItemPhantomConnector.clearStorage(stack, "FirstX", "FirstY", "FirstZ", "SecondX", "SecondY", "SecondZ", "CurrX", "CurrY", "CurrZ");
|
ItemPhantomConnector.clearStorage(stack, ActuallyComponents.FILLER_FIRST.get(), ActuallyComponents.FILLER_SECOND.get(), ActuallyComponents.FILLER_CURRENT.get());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue