Skip to content

Commit

Permalink
Added 'DisableVanillaTools' config
Browse files Browse the repository at this point in the history
  • Loading branch information
kill05 committed Jun 11, 2024
1 parent 45c34d9 commit 33bdb6c
Show file tree
Hide file tree
Showing 6 changed files with 140 additions and 32 deletions.
5 changes: 0 additions & 5 deletions src/main/java/com/github/kill05/MixinConfigPlugin.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.github.kill05;

import com.github.kill05.config.ArchitectConfig;
import org.objectweb.asm.tree.ClassNode;
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
Expand All @@ -22,10 +21,6 @@ public String getRefMapperConfig() {

@Override
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
if (mixinClassName.equals("com.github.kill05.mixins.disablevanilla.ItemToolMixin")) {
return ArchitectConfig.getDisableVanillaTools();
}

return true;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,16 +1,16 @@
package com.github.kill05.mixins.disablevanilla;

import com.github.kill05.config.ArchitectConfig;
import com.github.kill05.utils.ItemUtils;
import net.minecraft.core.block.Block;
import net.minecraft.core.data.tag.Tag;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.item.Item;
import net.minecraft.core.item.ItemStack;
import net.minecraft.core.item.material.ToolMaterial;
import net.minecraft.core.item.tool.ItemTool;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import sunsetsatellite.catalyst.core.util.ICustomDescription;

@Mixin(
Expand All @@ -23,41 +23,45 @@ public ItemToolMixin(int id) {
super(id);
}

@SuppressWarnings("rawtypes")
@Inject(
method = "<init>",
at = @At(value = "TAIL")
)
private void getStrVsBlockInject(String name, int id, int damageDealt, ToolMaterial toolMaterial, Tag tagEffectiveAgainst, CallbackInfo ci) {
setMaxDamage(1);
}

@Override
public String getDescription(ItemStack itemStack) {
return """
§eVanilla tools are disabled by Architect's Tools.
§eIf you wish to enable vanilla tools,
§eplease open 'architectstools.cfg',
§ethen set 'DisableVanillaTools' to 'false'.""";
return ItemUtils.getDisabledDescription();
}

@Override
public String getTranslatedName(ItemStack itemstack) {
return super.getTranslatedName(itemstack) + " §e(DISABLED)§r";
return ItemUtils.getDisabledName(super.getTranslatedName(itemstack));
}

@Override
public int getDamageVsEntity(Entity entity) {
return super.getDamageVsEntity(entity);
@Inject(
method = "getDamageVsEntity",
at = @At(value = "HEAD"),
cancellable = true
)
public void getDamageVsEntityInject(Entity entity, CallbackInfoReturnable<Integer> cir) {
if(ArchitectConfig.getDisableVanillaTools()) cir.setReturnValue(1);
}

@Override
public float getStrVsBlock(ItemStack itemstack, Block block) {
return super.getStrVsBlock(itemstack, block);
@Inject(
method = "isSilkTouch",
at = @At(value = "HEAD"),
cancellable = true
)
public void isSilkTouchInject(CallbackInfoReturnable<Boolean> cir) {
if(ArchitectConfig.getDisableVanillaTools()) cir.setReturnValue(false);
}

@Inject(
method = "getStrVsBlock",
at = @At(value = "HEAD"),
cancellable = true
)
public void getStrVsBlockInject(ItemStack itemstack, Block block, CallbackInfoReturnable<Float> cir) {
if(ArchitectConfig.getDisableVanillaTools()) cir.setReturnValue(1.0f);
}

@Override
public boolean canHarvestBlock(Block block) {
return super.canHarvestBlock(block);
public int getMaxDamage() {
return ArchitectConfig.getDisableVanillaTools() ? 1 : super.getMaxDamage();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package com.github.kill05.mixins.disablevanilla;

import com.github.kill05.config.ArchitectConfig;
import net.minecraft.core.block.Block;
import net.minecraft.core.item.tool.ItemToolPickaxe;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(
value = ItemToolPickaxe.class,
remap = false
)
public abstract class ItemToolPickaxeMixin {

@Inject(
method = "canHarvestBlock",
at = @At(value = "HEAD"),
cancellable = true
)
public void canHarvestBlockInject(Block block, CallbackInfoReturnable<Boolean> cir) {
if(ArchitectConfig.getDisableVanillaTools()) cir.setReturnValue(false);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
package com.github.kill05.mixins.disablevanilla;

import com.github.kill05.config.ArchitectConfig;
import com.github.kill05.utils.ItemUtils;
import net.minecraft.core.block.Block;
import net.minecraft.core.entity.Entity;
import net.minecraft.core.item.Item;
import net.minecraft.core.item.ItemStack;
import net.minecraft.core.item.tool.ItemToolSword;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import sunsetsatellite.catalyst.core.util.ICustomDescription;

@Mixin(
value = ItemToolSword.class,
remap = false
)
public abstract class ItemToolSwordMixin extends Item implements ICustomDescription {

public ItemToolSwordMixin(int id) {
super(id);
}

@Inject(
method = "getStrVsBlock",
at = @At(value = "HEAD"),
cancellable = true
)
public void getStrVsBlockInject(ItemStack itemstack, Block block, CallbackInfoReturnable<Float> cir) {
if(ArchitectConfig.getDisableVanillaTools()) cir.setReturnValue(1.0f);
}

@Inject(
method = "isSilkTouch",
at = @At(value = "HEAD"),
cancellable = true
)
public void isSilkTouchInject(CallbackInfoReturnable<Boolean> cir) {
if(ArchitectConfig.getDisableVanillaTools()) cir.setReturnValue(false);
}

@Inject(
method = "getDamageVsEntity",
at = @At(value = "HEAD"),
cancellable = true
)
public void getDamageVsEntityInject(Entity entity, CallbackInfoReturnable<Integer> cir) {
if(ArchitectConfig.getDisableVanillaTools()) cir.setReturnValue(1);
}


@Override
public int getMaxDamage() {
return ArchitectConfig.getDisableVanillaTools() ? 1 : super.getMaxDamage();
}

@Override
public String getDescription(ItemStack itemStack) {
return ItemUtils.getDisabledDescription();
}

@Override
public String getTranslatedName(ItemStack itemstack) {
return ItemUtils.getDisabledName(super.getTranslatedName(itemstack));
}
}
14 changes: 14 additions & 0 deletions src/main/java/com/github/kill05/utils/ItemUtils.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.kill05.utils;

import com.github.kill05.ArchitectTools;
import com.github.kill05.config.ArchitectConfig;
import com.github.kill05.items.ArchitectItem;
import com.github.kill05.items.part.PartType;
import com.github.kill05.items.tool.ArchitectTool;
Expand Down Expand Up @@ -37,4 +38,17 @@ public static boolean compare(@Nullable ItemStack stack, @NotNull Item item) {
}


public static String getDisabledName(String originalName) {
return ArchitectConfig.getDisableVanillaTools() ? originalName + " §e(DISABLED)§r" : originalName;
}

public static String getDisabledDescription() {
if(!ArchitectConfig.getDisableVanillaTools()) return "";
return """
§eVanilla tools are disabled by Architect's Tools.
§eIf you wish to enable vanilla tools,
§eplease open 'architectstools.cfg',
§ethen set 'DisableVanillaTools' to 'false'.""";
}

}
4 changes: 3 additions & 1 deletion src/main/resources/mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,9 @@
"mixins": [
"ItemStackMixin",
"StringTagMixin",
"disablevanilla.ItemToolMixin"
"disablevanilla.ItemToolSwordMixin",
"disablevanilla.ItemToolMixin",
"disablevanilla.ItemToolPickaxeMixin"
],
"client": [
],
Expand Down

0 comments on commit 33bdb6c

Please sign in to comment.