Skip to content

Commit

Permalink
updated antimatter, did more work on electric tools
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Mar 3, 2024
1 parent 05deb82 commit d55f602
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 136 deletions.
2 changes: 1 addition & 1 deletion AntimatterAPI
Submodule AntimatterAPI updated 22 files
+2 −0 common/src/main/java/muramasa/antimatter/capability/machine/MultiMachineEnergyHandler.java
+4 −3 common/src/main/java/muramasa/antimatter/client/event/ClientEvents.java
+3 −3 common/src/main/java/muramasa/antimatter/tool/AntimatterToolType.java
+0 −2 common/src/main/java/muramasa/antimatter/tool/IAbstractToolMethods.java
+10 −130 common/src/main/java/muramasa/antimatter/tool/IAntimatterTool.java
+192 −0 common/src/main/java/muramasa/antimatter/tool/IBasicAntimatterTool.java
+1 −1 common/src/main/java/muramasa/antimatter/tool/MaterialSword.java
+2 −34 common/src/main/java/muramasa/antimatter/tool/MaterialTool.java
+6 −5 common/src/main/java/muramasa/antimatter/tool/behaviour/BehaviourAOEBreak.java
+3 −2 common/src/main/java/muramasa/antimatter/tool/behaviour/BehaviourBlockTilling.java
+3 −2 common/src/main/java/muramasa/antimatter/tool/behaviour/BehaviourCropHarvesting.java
+2 −1 common/src/main/java/muramasa/antimatter/tool/behaviour/BehaviourExtendedHighlight.java
+3 −2 common/src/main/java/muramasa/antimatter/tool/behaviour/BehaviourLogStripping.java
+3 −2 common/src/main/java/muramasa/antimatter/tool/behaviour/BehaviourPoweredDebug.java
+3 −2 common/src/main/java/muramasa/antimatter/tool/behaviour/BehaviourPumpkinCarving.java
+3 −2 common/src/main/java/muramasa/antimatter/tool/behaviour/BehaviourShearing.java
+3 −2 common/src/main/java/muramasa/antimatter/tool/behaviour/BehaviourTorchPlacing.java
+3 −2 common/src/main/java/muramasa/antimatter/tool/behaviour/BehaviourTreeFelling.java
+3 −2 common/src/main/java/muramasa/antimatter/tool/behaviour/BehaviourVanillaShovel.java
+3 −2 common/src/main/java/muramasa/antimatter/tool/behaviour/BehaviourWaterlogToggle.java
+5 −4 common/src/main/java/muramasa/antimatter/tool/behaviour/BehaviourWrenchSwitching.java
+3 −2 common/src/main/java/muramasa/antimatter/util/Utils.java
5 changes: 5 additions & 0 deletions common/src/main/java/trinsdar/gt4r/data/GT4RData.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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");

Expand Down
136 changes: 7 additions & 129 deletions common/src/main/java/trinsdar/gt4r/items/IElectricTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand All @@ -77,14 +73,6 @@ default boolean isPoweredBarVisible(ItemStack stack) {
return getCurrentEnergy(stack) > 0;
}

default Item getItem() {
return (Item) this;
}

default Set<TagKey<Block>> getActualTags() {
return getAntimatterToolType().getToolTypes();
}


default long getCurrentEnergy(ItemStack stack) {
return getEnergyTag(stack).getLong(Ref.KEY_ITEM_ENERGY);
Expand All @@ -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<Block> effectiveBlockTag : type.getEffectiveBlockTags()) {
if (state.is(effectiveBlockTag)){
return true;
}
}
boolean isType = false;
for (TagKey<Block> 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){
Expand Down Expand Up @@ -163,43 +124,7 @@ default void onGenericAddInformation(ItemStack stack, List<Component> 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<String, IBehaviour<IAntimatterTool>> 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<String, IBehaviour<IAntimatterTool>> 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){
Expand All @@ -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<String, IBehaviour<IAntimatterTool>> 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<String, IBehaviour<IAntimatterTool>> 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<ItemStack> onGenericRightclick(Level level, Player player, InteractionHand usedHand){
for (Map.Entry<String, IBehaviour<IAntimatterTool>> e : getAntimatterToolType().getBehaviours().entrySet()) {
IBehaviour<?> b = e.getValue();
if (!(b instanceof IItemRightClick rightClick)) continue;
InteractionResultHolder<ItemStack> 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<String, IBehaviour<IAntimatterTool>> 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());
Expand Down Expand Up @@ -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<Enchantment, Integer> 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);
Expand Down
15 changes: 9 additions & 6 deletions common/src/main/java/trinsdar/gt4r/items/ItemElectricTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -71,11 +73,11 @@ public class ItemElectricTool extends ItemBasic<ItemElectricTool> 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
Expand Down Expand Up @@ -122,6 +124,7 @@ public void appendHoverText(ItemStack stack, @Nullable Level world, List<Compone
super.appendHoverText(stack, world, tooltip, flag);
}

//TODO figure out why I wrote the below todo
//TODO figure this out
//@Override
public boolean shouldCauseReequipAnimation(ItemStack oldStack, ItemStack newStack, boolean slotChanged) {
Expand All @@ -140,10 +143,10 @@ public int getUseDuration(ItemStack stack) {

public float getDestroySpeed(ItemStack stack, BlockState state) {
float destroySpeed = genericIsCorrectToolForDrops(stack, state) ? getDefaultMiningSpeed(stack) : 1.0F;
if (type.isPowered() && getCurrentEnergy(stack) == 0){
if (type.isPowered() && !hasEnoughDurability(stack, 1, true)){
destroySpeed = 0.0f;
}
for (Map.Entry<String, IBehaviour<IAntimatterTool>> e : getAntimatterToolType().getBehaviours().entrySet()) {
for (Map.Entry<String, IBehaviour<IBasicAntimatterTool>> e : getAntimatterToolType().getBehaviours().entrySet()) {
IBehaviour<?> b = e.getValue();
if (!(b instanceof IDestroySpeed destroySpeed1)) continue;
float i = destroySpeed1.getDestroySpeed(this, destroySpeed, stack, state);
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit d55f602

Please sign in to comment.