Skip to content

Commit

Permalink
got drill working it seems
Browse files Browse the repository at this point in the history
  • Loading branch information
Trinsdar committed Mar 4, 2024
1 parent d55f602 commit 79a0b98
Show file tree
Hide file tree
Showing 14 changed files with 66 additions and 13 deletions.
2 changes: 1 addition & 1 deletion common/src/main/java/trinsdar/gt4r/data/GT4RData.java
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ 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 ItemElectricTool DRILL = new ItemElectricTool("drill", GTCoreTools.DRILL, 6.0f, 6.5f, 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
8 changes: 3 additions & 5 deletions common/src/main/java/trinsdar/gt4r/items/IElectricTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -105,13 +105,13 @@ default CompoundTag validateEnergyTag(ItemStack stack, long startingEnergy, long
}

default void onGenericFillItemGroup(CreativeModeTab group, NonNullList<ItemStack> list, long maxEnergy) {
if (group != Ref.TAB_TOOLS) return;
if (group != Ref.TAB_ITEMS) return;
if (getAntimatterToolType().isPowered()) {
ItemStack stack = new ItemStack(this.getItem());
IEnergyHandlerItem h = TesseractCapUtils.getEnergyHandlerItem(stack).orElse(null);
if (h != null){
list.add(stack.copy());
h.setCapacity(maxEnergy);
list.add(stack.copy());
h.setEnergy(maxEnergy);
stack.setTag(h.getContainer().getTag());
list.add(stack);
Expand Down Expand Up @@ -174,10 +174,8 @@ default int damage(ItemStack stack, int amount) {
h.extractEu(multipliedDamage, false);
stack.setTag(h.getContainer().getTag());
//tag.putLong(Ref.KEY_TOOL_DATA_ENERGY, currentEnergy - multipliedDamage); // Otherwise take energy off of tool if energy is larger than multiplied damage
return 0; // Nothing is taken away from main durability
} else { // Lastly, set energy to 0 and take leftovers off of tool durability itself
return 0;
}
return 0;
}

default boolean hasEnoughDurability(ItemStack stack, int damage, boolean energy) {
Expand Down
69 changes: 62 additions & 7 deletions common/src/main/java/trinsdar/gt4r/items/ItemElectricTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import com.mojang.blaze3d.vertex.PoseStack;
import it.unimi.dsi.fastutil.ints.Int2ObjectMap;
import it.unimi.dsi.fastutil.ints.Int2ObjectOpenHashMap;
import it.unimi.dsi.fastutil.objects.Object2ObjectMap;
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import muramasa.antimatter.Ref;
import muramasa.antimatter.behaviour.IBehaviour;
import muramasa.antimatter.behaviour.IDestroySpeed;
Expand Down Expand Up @@ -54,6 +56,7 @@
import net.minecraft.world.item.enchantment.Enchantments;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelReader;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.HitResult;
import org.jetbrains.annotations.NotNull;
Expand All @@ -69,15 +72,17 @@
import java.util.Optional;
import java.util.function.Consumer;

import static trinsdar.gt4r.data.Materials.Steel;

public class ItemElectricTool extends ItemBasic<ItemElectricTool> implements IElectricTool {
final AntimatterToolType type;
int energyTier;
final Tier itemTier;
public ItemElectricTool(String id, AntimatterToolType base, float miningSpeed, int quality, int energyTier) {
super(GT4RRef.ID, id, ToolUtils.getToolProperties(Ref.TAB_ITEMS, false).stacksTo(1));
public ItemElectricTool(String id, AntimatterToolType base, float miningSpeed, float attackDamage, int quality, int energyTier) {
super(GT4RRef.ID, id, ToolUtils.getToolProperties(Ref.TAB_ITEMS, false).durability(1));
type = base;
this.energyTier = energyTier;
this.itemTier = new ElectricItemTier(miningSpeed, quality, base.getBaseAttackDamage());
this.itemTier = new ElectricItemTier(miningSpeed, quality, attackDamage);
}

@Override
Expand All @@ -95,9 +100,18 @@ public int getEnergyTier() {
return energyTier;
}

@Override
public Object2ObjectMap<String, IBehaviour<IBasicAntimatterTool>> getBehaviours(){
return getAntimatterToolType().getBehaviours();
}

public float getDefaultMiningSpeed(ItemStack stack) {
return IElectricTool.super.getDefaultMiningSpeed(stack) * (float)(3 * this.energyTier);
}

@Override
public void fillItemCategory(CreativeModeTab group, NonNullList<ItemStack> list) {
onGenericFillItemGroup(group, list, 100000);
onGenericFillItemGroup(group, list, 100000L * this.energyTier);
}

public boolean doesSneakBypassUse(ItemStack stack, LevelReader world, BlockPos pos, Player player) {
Expand Down Expand Up @@ -146,7 +160,7 @@ public float getDestroySpeed(ItemStack stack, BlockState state) {
if (type.isPowered() && !hasEnoughDurability(stack, 1, true)){
destroySpeed = 0.0f;
}
for (Map.Entry<String, IBehaviour<IBasicAntimatterTool>> e : getAntimatterToolType().getBehaviours().entrySet()) {
for (Map.Entry<String, IBehaviour<IBasicAntimatterTool>> e : getBehaviours().entrySet()) {
IBehaviour<?> b = e.getValue();
if (!(b instanceof IDestroySpeed destroySpeed1)) continue;
float i = destroySpeed1.getDestroySpeed(this, destroySpeed, stack, state);
Expand All @@ -170,7 +184,7 @@ public boolean mineBlock(ItemStack stack, Level level, BlockState state, BlockPo
public Multimap<Attribute, AttributeModifier> getDefaultAttributeModifiers(EquipmentSlot slot) {
Multimap<Attribute, AttributeModifier> modifiers = HashMultimap.create();
if (slot == EquipmentSlot.MAINHAND) {
modifiers.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Tool modifier", type.getBaseAttackDamage(), AttributeModifier.Operation.ADDITION));
modifiers.put(Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Tool modifier", itemTier.getAttackDamageBonus(), AttributeModifier.Operation.ADDITION));
modifiers.put(Attributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Tool modifier", type.getBaseAttackSpeed(), AttributeModifier.Operation.ADDITION));
}
return modifiers;
Expand Down Expand Up @@ -199,6 +213,21 @@ public void handleRenderHighlight(Player entity, LevelRenderer levelRenderer, Ca
onGenericHighlight(entity, levelRenderer, camera, target, partialTicks, poseStack, multiBufferSource);
}

@Override
public int getBarColor(ItemStack stack) {
return getPoweredBarColor(stack);
}

@Override
public int getBarWidth(ItemStack stack) {
return getPoweredBarWidth(stack);
}

@Override
public boolean isBarVisible(ItemStack stack) {
return isPoweredBarVisible(stack);
}

@Override
public boolean canAttackBlock(BlockState state, Level world, BlockPos pos, Player player) {
return type.getBlockBreakability();
Expand All @@ -224,7 +253,7 @@ public <T extends LivingEntity> int damageItem(ItemStack stack, int amount, T en

@Override
public int getMaxDamage(ItemStack stack) {
return 0;
return getMaxDamage();
}

//@Override
Expand Down Expand Up @@ -259,6 +288,32 @@ public ItemStack getContainerItem(ItemStack oldStack) {
return getGenericContainerItem(oldStack);
}

@Override
public int getItemColor(ItemStack stack, @Nullable Block block, int i) {
if (i == 1){
return 0xff6400;
}
if (i == 0) {
return Steel.getRGB();
}
return -1;
}

@Override
public Texture[] getTextures() {
List<Texture> textures = new ObjectArrayList<>();
int layers = getAntimatterToolType().getOverlayLayers();
textures.add(new Texture(getTextureDomain(), "item/tool/".concat(getAntimatterToolType().getId())));
if (layers == 1)
textures.add(new Texture(getTextureDomain(), "item/tool/overlay/".concat(getAntimatterToolType().getId())));
if (layers > 1) {
for (int i = 1; i <= layers; i++) {
textures.add(new Texture(getTextureDomain(), String.join("", "item/tool/overlay/", getAntimatterToolType().getId(), "_", Integer.toString(i))));
}
}
return textures.toArray(new Texture[textures.size()]);
}

public static class ElectricItemTier implements Tier {

private final float speed;
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 79a0b98

Please sign in to comment.