Skip to content

Commit

Permalink
Add complete tool set
Browse files Browse the repository at this point in the history
Signed-off-by: TheSilkMiner <thesilkminer@outlook.com>
  • Loading branch information
TheSilkMiner committed May 30, 2022
1 parent fc35cf3 commit 443d10a
Show file tree
Hide file tree
Showing 13 changed files with 242 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
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.world.item.AxeItem;
import net.minecraft.world.item.Item;
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 + ".Axe")
@ZenRegister(loaders = ContentTweakerConstants.CONTENT_LOADER_ID)
public final class AxeToolItemBuilder extends ToolItemBuilder<AxeToolItemBuilder> {
private static final class TotallyNotAnAxe extends AxeItem {
TotallyNotAnAxe(final ToolData data, final Supplier<Properties> properties) {
super(data.tier(), data.baseAttackDamage(), data.attackSpeed(), properties.get());
}
}

public AxeToolItemBuilder(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) {
return ObjectHolder.of(VanillaObjectTypes.ITEM, name, () -> new TotallyNotAnAxe(toolData, builtProperties));
}

@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".formatted(name.getPath()));

cotAssets.provideTemplated(PathHelper.texture(texture), ContentTweakerVanillaConstants.itemTemplate("axe"));
cotAssets.provideFixed(PathHelper.itemModel(name), ItemModel.of(new ResourceLocation("item/handheld")).layer(0, texture), ItemModel.SERIALIZER);
cotAssets.provideOrAlter(PathHelper.usLang(), Language::of, it -> it.item(name, "Custom Axe"), Language.SERIALIZER);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
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.HoeItem;
import net.minecraft.world.item.Item;
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 + ".Hoe")
@ZenRegister(loaders = ContentTweakerConstants.CONTENT_LOADER_ID)
public final class HoeToolItemBuilder extends ToolItemBuilder<HoeToolItemBuilder> {
private static final class TotallyNotAHoe extends HoeItem {
TotallyNotAHoe(final ToolData data, final Supplier<Properties> properties) {
super(data.tier(), (int) data.baseAttackDamage(), data.attackSpeed(), properties.get());
}
}

public HoeToolItemBuilder(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 hoe item with a non-whole attack damage");
}
return ObjectHolder.of(VanillaObjectTypes.ITEM, name, () -> new TotallyNotAHoe(toolData, builtProperties));
}

@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".formatted(name.getPath()));

cotAssets.provideTemplated(PathHelper.texture(texture), ContentTweakerVanillaConstants.itemTemplate("hoe"));
cotAssets.provideFixed(PathHelper.itemModel(name), ItemModel.of(new ResourceLocation("item/handheld")).layer(0, texture), ItemModel.SERIALIZER);
cotAssets.provideOrAlter(PathHelper.usLang(), Language::of, it -> it.item(name, "Custom Hoe"), Language.SERIALIZER);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@
@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);
TotallyNotAPickaxe(final ToolData data, final Supplier<Properties> properties) {
super(data.tier(), (int) data.baseAttackDamage(), data.attackSpeed(), properties.get());
}
}

Expand All @@ -40,7 +40,7 @@ public ObjectHolder<? extends Item> createTool(final ResourceLocation name, fina
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()));
return ObjectHolder.of(VanillaObjectTypes.ITEM, name, () -> new TotallyNotAPickaxe(toolData, builtProperties));
}

@Override
Expand All @@ -52,8 +52,4 @@ public void provideResources(final ResourceLocation name, final ResourceManager
cotAssets.provideFixed(PathHelper.itemModel(name), ItemModel.of(new ResourceLocation("item/handheld")).layer(0, 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);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
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.world.item.AxeItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ShovelItem;
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 + ".Shovel")
@ZenRegister(loaders = ContentTweakerConstants.CONTENT_LOADER_ID)
public final class ShovelToolItemBuilder extends ToolItemBuilder<ShovelToolItemBuilder> {
private static final class TotallyNotAShovel extends ShovelItem {
TotallyNotAShovel(final ToolData data, final Supplier<Properties> properties) {
super(data.tier(), data.baseAttackDamage(), data.attackSpeed(), properties.get());
}
}

public ShovelToolItemBuilder(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) {
return ObjectHolder.of(VanillaObjectTypes.ITEM, name, () -> new TotallyNotAShovel(toolData, builtProperties));
}

@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".formatted(name.getPath()));

cotAssets.provideTemplated(PathHelper.texture(texture), ContentTweakerVanillaConstants.itemTemplate("shovel"));
cotAssets.provideFixed(PathHelper.itemModel(name), ItemModel.of(new ResourceLocation("item/handheld")).layer(0, texture), ItemModel.SERIALIZER);
cotAssets.provideOrAlter(PathHelper.usLang(), Language::of, it -> it.item(name, "Custom Shovel"), Language.SERIALIZER);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
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.world.item.Item;
import net.minecraft.world.item.SwordItem;
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 + ".Sword")
@ZenRegister(loaders = ContentTweakerConstants.CONTENT_LOADER_ID)
public final class SwordItemBuilder extends ItemBuilder<SwordItemBuilder> {
private Integer attackDamageBase;
private Float attackDamageSpeed;
private Tier tier;

public SwordItemBuilder(final BiFunction<ObjectHolder<? extends Item>, Consumer<ResourceManager>, ItemReference> registrationManager) {
super(registrationManager);
this.attackDamageBase = null;
this.attackDamageSpeed = null;
this.tier = null;
}

@ZenCodeType.Method("baseAttackDamage")
public SwordItemBuilder baseAttackDamage(final int attackDamageBase) {
this.attackDamageBase = attackDamageBase;
return this;
}

@ZenCodeType.Method("attackSpeed")
public SwordItemBuilder attackSpeed(final float attackSpeed) {
this.attackDamageSpeed = attackSpeed;
return this;
}

@ZenCodeType.Method("tier")
public SwordItemBuilder tier(final Tier tier) {
this.tier = Objects.requireNonNull(tier);
return this;
}

@Override
public ObjectHolder<? extends Item> create(final ResourceLocation name, final Supplier<Item.Properties> builtProperties) {
if (this.tier == null) {
throw new IllegalStateException("Unable to create a sword item without a tier");
}
if (this.attackDamageBase == null) {
throw new IllegalStateException("Unable to create a sword without a base attack damage");
}
if (this.attackDamageSpeed == null) {
throw new IllegalStateException("Unable to create a sword item without attack speed");
}
return ObjectHolder.of(VanillaObjectTypes.ITEM, name, () -> new SwordItem(this.tier, this.attackDamageBase, this.attackDamageSpeed, 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".formatted(name.getPath()));

cotAssets.provideTemplated(PathHelper.texture(texture), ContentTweakerVanillaConstants.itemTemplate("katana"));
cotAssets.provideFixed(PathHelper.itemModel(name), ItemModel.of(new ResourceLocation("item/handheld")).layer(0, texture), ItemModel.SERIALIZER);
cotAssets.provideOrAlter(PathHelper.usLang(), Language::of, it -> it.item(name, "Custom Sword"), Language.SERIALIZER);
}
}
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 443d10a

Please sign in to comment.