Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import blob.vanillasquared.util.data.BlockComponent;
import blob.vanillasquared.util.data.GeneralWeapon;
import blob.vanillasquared.util.data.Dura;
import blob.vanillasquared.util.api.other.vsqIdentifiers;
import net.minecraft.core.component.DataComponents;
import net.minecraft.tags.BlockTags;
Expand Down Expand Up @@ -47,17 +46,6 @@ ToolMaterial.DIAMOND, new BlockComponent(0.65F, 0.5F, 0.5F, 1.0F),
ToolMaterial.NETHERITE, new BlockComponent(0.7F, 0.55F, 0.55F, 1.0F)
);

@Unique
private static final Map<ToolMaterial, Dura> DURABILITY = Map.of(
ToolMaterial.WOOD, new Dura(75),
ToolMaterial.STONE, new Dura(150),
ToolMaterial.COPPER, new Dura(200),
ToolMaterial.IRON, new Dura(250),
ToolMaterial.GOLD, new Dura(100),
ToolMaterial.DIAMOND, new Dura(1550),
ToolMaterial.NETHERITE, new Dura(2069)
);

@Inject(at = @At("HEAD"), method = "axe", cancellable = true)
public void init(ToolMaterial toolMaterial, float f, float g, CallbackInfoReturnable<Item.Properties> cir) {
BlockComponent blockComponent = BLOCK_COMPONENT.get(toolMaterial);
Expand All @@ -66,8 +54,6 @@ public void init(ToolMaterial toolMaterial, float f, float g, CallbackInfoReturn
return;
}

Dura durability = DURABILITY.getOrDefault(toolMaterial, Dura.DEFAULT);

cir.setReturnValue(this.tool(toolMaterial, BlockTags.MINEABLE_WITH_AXE, f, g, 5.0F).component(DataComponents.BLOCKS_ATTACKS, blockComponent.build()).component(DataComponents.WEAPON, new Weapon(1, 5.0F)).attributes(generalWeapon.build()).durability(durability.dura()));
cir.setReturnValue(this.tool(toolMaterial, BlockTags.MINEABLE_WITH_AXE, f, g, 5.0F).component(DataComponents.BLOCKS_ATTACKS, blockComponent.build()).component(DataComponents.WEAPON, new Weapon(1, 5.0F)).attributes(generalWeapon.build()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
import net.minecraft.core.component.DataComponents;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ToolMaterial;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.item.component.Tool;
import net.minecraft.world.item.component.Weapon;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.Unique;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
Expand All @@ -28,10 +31,22 @@
@Mixin(ToolMaterial.class)
public abstract class ToolMaterialMixin {

@Shadow
@Final
private TagKey<Block> incorrectBlocksForDrops;

@Shadow
@Final
private float speed;

@Shadow
private Item.Properties applyCommonProperties(Item.Properties properties) {
throw new AssertionError();
}
@Shadow
private ItemAttributeModifiers createToolAttributes(float f, float g) {
throw new AssertionError();
}
@Unique
private static final Map<ToolMaterial, GeneralWeapon> SWORD = Map.of(
ToolMaterial.WOOD, new GeneralWeapon(vsqIdentifiers.vsqSwordOverride.identifier(), EquipmentSlotGroup.MAINHAND,3.0d, -2.4d, 0.0d),
Expand Down Expand Up @@ -61,8 +76,15 @@ private void applySwordProperties(Item.Properties properties, float f, float g,
return;
}

HolderGetter<Block> holderGetter = BuiltInRegistries.acquireBootstrapRegistrationLookup(BuiltInRegistries.BLOCK);
cir.setReturnValue(this.applyCommonProperties(properties).component(DataComponents.TOOL, new Tool(List.of(Tool.Rule.minesAndDrops(HolderSet.direct(Blocks.COBWEB.builtInRegistryHolder()), 15.0F), Tool.Rule.overrideSpeed(holderGetter.getOrThrow(BlockTags.SWORD_INSTANTLY_MINES), Float.MAX_VALUE), Tool.Rule.overrideSpeed(holderGetter.getOrThrow(BlockTags.SWORD_EFFICIENT), 1.5F)), 1.0F, 2, false)).attributes(swordAttributes.build()).component(DataComponents.WEAPON, new Weapon(1)));
}
@Inject(method = "applyToolProperties", at = @At("HEAD"), cancellable = true)
private void applyToolProperties (Item.Properties properties, TagKey<Block> tagKey, float f, float g, float h, CallbackInfoReturnable<Item.Properties> cir) {
ToolMaterial material = (ToolMaterial) (Object) this;
Dura durability = DURABILITY.getOrDefault(material, Dura.DEFAULT);
HolderGetter<Block> holderGetter = BuiltInRegistries.acquireBootstrapRegistrationLookup(BuiltInRegistries.BLOCK);
cir.setReturnValue(this.applyCommonProperties(properties).component(DataComponents.TOOL, new Tool(List.of(Tool.Rule.minesAndDrops(HolderSet.direct(Blocks.COBWEB.builtInRegistryHolder()), 15.0F), Tool.Rule.overrideSpeed(holderGetter.getOrThrow(BlockTags.SWORD_INSTANTLY_MINES), Float.MAX_VALUE), Tool.Rule.overrideSpeed(holderGetter.getOrThrow(BlockTags.SWORD_EFFICIENT), 1.5F)), 1.0F, 2, false)).attributes(swordAttributes.build()).component(DataComponents.WEAPON, new Weapon(1)).durability(durability.dura()));

cir.setReturnValue(this.applyCommonProperties(properties).component(DataComponents.TOOL, new Tool(List.of(Tool.Rule.deniesDrops(holderGetter.getOrThrow(this.incorrectBlocksForDrops)), Tool.Rule.minesAndDrops(holderGetter.getOrThrow(tagKey), this.speed)), 1.0F, 1, true)).attributes(this.createToolAttributes(f, g)).component(DataComponents.WEAPON, new Weapon(2, h)).durability(durability.dura()));
}
}