From d55f60261f6d85467047a8c60b83a397b8098704 Mon Sep 17 00:00:00 2001 From: trinsdar <30245301+Trinsdar@users.noreply.github.com> Date: Sun, 3 Mar 2024 17:14:27 -0500 Subject: [PATCH] updated antimatter, did more work on electric tools --- AntimatterAPI | 2 +- .../java/trinsdar/gt4r/data/GT4RData.java | 5 + .../trinsdar/gt4r/items/IElectricTool.java | 136 +----------------- .../trinsdar/gt4r/items/ItemElectricTool.java | 15 +- 4 files changed, 22 insertions(+), 136 deletions(-) diff --git a/AntimatterAPI b/AntimatterAPI index 2e7bc7fe..5d37a016 160000 --- a/AntimatterAPI +++ b/AntimatterAPI @@ -1 +1 @@ -Subproject commit 2e7bc7fe174cee6e482e9e77e41531151cb87d78 +Subproject commit 5d37a016aacf1c294b002398bb685b431eb3686a diff --git a/common/src/main/java/trinsdar/gt4r/data/GT4RData.java b/common/src/main/java/trinsdar/gt4r/data/GT4RData.java index 98caed5b..1101c757 100644 --- a/common/src/main/java/trinsdar/gt4r/data/GT4RData.java +++ b/common/src/main/java/trinsdar/gt4r/data/GT4RData.java @@ -1,6 +1,7 @@ package trinsdar.gt4r.data; import earth.terrarium.botarium.common.registry.fluid.FluidProperties; +import io.github.gregtechintergalactical.gtcore.data.GTCoreTools; import muramasa.antimatter.AntimatterAPI; import muramasa.antimatter.Ref; import muramasa.antimatter.cover.CoverFactory; @@ -11,6 +12,7 @@ import muramasa.antimatter.item.ItemCover; import muramasa.antimatter.item.ItemFluidCell; import muramasa.antimatter.machine.Tier; +import muramasa.antimatter.material.MaterialTags; import muramasa.antimatter.ore.CobbleStoneType; import muramasa.antimatter.ore.StoneType; import muramasa.antimatter.pipe.PipeSize; @@ -42,6 +44,7 @@ import trinsdar.gt4r.cover.redstone.CoverRedstoneMachineController; import trinsdar.gt4r.data.client.RecipeRenderer; import trinsdar.gt4r.items.ItemCraftingModule; +import trinsdar.gt4r.items.ItemElectricTool; import trinsdar.gt4r.items.ItemMixedMetal; import trinsdar.gt4r.items.ItemPowerUnit; import trinsdar.gt4r.items.ItemStorageOrb; @@ -133,6 +136,8 @@ private static Block.Properties prepareProperties() { public static ItemBasic MachineParts = new ItemBasic<>(GT4RRef.ID, "machine_parts"); public static ItemBasic StorageDataOrb = new ItemStorageOrb(GT4RRef.ID, "storage_data_orb").tip("A High Capacity Data Storage"); + public static ItemElectricTool DRILL = new ItemElectricTool("drill", GTCoreTools.DRILL, 6.0f, 2, 1); + public static ItemBasic ZPM = new ItemBattery(GT4RRef.ID, "zpm", Tier.ZPM, 100000000000L, false); //public static ItemBasic BatteryEnergyOrbCluster = new ItemBasic<>(Ref.ID, "battery_energy_orb_cluster"); diff --git a/common/src/main/java/trinsdar/gt4r/items/IElectricTool.java b/common/src/main/java/trinsdar/gt4r/items/IElectricTool.java index 086c24b1..a26deb2a 100644 --- a/common/src/main/java/trinsdar/gt4r/items/IElectricTool.java +++ b/common/src/main/java/trinsdar/gt4r/items/IElectricTool.java @@ -16,6 +16,7 @@ import muramasa.antimatter.tool.AntimatterToolType; import muramasa.antimatter.tool.IAbstractToolMethods; import muramasa.antimatter.tool.IAntimatterTool; +import muramasa.antimatter.tool.IBasicAntimatterTool; import muramasa.antimatter.tool.ToolUtils; import muramasa.antimatter.util.Utils; import net.minecraft.ChatFormatting; @@ -54,12 +55,7 @@ import java.util.Map; import java.util.Set; -public interface IElectricTool extends IAbstractToolMethods, IEnergyItem { - - AntimatterToolType getAntimatterToolType(); - - Tier getItemTier(); - +public interface IElectricTool extends IBasicAntimatterTool, IEnergyItem { default int getPoweredBarColor(ItemStack stack){ return 0x00BFFF; } @@ -77,14 +73,6 @@ default boolean isPoweredBarVisible(ItemStack stack) { return getCurrentEnergy(stack) > 0; } - default Item getItem() { - return (Item) this; - } - - default Set> getActualTags() { - return getAntimatterToolType().getToolTypes(); - } - default long getCurrentEnergy(ItemStack stack) { return getEnergyTag(stack).getLong(Ref.KEY_ITEM_ENERGY); @@ -106,33 +94,6 @@ default CompoundTag getEnergyTag(ItemStack stack){ return dataTag != null ? dataTag : validateEnergyTag(stack, 0, 10000); } - default boolean genericIsCorrectToolForDrops(ItemStack stack, BlockState state) { - AntimatterToolType type = this.getAntimatterToolType(); - if (type.getEffectiveMaterials().contains(state.getMaterial())) { - return true; - } - if (type.getEffectiveBlocks().contains(state.getBlock())) { - return true; - } - for (TagKey effectiveBlockTag : type.getEffectiveBlockTags()) { - if (state.is(effectiveBlockTag)){ - return true; - } - } - boolean isType = false; - for (TagKey toolType : getAntimatterToolType().getToolTypes()) { - if (state.is(toolType)){ - isType = true; - break; - } - } - return isType && ToolUtils.isCorrectTierForDrops(getItemTier(), state); - } - - default float getDefaultMiningSpeed(ItemStack stack){ - return getItemTier().getSpeed() * getAntimatterToolType().getMiningSpeedMultiplier(); - } - default CompoundTag validateEnergyTag(ItemStack stack, long startingEnergy, long maxEnergy){ IEnergyHandlerItem h = TesseractCapUtils.getEnergyHandlerItem(stack).orElse(null); if (h != null){ @@ -163,43 +124,7 @@ default void onGenericAddInformation(ItemStack stack, List tooltip, T //TODO change this to object %s system for other lang compat if (flag.isAdvanced() && getAntimatterToolType().isPowered()) tooltip.add(Utils.translatable("antimatter.tooltip.energy").append(": " + getCurrentEnergy(stack) + " / " + getMaxEnergy(stack))); - if (getAntimatterToolType().getTooltip().size() != 0) tooltip.addAll(getAntimatterToolType().getTooltip()); - tooltip.add(Utils.translatable("antimatter.tooltip.mining_level", getItemTier().getLevel()).withStyle(ChatFormatting.YELLOW)); - tooltip.add(Utils.translatable("antimatter.tooltip.tool_speed", Utils.literal("" + getDefaultMiningSpeed(stack)).withStyle(ChatFormatting.LIGHT_PURPLE))); - for (Map.Entry> e : getAntimatterToolType().getBehaviours().entrySet()) { - IBehaviour b = e.getValue(); - if (!(b instanceof IAddInformation addInformation)) continue; - addInformation.onAddInformation(this, stack, tooltip, flag); - } - } - - default boolean onGenericHitEntity(ItemStack stack, LivingEntity target, LivingEntity attacker, float volume, float pitch) { - if (getAntimatterToolType().getUseSound() != null) - target.getCommandSenderWorld().playSound(null, target.getX(), target.getY(), target.getZ(), getAntimatterToolType().getUseSound(), SoundSource.HOSTILE, volume, pitch); - Utils.damageStack(getAntimatterToolType().getAttackDurability(), stack, attacker); - if (attacker instanceof Player player) refillTool(stack, player); - return true; - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - default boolean onGenericBlockDestroyed(ItemStack stack, Level world, BlockState state, BlockPos pos, LivingEntity entity) { - if (entity instanceof Player player) { - if (getAntimatterToolType().getUseSound() != null) - player.playNotifySound(getAntimatterToolType().getUseSound(), SoundSource.BLOCKS, 0.84F, 0.75F); - boolean isToolEffective = genericIsCorrectToolForDrops(stack, state); - if (state.getDestroySpeed(world, pos) != 0.0F) { - int damage = isToolEffective ? getAntimatterToolType().getUseDurability() : getAntimatterToolType().getUseDurability() + 1; - Utils.damageStack(damage, stack, entity); - } - } - boolean returnValue = true; - for (Map.Entry> e : getAntimatterToolType().getBehaviours().entrySet()) { - IBehaviour b = e.getValue(); - if (!(b instanceof IBlockDestroyed)) continue; - returnValue = ((IBlockDestroyed) b).onBlockDestroyed(this, stack, world, state, pos, entity); - } - if (entity instanceof Player player) refillTool(stack, player); - return returnValue; + IBasicAntimatterTool.super.onGenericAddInformation(stack, tooltip, flag); } default void refillTool(ItemStack stack, Player player){ @@ -224,56 +149,6 @@ default void refillTool(ItemStack stack, Player player){ } } - default InteractionResult genericInteractLivingEntity(ItemStack stack, Player player, LivingEntity interactionTarget, InteractionHand usedHand){ - InteractionResult result = InteractionResult.PASS; - for (Map.Entry> e : getAntimatterToolType().getBehaviours().entrySet()) { - IBehaviour b = e.getValue(); - if (!(b instanceof IInteractEntity interactEntity)) continue; - InteractionResult r = interactEntity.interactLivingEntity(this, stack, player, interactionTarget, usedHand); - if (result != InteractionResult.SUCCESS) result = r; - } - return result; - } - - @SuppressWarnings({"unchecked", "rawtypes"}) - default InteractionResult onGenericItemUse(UseOnContext ctx) { - InteractionResult result = InteractionResult.PASS; - for (Map.Entry> e : getAntimatterToolType().getBehaviours().entrySet()) { - IBehaviour b = e.getValue(); - if (!(b instanceof IItemUse itemUse)) continue; - InteractionResult r = itemUse.onItemUse(this, ctx); - if (result != InteractionResult.SUCCESS) result = r; - } - return result; - } - - @SuppressWarnings({"rawtypes", "unchecked"}) - default InteractionResultHolder onGenericRightclick(Level level, Player player, InteractionHand usedHand){ - for (Map.Entry> e : getAntimatterToolType().getBehaviours().entrySet()) { - IBehaviour b = e.getValue(); - if (!(b instanceof IItemRightClick rightClick)) continue; - InteractionResultHolder r = rightClick.onRightClick(this, level, player, usedHand); - if (r.getResult().shouldAwardStats()) return r; - } - return InteractionResultHolder.pass(player.getItemInHand(usedHand)); - } - - @SuppressWarnings("rawtypes") - default InteractionResult onGenericHighlight(Player player, LevelRenderer levelRenderer, Camera camera, HitResult target, float partialTicks, PoseStack poseStack, MultiBufferSource multiBufferSource) { - InteractionResult result = InteractionResult.PASS; - for (Map.Entry> e : getAntimatterToolType().getBehaviours().entrySet()) { - IBehaviour b = e.getValue(); - if (!(b instanceof IItemHighlight)) continue; - InteractionResult type = ((IItemHighlight) b).onDrawHighlight(player, levelRenderer, camera, target, partialTicks, poseStack, multiBufferSource); - if (type != InteractionResult.SUCCESS) { - result = type; - } else { - return InteractionResult.FAIL; - } - } - return result; - } - default ItemStack getGenericContainerItem(final ItemStack oldStack) { ItemStack stack = oldStack.copy(); damage(stack, getAntimatterToolType().getCraftingDurability()); @@ -306,7 +181,10 @@ default int damage(ItemStack stack, int amount) { } default boolean hasEnoughDurability(ItemStack stack, int damage, boolean energy) { - return energy && getCurrentEnergy(stack) >= damage * 100; + Map enchants = EnchantmentHelper.getEnchantments(stack); + int energyEfficiency = enchants.getOrDefault(Data.ENERGY_EFFICIENCY, 0); + int energyUse = Math.max(1, getDefaultEnergyUse() - (int)((energyEfficiency * 0.1f) * getDefaultEnergyUse())); + return energy && getCurrentEnergy(stack) >= (long) damage * energyUse; } boolean canDisableShield(ItemStack stack, ItemStack shield, LivingEntity entity, LivingEntity attacker); diff --git a/common/src/main/java/trinsdar/gt4r/items/ItemElectricTool.java b/common/src/main/java/trinsdar/gt4r/items/ItemElectricTool.java index a716c48d..e921adc4 100644 --- a/common/src/main/java/trinsdar/gt4r/items/ItemElectricTool.java +++ b/common/src/main/java/trinsdar/gt4r/items/ItemElectricTool.java @@ -21,6 +21,8 @@ import muramasa.antimatter.tool.AntimatterToolType; import muramasa.antimatter.tool.IAbstractToolMethods; import muramasa.antimatter.tool.IAntimatterTool; +import muramasa.antimatter.tool.IBasicAntimatterTool; +import muramasa.antimatter.tool.ToolUtils; import muramasa.antimatter.util.TagUtils; import muramasa.antimatter.util.Utils; import net.minecraft.client.Camera; @@ -71,11 +73,11 @@ public class ItemElectricTool extends ItemBasic implements IEl final AntimatterToolType type; int energyTier; final Tier itemTier; - public ItemElectricTool(String id, AntimatterToolType base, float miningSpeed, Properties properties, int energyTier) { - super(GT4RRef.ID, id, properties.stacksTo(1).tab(Ref.TAB_ITEMS)); + public ItemElectricTool(String id, AntimatterToolType base, float miningSpeed, int quality, int energyTier) { + super(GT4RRef.ID, id, ToolUtils.getToolProperties(Ref.TAB_ITEMS, false).stacksTo(1)); type = base; this.energyTier = energyTier; - this.itemTier = new ElectricItemTier(miningSpeed, base.getBaseQuality(), base.getBaseAttackDamage()); + this.itemTier = new ElectricItemTier(miningSpeed, quality, base.getBaseAttackDamage()); } @Override @@ -122,6 +124,7 @@ public void appendHoverText(ItemStack stack, @Nullable Level world, List> e : getAntimatterToolType().getBehaviours().entrySet()) { + for (Map.Entry> e : getAntimatterToolType().getBehaviours().entrySet()) { IBehaviour b = e.getValue(); if (!(b instanceof IDestroySpeed destroySpeed1)) continue; float i = destroySpeed1.getDestroySpeed(this, destroySpeed, stack, state); @@ -239,7 +242,7 @@ public boolean isEnchantable(ItemStack stack) { return true; } - @Override + //@Override public boolean canApplyAtEnchantingTable(ItemStack stack, Enchantment enchantment) { if (type.getBlacklistedEnchantments().contains(enchantment)) return false; if (type.getToolTypes().contains(BlockTags.MINEABLE_WITH_AXE) && enchantment.category == EnchantmentCategory.WEAPON) {