Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add material armors #2656

Open
wants to merge 7 commits into
base: 1.20.1
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
5 changes: 4 additions & 1 deletion src/generated/resources/assets/gtceu/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,6 @@
"config.gtceu.option.enableCleanroom": "ɯooɹuɐǝןƆǝןqɐuǝ",
"config.gtceu.option.enableFEConverters": "sɹǝʇɹǝʌuoƆƎℲǝןqɐuǝ",
"config.gtceu.option.enableMaintenance": "ǝɔuɐuǝʇuıɐWǝןqɐuǝ",
"config.gtceu.option.enableMoreDualHatchAbility": "ʎʇıןıqⱯɥɔʇɐHןɐnᗡǝɹoWǝןqɐuǝ",
"config.gtceu.option.enableResearch": "ɥɔɹɐǝsǝᴚǝןqɐuǝ",
"config.gtceu.option.enableTieredCasings": "sbuısɐƆpǝɹǝı⟘ǝןqɐuǝ",
"config.gtceu.option.enableWorldAccelerators": "sɹoʇɐɹǝןǝɔɔⱯpןɹoMǝןqɐuǝ",
Expand Down Expand Up @@ -3648,6 +3647,10 @@
"item.gtceu.ancient_gold_coin.tooltip": "suınᴚ ʇuǝıɔuɐ uı punoℲㄥ§",
"item.gtceu.anvil_casting_mold": ")ןıʌuⱯ( pןoW buıʇsɐƆ",
"item.gtceu.anvil_casting_mold.tooltip": "sןıʌuⱯ buıdɐɥs ɹoɟ pןoWㄥ§",
"item.gtceu.armor.boots": "sʇooᗺ %s",
"item.gtceu.armor.chestplate": "ǝʇɐןdʇsǝɥƆ %s",
"item.gtceu.armor.helmet": "ʇǝɯןǝH %s",
"item.gtceu.armor.leggings": "sbuıbbǝꞀ %s",
"item.gtceu.ash_dust": "sǝɥsⱯ",
"item.gtceu.avanced_nanomuscle_chestplate": "ǝʇɐןdʇsǝɥƆ ǝʇınS ™ǝןɔsnWouɐN pǝɔuɐʌpⱯ",
"item.gtceu.axe_extruder_mold.tooltip": "sǝxⱯ buıʞɐɯ ɹoɟ ǝdɐɥS ɹǝpnɹʇxƎㄥ§",
Expand Down
5 changes: 4 additions & 1 deletion src/generated/resources/assets/gtceu/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -1742,7 +1742,6 @@
"config.gtceu.option.enableCleanroom": "enableCleanroom",
"config.gtceu.option.enableFEConverters": "enableFEConverters",
"config.gtceu.option.enableMaintenance": "enableMaintenance",
"config.gtceu.option.enableMoreDualHatchAbility": "enableMoreDualHatchAbility",
"config.gtceu.option.enableResearch": "enableResearch",
"config.gtceu.option.enableTieredCasings": "enableTieredCasings",
"config.gtceu.option.enableWorldAccelerators": "enableWorldAccelerators",
Expand Down Expand Up @@ -3648,6 +3647,10 @@
"item.gtceu.ancient_gold_coin.tooltip": "§7Found in ancient Ruins",
"item.gtceu.anvil_casting_mold": "Casting Mold (Anvil)",
"item.gtceu.anvil_casting_mold.tooltip": "§7Mold for shaping Anvils",
"item.gtceu.armor.boots": "%s Boots",
"item.gtceu.armor.chestplate": "%s Chestplate",
"item.gtceu.armor.helmet": "%s Helmet",
"item.gtceu.armor.leggings": "%s Leggings",
"item.gtceu.ash_dust": "Ashes",
"item.gtceu.avanced_nanomuscle_chestplate": "Advanced NanoMuscle™ Suite Chestplate",
"item.gtceu.axe_extruder_mold.tooltip": "§7Extruder Shape for making Axes",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1024,6 +1024,14 @@ public Builder toolStats(ToolProperty toolProperty) {
return this;
}

/**
* Use {@link ArmorProperty.Builder} to create an Armor Property.
*/
public Builder armorStats(ArmorProperty armorProperty) {
properties.setProperty(PropertyKey.ARMOR, armorProperty);
return this;
}

