diff --git a/src/generated/resources/.cache/8202586f691eec5ad0bb88d13a278951d0c130fb b/src/generated/resources/.cache/8202586f691eec5ad0bb88d13a278951d0c130fb index 1e579f6c..f578c3ec 100644 --- a/src/generated/resources/.cache/8202586f691eec5ad0bb88d13a278951d0c130fb +++ b/src/generated/resources/.cache/8202586f691eec5ad0bb88d13a278951d0c130fb @@ -1,2 +1,2 @@ -// 1.20.4 2024-03-11T19:49:00.7736791 Languages: en_us for mod: justdirethings -b43100a43c2470204006e31370ed7becadba6ca6 assets/justdirethings/lang/en_us.json +// 1.20.4 2024-03-11T22:46:10.0136183 Languages: en_us for mod: justdirethings +bb6ed393fbe445017cf36ea6a1bc8f2f4dc62de5 assets/justdirethings/lang/en_us.json diff --git a/src/generated/resources/assets/justdirethings/lang/en_us.json b/src/generated/resources/assets/justdirethings/lang/en_us.json index 20db6e81..f8e7d1df 100644 --- a/src/generated/resources/assets/justdirethings/lang/en_us.json +++ b/src/generated/resources/assets/justdirethings/lang/en_us.json @@ -33,6 +33,7 @@ "item.justdirethings.raw_blazegold": "Raw Blazegold", "item.justdirethings.raw_ferricore": "Raw Ferricore", "itemGroup.DeferredHolder{ResourceKey[minecraft:creative_mode_tab / justdirethings:justdirethings]}": "Just Dire Things", + "justdirethings.ability.dropteleport": "Drops Teleporter", "justdirethings.ability.hammer": "Hammer", "justdirethings.ability.hammervalue": "Hammer: %s", "justdirethings.ability.lawnmower": "Lawnmower", @@ -40,6 +41,7 @@ "justdirethings.ability.mobscanner": "Mob Scanner", "justdirethings.ability.oreminer": "Ore Miner", "justdirethings.ability.orescanner": "Ore Scanner", + "justdirethings.ability.orexray": "X-Ray", "justdirethings.ability.skysweeper": "Sky Sweeper", "justdirethings.ability.smelter": "Auto Smelter", "justdirethings.ability.treefeller": "Tree Feller", diff --git a/src/main/java/com/direwolf20/justdirethings/client/renderactions/ThingFinder.java b/src/main/java/com/direwolf20/justdirethings/client/renderactions/ThingFinder.java index 1cb7f0f2..ec975976 100644 --- a/src/main/java/com/direwolf20/justdirethings/client/renderactions/ThingFinder.java +++ b/src/main/java/com/direwolf20/justdirethings/client/renderactions/ThingFinder.java @@ -88,7 +88,7 @@ public static void render(RenderLevelStageEvent evt, Player player, ItemStack he public static void discover(Player player, Ability toolAbility) { if (toolAbility.equals(Ability.MOBSCANNER)) discoverMobs(player, true); - else if (toolAbility.equals(Ability.ORESCANNER)) + else if (toolAbility.equals(Ability.ORESCANNER) || toolAbility.equals(Ability.OREXRAY)) discoverOres(player, toolAbility); } @@ -100,10 +100,10 @@ private static void discoverOres(Player player, Ability toolAbility) { .filter(blockPos -> player.level().getBlockState(blockPos).getTags().anyMatch(tag -> tag.equals(Tags.Blocks.ORES))) .map(BlockPos::immutable) .collect(Collectors.toList()); - if (!toolAbility.equals(Ability.ORESCANNER)) { //Todo Proper + if (toolAbility.equals(Ability.OREXRAY)) { xRayStartTime = System.currentTimeMillis(); generateVBO(player); - } else { + } else if (toolAbility.equals(Ability.ORESCANNER)) { blockParticlesStartTime = System.currentTimeMillis(); } } diff --git a/src/main/java/com/direwolf20/justdirethings/common/items/tools/CelestigemPickaxe.java b/src/main/java/com/direwolf20/justdirethings/common/items/tools/CelestigemPickaxe.java index 8b0d58bc..e58d9c26 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/items/tools/CelestigemPickaxe.java +++ b/src/main/java/com/direwolf20/justdirethings/common/items/tools/CelestigemPickaxe.java @@ -14,15 +14,16 @@ public class CelestigemPickaxe extends BasePickaxe implements PoweredItem { public CelestigemPickaxe() { super(GooTier.CELESTIGEM, 1, -2.8F, new Properties()); - registerAbility(Ability.ORESCANNER); + registerAbility(Ability.OREXRAY); registerAbility(Ability.OREMINER); registerAbility(Ability.SMELTER); - registerAbility(Ability.HAMMER, new AbilityParams(3, 3, 2)); + registerAbility(Ability.HAMMER, new AbilityParams(3, 5, 2)); + registerAbility(Ability.DROPTELEPORT); } @Override public InteractionResultHolder use(Level level, Player player, InteractionHand hand) { - scanFor(level, player, hand, Ability.ORESCANNER); + scanFor(level, player, hand, Ability.OREXRAY); return super.use(level, player, hand); } diff --git a/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BaseAxe.java b/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BaseAxe.java index 67626ad8..59477685 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BaseAxe.java +++ b/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BaseAxe.java @@ -8,6 +8,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; @@ -15,6 +16,7 @@ import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.*; +import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; @@ -32,6 +34,12 @@ public BaseAxe(Tier pTier, float pAttackDamageModifier, float pAttackSpeedModifi super(pTier, pAttackDamageModifier, pAttackSpeedModifier, pProperties); } + @Override + public InteractionResult useOn(UseOnContext pContext) { + bindDrops(pContext); + return super.useOn(pContext); + } + @Override public boolean mineBlock(ItemStack pStack, Level pLevel, BlockState pState, BlockPos pPos, LivingEntity pEntityLiving) { return true; //We handle damage in the BlockEvent.BreakEvent diff --git a/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BaseHoe.java b/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BaseHoe.java index e1a4cfe1..9d56f63e 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BaseHoe.java +++ b/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BaseHoe.java @@ -7,11 +7,13 @@ import net.minecraft.client.gui.screens.Screen; import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; +import net.minecraft.world.InteractionResult; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.attributes.Attribute; import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.item.*; +import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; @@ -28,6 +30,12 @@ public BaseHoe(Tier pTier, int pAttackDamageModifier, float pAttackSpeedModifier super(pTier, pAttackDamageModifier, pAttackSpeedModifier, pProperties); } + @Override + public InteractionResult useOn(UseOnContext pContext) { + bindDrops(pContext); + return super.useOn(pContext); + } + @Override public boolean mineBlock(ItemStack pStack, Level pLevel, BlockState pState, BlockPos pPos, LivingEntity pEntityLiving) { return true; //We handle damage in the BlockEvent.BreakEvent diff --git a/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BasePickaxe.java b/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BasePickaxe.java index 180d8e2b..dfac5512 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BasePickaxe.java +++ b/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BasePickaxe.java @@ -6,9 +6,12 @@ import net.minecraft.ChatFormatting; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screens.Screen; +import net.minecraft.client.resources.language.I18n; import net.minecraft.core.BlockPos; +import net.minecraft.core.GlobalPos; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; @@ -16,6 +19,7 @@ import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.*; +import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; @@ -33,6 +37,12 @@ public BasePickaxe(Tier pTier, int pAttackDamageModifier, float pAttackSpeedModi super(pTier, pAttackDamageModifier, pAttackSpeedModifier, pProperties); } + @Override + public InteractionResult useOn(UseOnContext pContext) { + bindDrops(pContext); + return super.useOn(pContext); + } + @Override public boolean mineBlock(ItemStack pStack, Level pLevel, BlockState pState, BlockPos pPos, LivingEntity pEntityLiving) { return true; //We handle damage in the BlockEvent.BreakEvent @@ -54,6 +64,7 @@ public void appendHoverText(ItemStack stack, @javax.annotation.Nullable Level le } boolean sneakPressed = Screen.hasShiftDown(); if (stack.getItem() instanceof ToggleableTool toggleableTool) { + GlobalPos boundInventory = ToggleableTool.getBoundInventory(stack); PoweredItem.appendFEText(stack, level, tooltip, flagIn); if (sneakPressed) { if (ToggleableTool.getEnabled(stack)) @@ -74,6 +85,15 @@ public void appendHoverText(ItemStack stack, @javax.annotation.Nullable Level le boolean active = ToggleableTool.getSetting(stack, ability.getName()); ChatFormatting chatFormatting = active ? ChatFormatting.GREEN : ChatFormatting.DARK_RED; tooltip.add(Component.translatable(ability.getLocalization()).withStyle(chatFormatting)); + if (ability.equals(Ability.DROPTELEPORT)) { + chatFormatting = ChatFormatting.DARK_PURPLE; + String dimString; + if (boundInventory == null) + dimString = " -Unbound"; + else + dimString = " -" + I18n.get(boundInventory.dimension().location().getPath()) + ": [" + boundInventory.pos().getX() + "," + boundInventory.pos().getY() + "," + boundInventory.pos().getZ() + "]"; + tooltip.add(Component.literal(dimString).withStyle(chatFormatting)); + } } } else { if (ToggleableTool.getEnabled(stack)) diff --git a/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BaseShovel.java b/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BaseShovel.java index 58cbe941..d3743b0f 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BaseShovel.java +++ b/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BaseShovel.java @@ -8,6 +8,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; @@ -15,6 +16,7 @@ import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.*; +import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; @@ -31,6 +33,12 @@ public BaseShovel(Tier pTier, float pAttackDamageModifier, float pAttackSpeedMod super(pTier, pAttackDamageModifier, pAttackSpeedModifier, pProperties); } + @Override + public InteractionResult useOn(UseOnContext pContext) { + bindDrops(pContext); + return super.useOn(pContext); + } + @Override public boolean mineBlock(ItemStack pStack, Level pLevel, BlockState pState, BlockPos pPos, LivingEntity pEntityLiving) { return true; //We handle damage in the BlockEvent.BreakEvent diff --git a/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BaseSword.java b/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BaseSword.java index 37acb0f1..2096e020 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BaseSword.java +++ b/src/main/java/com/direwolf20/justdirethings/common/items/tools/basetools/BaseSword.java @@ -8,6 +8,7 @@ import net.minecraft.core.BlockPos; import net.minecraft.network.chat.Component; import net.minecraft.world.InteractionHand; +import net.minecraft.world.InteractionResult; import net.minecraft.world.InteractionResultHolder; import net.minecraft.world.entity.EquipmentSlot; import net.minecraft.world.entity.LivingEntity; @@ -15,6 +16,7 @@ import net.minecraft.world.entity.ai.attributes.AttributeModifier; import net.minecraft.world.entity.player.Player; import net.minecraft.world.item.*; +import net.minecraft.world.item.context.UseOnContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.state.BlockState; @@ -36,6 +38,12 @@ public boolean mineBlock(ItemStack pStack, Level pLevel, BlockState pState, Bloc return true; //We handle damage in the BlockEvent.BreakEvent } + @Override + public InteractionResult useOn(UseOnContext pContext) { + bindDrops(pContext); + return super.useOn(pContext); + } + @Override public boolean hurtEnemy(ItemStack pStack, LivingEntity pTarget, LivingEntity pAttacker) { return hurtEnemyAbility(pStack, pTarget, pAttacker); diff --git a/src/main/java/com/direwolf20/justdirethings/common/items/tools/utils/Ability.java b/src/main/java/com/direwolf20/justdirethings/common/items/tools/utils/Ability.java index 9ed04528..a1da9eed 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/items/tools/utils/Ability.java +++ b/src/main/java/com/direwolf20/justdirethings/common/items/tools/utils/Ability.java @@ -8,6 +8,7 @@ import java.util.Map; public enum Ability { + //Tier 1 MOBSCANNER(SettingType.TOGGLE, 10, 100), //TODO Configs OREMINER(SettingType.TOGGLE, 1, 10), ORESCANNER(SettingType.TOGGLE, 10, 100), @@ -15,8 +16,12 @@ public enum Ability { SKYSWEEPER(SettingType.TOGGLE, 1, 10), TREEFELLER(SettingType.TOGGLE, 1, 10), LEAFBREAKER(SettingType.TOGGLE, 1, 10), + //Tier 2 SMELTER(SettingType.TOGGLE, 1, 10), - HAMMER(SettingType.CYCLE, 1, 10); + HAMMER(SettingType.CYCLE, 1, 10), + //Tier 3 + OREXRAY(SettingType.TOGGLE, 100, 1000), + DROPTELEPORT(SettingType.TOGGLE, 10, 100); public enum SettingType { TOGGLE, diff --git a/src/main/java/com/direwolf20/justdirethings/common/items/tools/utils/Helpers.java b/src/main/java/com/direwolf20/justdirethings/common/items/tools/utils/Helpers.java index 63059017..a5696bdc 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/items/tools/utils/Helpers.java +++ b/src/main/java/com/direwolf20/justdirethings/common/items/tools/utils/Helpers.java @@ -25,6 +25,8 @@ import net.neoforged.neoforge.common.Tags; import net.neoforged.neoforge.energy.IEnergyStorage; import net.neoforged.neoforge.event.level.BlockEvent; +import net.neoforged.neoforge.items.IItemHandler; +import net.neoforged.neoforge.items.ItemHandlerHelper; import java.util.*; import java.util.function.Predicate; @@ -189,6 +191,19 @@ public static void dropDrops(List drops, ServerLevel level, BlockPos } } + public static void teleportDrops(List drops, IItemHandler handler) { + List leftovers = new ArrayList<>(); + for (ItemStack drop : drops) { + ItemStack leftover = ItemHandlerHelper.insertItemStacked(handler, drop, false); + if (!leftover.isEmpty()) { + leftovers.add(leftover); + } + } + // Clear the original drops list and add all leftovers to it + drops.clear(); + drops.addAll(leftovers); + } + public static Set findLikeBlocks(Level pLevel, BlockState pState, BlockPos pPos, Direction direction, int maxBreak, int range) { if (direction == null) return findBlocks(pLevel, pState, pPos, maxBreak, range); diff --git a/src/main/java/com/direwolf20/justdirethings/common/items/tools/utils/ToggleableTool.java b/src/main/java/com/direwolf20/justdirethings/common/items/tools/utils/ToggleableTool.java index bfce13e3..32fbe17b 100644 --- a/src/main/java/com/direwolf20/justdirethings/common/items/tools/utils/ToggleableTool.java +++ b/src/main/java/com/direwolf20/justdirethings/common/items/tools/utils/ToggleableTool.java @@ -5,8 +5,11 @@ import com.direwolf20.justdirethings.common.events.BlockToolModification; import com.direwolf20.justdirethings.datagen.JustDireBlockTags; import com.direwolf20.justdirethings.util.MiningCollect; +import com.direwolf20.justdirethings.util.MiscHelpers; +import com.direwolf20.justdirethings.util.NBTUtils; import net.minecraft.core.BlockPos; import net.minecraft.core.Direction; +import net.minecraft.core.GlobalPos; import net.minecraft.core.particles.ParticleTypes; import net.minecraft.nbt.CompoundTag; import net.minecraft.network.chat.Component; @@ -23,8 +26,11 @@ import net.minecraft.world.level.ClipContext; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.Vec3; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.items.IItemHandler; import org.jetbrains.annotations.NotNull; import java.util.*; @@ -109,6 +115,16 @@ default void mineBlocksAbility(ItemStack pStack, Level pLevel, BlockPos pPos, Li if (smeltedItemsFlag[0]) smelterParticles((ServerLevel) pLevel, breakBlockPositions); } + if (!drops.isEmpty() && canUseAbility(pStack, Ability.DROPTELEPORT)) { + GlobalPos globalPos = getBoundInventory(pStack); + if (globalPos != null) { + IItemHandler handler = MiscHelpers.getAttachedInventory(pLevel.getServer().getLevel(globalPos.dimension()), globalPos.pos(), getBoundInventorySide(pStack)); + if (handler != null) { + teleportDrops(drops, handler); + teleportParticles((ServerLevel) pLevel, breakBlockPositions); + } + } + } if (!drops.isEmpty()) { Helpers.dropDrops(drops, (ServerLevel) pLevel, pPos); pState.getBlock().popExperience((ServerLevel) pLevel, pPos, totalExp); @@ -127,6 +143,18 @@ default void smelterParticles(ServerLevel level, Set oreBlocksList) { } } + default void teleportParticles(ServerLevel level, Set oreBlocksList) { + Random random = new Random(); + for (int i = 0; i < 5; i++) { + for (BlockPos pos : oreBlocksList) { + double d0 = (double) pos.getX() + random.nextDouble(); + double d1 = (double) pos.getY() + random.nextDouble(); + double d2 = (double) pos.getZ() + random.nextDouble(); + level.sendParticles(ParticleTypes.PORTAL, d0, d1, d2, 1, 0.0, 0.0, 0.0, 0); + } + } + } + default boolean scanFor(Level level, Player player, InteractionHand hand, Ability toolAbility) { if (!player.isShiftKeyDown()) { ItemStack itemStack = player.getItemInHand(hand); @@ -186,6 +214,23 @@ default boolean lawnmower(Level level, Player player, InteractionHand hand) { return false; } + default boolean bindDrops(UseOnContext pContext) { + Player player = pContext.getPlayer(); + if (player == null) return false; + if (!player.isShiftKeyDown()) return false; + ItemStack pStack = pContext.getItemInHand(); + if (!(pStack.getItem() instanceof ToggleableTool toggleableTool)) return false; + if (!toggleableTool.hasAbility(Ability.DROPTELEPORT)) return false; + Level pLevel = pContext.getLevel(); + BlockPos pPos = pContext.getClickedPos(); + BlockEntity blockEntity = pLevel.getBlockEntity(pPos); + if (blockEntity == null) return false; + IItemHandler handler = pLevel.getCapability(Capabilities.ItemHandler.BLOCK, pPos, pContext.getClickedFace()); + if (handler == null) return false; + setBoundInventory(pStack, GlobalPos.of(pLevel.dimension(), pPos), pContext.getClickedFace()); + return true; + } + //Thanks Soaryn! @NotNull static Direction getTargetLookDirection(LivingEntity livingEntity) { @@ -234,6 +279,26 @@ static boolean cycleSetting(ItemStack stack, String setting) { return tagCompound.getBoolean(setting); } + static void setBoundInventory(ItemStack stack, GlobalPos bindLocation, Direction side) { + CompoundTag tagCompound = stack.getOrCreateTag(); + tagCompound.put("boundinventory", NBTUtils.globalPosToNBT(bindLocation)); + tagCompound.putInt("boundinventory_side", side.ordinal()); + } + + static GlobalPos getBoundInventory(ItemStack stack) { + CompoundTag tagCompound = stack.getOrCreateTag(); + if (tagCompound.contains("boundinventory")) + return NBTUtils.nbtToGlobalPos(tagCompound.getCompound("boundinventory")); + return null; + } + + static Direction getBoundInventorySide(ItemStack stack) { + CompoundTag tagCompound = stack.getOrCreateTag(); + if (tagCompound.contains("boundinventory_side")) + return Direction.values()[tagCompound.getInt("boundinventory_side")]; + return null; + } + static boolean setSetting(ItemStack stack, String setting, boolean value) { CompoundTag tagCompound = stack.getOrCreateTag(); tagCompound.putBoolean(setting, value); diff --git a/src/main/java/com/direwolf20/justdirethings/datagen/JustDireLanguageProvider.java b/src/main/java/com/direwolf20/justdirethings/datagen/JustDireLanguageProvider.java index ab0ae79f..b08de315 100644 --- a/src/main/java/com/direwolf20/justdirethings/datagen/JustDireLanguageProvider.java +++ b/src/main/java/com/direwolf20/justdirethings/datagen/JustDireLanguageProvider.java @@ -89,6 +89,8 @@ protected void addTranslations() { add(Ability.SMELTER.getLocalization(), "Auto Smelter"); add(Ability.HAMMER.getLocalization(), "Hammer"); add(Ability.HAMMER.getLocalization() + "value", "Hammer: %s"); + add(Ability.OREXRAY.getLocalization(), "X-Ray"); + add(Ability.DROPTELEPORT.getLocalization(), "Drops Teleporter"); //GUI add("justdirethings.screen.energy", "Energy: %s/%s FE"); diff --git a/src/main/java/com/direwolf20/justdirethings/util/MiscHelpers.java b/src/main/java/com/direwolf20/justdirethings/util/MiscHelpers.java index e9033988..c2c31f5f 100644 --- a/src/main/java/com/direwolf20/justdirethings/util/MiscHelpers.java +++ b/src/main/java/com/direwolf20/justdirethings/util/MiscHelpers.java @@ -1,5 +1,12 @@ package com.direwolf20.justdirethings.util; +import net.minecraft.core.BlockPos; +import net.minecraft.core.Direction; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.neoforged.neoforge.capabilities.Capabilities; +import net.neoforged.neoforge.items.IItemHandler; + import java.util.Random; public class MiscHelpers { @@ -8,4 +15,15 @@ public class MiscHelpers { public static double nextDouble(double min, double max) { return min + (max - min) * rand.nextDouble(); } + + public static IItemHandler getAttachedInventory(Level level, BlockPos blockPos, Direction side) { + assert level != null; + BlockEntity be = level.getBlockEntity(blockPos); + // if we have a TE and its an item handler, try extracting from that + if (be != null) { + IItemHandler handler = level.getCapability(Capabilities.ItemHandler.BLOCK, blockPos, side); + return handler; + } + return null; + } } diff --git a/src/main/java/com/direwolf20/justdirethings/util/NBTUtils.java b/src/main/java/com/direwolf20/justdirethings/util/NBTUtils.java index 7db2eeef..08602e39 100644 --- a/src/main/java/com/direwolf20/justdirethings/util/NBTUtils.java +++ b/src/main/java/com/direwolf20/justdirethings/util/NBTUtils.java @@ -1,7 +1,14 @@ package com.direwolf20.justdirethings.util; +import net.minecraft.core.BlockPos; +import net.minecraft.core.GlobalPos; +import net.minecraft.core.registries.Registries; import net.minecraft.nbt.CompoundTag; +import net.minecraft.nbt.NbtUtils; +import net.minecraft.resources.ResourceKey; +import net.minecraft.resources.ResourceLocation; import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.Level; public class NBTUtils { public static boolean toggleBoolean(ItemStack itemStack, String name) { @@ -27,4 +34,17 @@ public static int setIntValue(ItemStack itemStack, String name, int value) { itemStack.getOrCreateTag().putInt(name, value); return value; } + + public static CompoundTag globalPosToNBT(GlobalPos globalPos) { + CompoundTag tag = new CompoundTag(); + tag.putString("level", globalPos.dimension().location().toString()); + tag.put("blockpos", NbtUtils.writeBlockPos(globalPos.pos())); + return tag; + } + + public static GlobalPos nbtToGlobalPos(CompoundTag tag) { + ResourceKey levelKey = ResourceKey.create(Registries.DIMENSION, new ResourceLocation(tag.getString("level"))); + BlockPos blockPos = NbtUtils.readBlockPos(tag.getCompound("blockpos")); + return GlobalPos.of(levelKey, blockPos); + } } diff --git a/src/main/resources/assets/justdirethings/textures/gui/buttons/dropteleport.png b/src/main/resources/assets/justdirethings/textures/gui/buttons/dropteleport.png new file mode 100644 index 00000000..8c5765bd Binary files /dev/null and b/src/main/resources/assets/justdirethings/textures/gui/buttons/dropteleport.png differ diff --git a/src/main/resources/assets/justdirethings/textures/gui/buttons/orexray.png b/src/main/resources/assets/justdirethings/textures/gui/buttons/orexray.png new file mode 100644 index 00000000..ead6c621 Binary files /dev/null and b/src/main/resources/assets/justdirethings/textures/gui/buttons/orexray.png differ