-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[WIP/Not Working] Add framework to add custom tools
Signed-off-by: TheSilkMiner <thesilkminer@outlook.com>
- Loading branch information
1 parent
e4781d5
commit 889cc1b
Showing
2 changed files
with
133 additions
and
0 deletions.
There are no files selected for viewing
60 changes: 60 additions & 0 deletions
60
...va/com/blamejared/contenttweaker/vanilla/api/zen/builder/item/PickaxeToolItemBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package com.blamejared.contenttweaker.vanilla.api.zen.builder.item; | ||
|
||
import com.blamejared.contenttweaker.core.api.ContentTweakerConstants; | ||
import com.blamejared.contenttweaker.core.api.object.ObjectHolder; | ||
import com.blamejared.contenttweaker.core.api.resource.ResourceFragment; | ||
import com.blamejared.contenttweaker.core.api.resource.ResourceManager; | ||
import com.blamejared.contenttweaker.core.api.resource.StandardResourceFragmentKeys; | ||
import com.blamejared.contenttweaker.vanilla.api.resource.ItemModel; | ||
import com.blamejared.contenttweaker.vanilla.api.resource.Language; | ||
import com.blamejared.contenttweaker.vanilla.api.resource.PathHelper; | ||
import com.blamejared.contenttweaker.vanilla.api.zen.ContentTweakerVanillaConstants; | ||
import com.blamejared.contenttweaker.vanilla.api.zen.object.ItemReference; | ||
import com.blamejared.contenttweaker.vanilla.object.VanillaObjectTypes; | ||
import com.blamejared.crafttweaker.api.annotation.ZenRegister; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.util.Mth; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.PickaxeItem; | ||
import org.openzen.zencode.java.ZenCodeType; | ||
|
||
import java.util.function.BiFunction; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
@ZenCodeType.Name(ContentTweakerVanillaConstants.ITEM_BUILDER_PACKAGE + ".Pickaxe") | ||
@ZenRegister(loaders = ContentTweakerConstants.CONTENT_LOADER_ID) | ||
public final class PickaxeToolItemBuilder extends ToolItemBuilder<PickaxeToolItemBuilder> { | ||
private static final class TotallyNotAPickaxe extends PickaxeItem { | ||
TotallyNotAPickaxe(final ToolData data, final Properties properties) { | ||
super(data.tier(), (int) data.baseAttackDamage(), data.attackSpeed(), properties); | ||
} | ||
} | ||
|
||
public PickaxeToolItemBuilder(final BiFunction<ObjectHolder<? extends Item>, Consumer<ResourceManager>, ItemReference> registrationManager) { | ||
super(registrationManager); | ||
} | ||
|
||
@Override | ||
public ObjectHolder<? extends Item> createTool(final ResourceLocation name, final ToolData toolData, final Supplier<Item.Properties> builtProperties) { | ||
if (Mth.floor(toolData.baseAttackDamage()) != toolData.baseAttackDamage()) { | ||
throw new IllegalStateException("Unable to create a pickaxe item with a non-whole attack damage"); | ||
} | ||
return ObjectHolder.of(VanillaObjectTypes.ITEM, name, () -> this.build(toolData, builtProperties.get())); | ||
} | ||
|
||
@Override | ||
public void provideResources(final ResourceLocation name, final ResourceManager manager) { | ||
final ResourceFragment cotAssets = manager.fragment(StandardResourceFragmentKeys.CONTENT_TWEAKER_ASSETS); | ||
final ResourceLocation texture = new ResourceLocation(name.getNamespace(), "item/%s_overlay".formatted(name.getPath())); | ||
final ResourceLocation base = new ResourceLocation("item/iron_pickaxe"); | ||
|
||
cotAssets.provideTemplated(PathHelper.texture(texture), "missing_pickaxe_overlay.png"); | ||
cotAssets.provideFixed(PathHelper.itemModel(name), ItemModel.ofGenerated().layer(0, base).layer(1, texture), ItemModel.SERIALIZER); | ||
cotAssets.provideOrAlter(PathHelper.usLang(), Language::of, it -> it.item(name, "Custom Pickaxe"), Language.SERIALIZER); | ||
} | ||
|
||
private PickaxeItem build(final ToolData data, final Item.Properties builtProperties) { | ||
return new TotallyNotAPickaxe(data, builtProperties); | ||
} | ||
} |
73 changes: 73 additions & 0 deletions
73
...main/java/com/blamejared/contenttweaker/vanilla/api/zen/builder/item/ToolItemBuilder.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.blamejared.contenttweaker.vanilla.api.zen.builder.item; | ||
|
||
import com.blamejared.contenttweaker.core.api.ContentTweakerConstants; | ||
import com.blamejared.contenttweaker.core.api.object.ObjectHolder; | ||
import com.blamejared.contenttweaker.core.api.resource.ResourceManager; | ||
import com.blamejared.contenttweaker.vanilla.api.zen.ContentTweakerVanillaConstants; | ||
import com.blamejared.contenttweaker.vanilla.api.zen.object.ItemReference; | ||
import com.blamejared.crafttweaker.api.annotation.ZenRegister; | ||
import com.blamejared.crafttweaker.api.util.GenericUtil; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.Tier; | ||
import org.openzen.zencode.java.ZenCodeType; | ||
|
||
import java.util.Objects; | ||
import java.util.function.BiFunction; | ||
import java.util.function.Consumer; | ||
import java.util.function.Supplier; | ||
|
||
@ZenCodeType.Name(ContentTweakerVanillaConstants.ITEM_BUILDER_PACKAGE + ".ToolBuilder") | ||
@ZenRegister(loaders = ContentTweakerConstants.CONTENT_LOADER_ID) | ||
public abstract class ToolItemBuilder<T extends ToolItemBuilder<T>> extends ItemBuilder<T> { | ||
protected record ToolData(Tier tier, float baseAttackDamage, float attackSpeed) {} | ||
|
||
private Float attackDamageBase; | ||
private Float attackDamageSpeed; | ||
private Tier tier; | ||
|
||
protected ToolItemBuilder(final BiFunction<ObjectHolder<? extends Item>, Consumer<ResourceManager>, ItemReference> registrationManager) { | ||
super(registrationManager); | ||
this.attackDamageBase = null; | ||
this.attackDamageSpeed = null; | ||
this.tier = null; | ||
} | ||
|
||
@ZenCodeType.Method("baseAttackDamage") | ||
public T baseAttackDamage(final float attackDamageBase) { | ||
this.attackDamageBase = attackDamageBase; | ||
return this.self(); | ||
} | ||
|
||
@ZenCodeType.Method("attackSpeed") | ||
public T attackSpeed(final float attackSpeed) { | ||
this.attackDamageSpeed = attackSpeed; | ||
return this.self(); | ||
} | ||
|
||
@ZenCodeType.Method("tier") | ||
public T tier(final Tier tier) { | ||
this.tier = Objects.requireNonNull(tier); | ||
return this.self(); | ||
} | ||
|
||
@Override | ||
public final ObjectHolder<? extends Item> create(final ResourceLocation name, final Supplier<Item.Properties> builtProperties) { | ||
if (this.tier == null) { | ||
throw new IllegalStateException("Unable to create a tool item without a tier"); | ||
} | ||
if (this.attackDamageBase == null) { | ||
throw new IllegalStateException("Unable to create a tool without a base attack damage"); | ||
} | ||
if (this.attackDamageSpeed == null) { | ||
throw new IllegalStateException("Unable to create a tool item without attack speed"); | ||
} | ||
return this.createTool(name, new ToolData(this.tier, this.attackDamageBase, this.attackDamageSpeed), builtProperties); | ||
} | ||
|
||
public abstract ObjectHolder<? extends Item> createTool(final ResourceLocation name, final ToolData toolData, final Supplier<Item.Properties> builtProperties); | ||
|
||
private T self() { | ||
return GenericUtil.uncheck(this); | ||
} | ||
} |