public Builder rotorStats(int power, int efficiency, float damage, int durability) {
properties.setProperty(PropertyKey.ROTOR, new RotorProperty(power, efficiency, damage, durability));
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,223 @@
package com.gregtechceu.gtceu.api.data.chemical.material.properties;

import com.gregtechceu.gtceu.api.data.chemical.ChemicalHelper;
import com.gregtechceu.gtceu.api.data.chemical.material.Material;
import com.gregtechceu.gtceu.api.data.tag.TagPrefix;
import com.gregtechceu.gtceu.utils.SupplierMemoizer;

import net.minecraft.Util;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.crafting.Ingredient;

import com.google.common.base.Preconditions;
import lombok.Getter;
import lombok.Setter;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;
import org.jetbrains.annotations.Range;

import java.util.EnumMap;
import java.util.Map;
import java.util.function.Supplier;

// TODO document
public class ArmorProperty implements IMaterialProperty {

@Setter
@Range(from = 0, to = Integer.MAX_VALUE)
private int durabilityMultiplier;
@Setter
private Map<ArmorItem.Type, Integer> protectionValues;
@Setter
private int enchantability;
private Supplier<SoundEvent> sound;
@Setter
private float toughness;
@Setter
private float knockbackResistance;

@Nullable
@Setter
private Supplier<@NotNull Ingredient> repairIngredient;
private boolean noRepair;

@Setter
private String name = "gtceu:metal";
@Getter
@Setter
private CustomTextureGetter customTextureGetter = (stack, entity, slot, overlay) -> null;

@Getter
@Setter
private boolean dyeable;

@Getter
private final ArmorMaterial armorMaterial;
private Material material;

public ArmorProperty(int durabilityMultiplier, int[] protectionValues) {
this.durabilityMultiplier = durabilityMultiplier;
this.protectionValues = Util.make(new EnumMap<>(ArmorItem.Type.class), map -> {
for (int i = 0; i < ArmorItem.Type.values().length; i++) {
map.put(ArmorItem.Type.values()[i], protectionValues[i]);
}
});
this.sound = SupplierMemoizer.memoize(() -> SoundEvents.ARMOR_EQUIP_IRON);
this.toughness = 0;
this.knockbackResistance = 0;
this.armorMaterial = new ArmorMaterial();
}

public void setSound(Supplier<SoundEvent> sound) {
this.sound = SupplierMemoizer.memoize(sound);
}

@Override
public void verifyProperty(MaterialProperties properties) {
if (this.material == null) {
this.material = properties.getMaterial();
}
if (this.repairIngredient == null && !noRepair) {
this.repairIngredient = SupplierMemoizer
.memoize(() -> Ingredient.of(ChemicalHelper.getTag(TagPrefix.plate, material)));
}
}

public static class Builder {

private final ArmorProperty armorProperty;

public static ArmorProperty.Builder of(int durabilityMultiplier, int[] protectionValues) {
Preconditions.checkArgument(protectionValues != null && protectionValues.length == 4,
"protectionValues must have 4 entries!");
return new ArmorProperty.Builder(durabilityMultiplier, protectionValues);
}

private Builder(int durabilityMultiplier, int[] protectionValues) {
armorProperty = new ArmorProperty(durabilityMultiplier, protectionValues);
}

public ArmorProperty.Builder unbreakable() {
armorProperty.durabilityMultiplier = 0;
return this;
}

public ArmorProperty.Builder enchantability(int enchantability) {
armorProperty.enchantability = enchantability;
return this;
}

public ArmorProperty.Builder protectionValue(ArmorItem.Type type, int value) {
armorProperty.protectionValues.put(type, value);
return this;
}

public ArmorProperty.Builder protectionValues(Map<ArmorItem.Type, Integer> protectionValues) {
armorProperty.protectionValues = protectionValues;
return this;
}

public ArmorProperty.Builder repairIngredient(@Nullable Supplier<@NotNull Ingredient> repairIngredient) {
if (repairIngredient == null) {
armorProperty.repairIngredient = null;
armorProperty.noRepair = true;
} else {
armorProperty.repairIngredient = SupplierMemoizer.memoize(repairIngredient);
}
return this;
}

public ArmorProperty.Builder toughness(float toughness) {
armorProperty.toughness = toughness;
return this;
}

public ArmorProperty.Builder knockbackResistance(float knockbackResistance) {
armorProperty.knockbackResistance = knockbackResistance;
return this;
}

public ArmorProperty.Builder dyeable(boolean dyeable) {
armorProperty.dyeable = dyeable;
return this;
}

public ArmorProperty.Builder customTexture(ArmorProperty.@NotNull CustomTextureGetter textureGetter) {
armorProperty.customTextureGetter = textureGetter;
return this;
}

public ArmorProperty build() {
return armorProperty;
}
}

@FunctionalInterface
public interface CustomTextureGetter {

ResourceLocation getCustomTexture(ItemStack stack, Entity entity, EquipmentSlot slot, boolean overlay);
}

public class ArmorMaterial implements net.minecraft.world.item.ArmorMaterial {

private static final EnumMap<ArmorItem.Type, Integer> HEALTH_FUNCTION_FOR_TYPE = Util
.make(new EnumMap<>(ArmorItem.Type.class), (map) -> {
map.put(ArmorItem.Type.BOOTS, 13);
map.put(ArmorItem.Type.LEGGINGS, 15);
map.put(ArmorItem.Type.CHESTPLATE, 16);
map.put(ArmorItem.Type.HELMET, 11);
});

@Override
public int getDurabilityForType(ArmorItem.@NotNull Type type) {
return HEALTH_FUNCTION_FOR_TYPE.get(type) * ArmorProperty.this.durabilityMultiplier;
}

@Override
public int getDefenseForType(ArmorItem.@NotNull Type type) {
return ArmorProperty.this.protectionValues.get(type);
}

@Override
public int getEnchantmentValue() {
return ArmorProperty.this.enchantability;
}

@Override
public @NotNull SoundEvent getEquipSound() {
return ArmorProperty.this.sound.get();
}

@Override
public @NotNull Ingredient getRepairIngredient() {
return ArmorProperty.this.repairIngredient != null ?
ArmorProperty.this.repairIngredient.get() :
Ingredient.EMPTY;
}

@Override
public @NotNull String getName() {
return ArmorProperty.this.name;
}

@Override
public float getToughness() {
return ArmorProperty.this.toughness;
}

@Override
public float getKnockbackResistance() {
return ArmorProperty.this.knockbackResistance;
}

public ArmorProperty getArmorProperty() {
return ArmorProperty.this;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@

import com.lowdragmc.lowdraglib.Platform;

import lombok.Getter;
import lombok.Setter;

import java.util.*;

public class MaterialProperties {
Expand All @@ -19,6 +22,8 @@ public static void addBaseType(PropertyKey<?> baseTypeKey) {
}

private final Map<PropertyKey<? extends IMaterialProperty>, IMaterialProperty> propertyMap;
@Getter
@Setter
private Material material;

public MaterialProperties() {
Expand All @@ -39,6 +44,8 @@ public <T extends IMaterialProperty> boolean hasProperty(PropertyKey<T> key) {

public <T extends IMaterialProperty> void setProperty(PropertyKey<T> key, IMaterialProperty value) {
if (value == null) throw new IllegalArgumentException("Material Property must not be null!");
if (!key.getType().isInstance(value))
throw new IllegalArgumentException("Material Property must be of the same type as the property key!");
if (hasProperty(key))
throw new IllegalArgumentException("Material Property " + key.toString() + " already registered!");
propertyMap.put(key, value);
Expand Down Expand Up @@ -83,14 +90,6 @@ public void verify() {
}
}

public void setMaterial(Material material) {
this.material = material;
}

public Material getMaterial() {
return material;
}

@Override
public String toString() {
StringBuilder sb = new StringBuilder();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.gregtechceu.gtceu.api.data.chemical.material.properties;

import lombok.Getter;

public class PropertyKey<T extends IMaterialProperty> {

public static final PropertyKey<BlastProperty> BLAST = new PropertyKey<>("blast", BlastProperty.class);
Expand All @@ -16,6 +18,7 @@ public class PropertyKey<T extends IMaterialProperty> {
ItemPipeProperties.class);
public static final PropertyKey<OreProperty> ORE = new PropertyKey<>("ore", OreProperty.class);
public static final PropertyKey<ToolProperty> TOOL = new PropertyKey<>("tool", ToolProperty.class);
public static final PropertyKey<ArmorProperty> ARMOR = new PropertyKey<>("armor", ArmorProperty.class);
public static final PropertyKey<RotorProperty> ROTOR = new PropertyKey<>("rotor", RotorProperty.class);
public static final PropertyKey<WireProperties> WIRE = new PropertyKey<>("wire", WireProperties.class);
public static final PropertyKey<WoodProperty> WOOD = new PropertyKey<>("wood", WoodProperty.class);
Expand All @@ -25,18 +28,16 @@ public class PropertyKey<T extends IMaterialProperty> {
// Empty property used to allow property-less Materials without removing base type enforcement
public static final PropertyKey<EmptyProperty> EMPTY = new PropertyKey<>("empty", EmptyProperty.class);

@Getter
private final String key;
@Getter
private final Class<T> type;

public PropertyKey(String key, Class<T> type) {
this.key = key;
this.type = type;
}

protected String getKey() {
return key;
}

protected T constructDefault() {
try {
return type.newInstance();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.item.Tiers;
Expand Down Expand Up @@ -179,6 +180,16 @@ public static ItemStack get(GTToolType toolType, Material material) {
return ItemStack.EMPTY;
}

public static ItemStack getArmor(ArmorItem.Type armorType, Material material) {
if (material.hasProperty(PropertyKey.ARMOR)) {
var entry = GTMaterialItems.ARMOR_ITEMS.get(material, armorType);
if (entry != null) {
return entry.get().getDefaultInstance();
}
}
return ItemStack.EMPTY;
}

public static boolean is(ItemStack stack, GTToolType toolType) {
return getToolTypes(stack).contains(toolType);
}
Expand Down
Loading
Loading