Skip to content

Commit

Permalink
update to 7.1
Browse files Browse the repository at this point in the history
  • Loading branch information
mizuri-n committed Apr 24, 2024
1 parent 29eb995 commit 9d18d70
Show file tree
Hide file tree
Showing 17 changed files with 213 additions and 5 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ dependencies {

modImplementation "BTA_Babric_PrismaticLibe:prismaticlibe:${project.prismatic_version}"

modImplementation "ModMenu:ModMenu:2.0.4"
modImplementation "ModMenu:ModMenu:2.0.5"

implementation "org.slf4j:slf4j-api:1.8.0-beta4"
implementation "org.apache.logging.log4j:log4j-slf4j18-impl:2.16.0"
Expand Down
6 changes: 3 additions & 3 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
org.gradle.jvmargs=-Xmx2G

# BTA
bta_version=7.1-pre2a
bta_version=7.1

# Loader
loader_version=0.14.19-babric.3-bta

# HalpLibe
halplibe_version=3.5.1
halplibe_version=3.5.2

prismatic_version=3.0.3-7.1

# Mod
mod_version=1.0.3
mod_version=1.0.4
mod_group=Mizuri-n
mod_name=Better with Defense
141 changes: 141 additions & 0 deletions src/main/java/mizurin/shieldmod/armorRecipeColor.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package mizurin.shieldmod;

import com.mojang.nbt.CompoundTag;
import net.minecraft.core.data.registry.recipe.SearchQuery;
import net.minecraft.core.data.registry.recipe.entry.RecipeEntryCraftingDynamic;
import net.minecraft.core.item.Item;
import net.minecraft.core.item.ItemDye;
import net.minecraft.core.item.ItemStack;
import net.minecraft.core.player.inventory.InventoryCrafting;
import net.minecraft.core.util.helper.Color;
import useless.prismaticlibe.IColoredArmor;
import useless.prismaticlibe.debug.ItemArmorColored;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

//Special thanks to UselessBullets for being extremely awesome https://github.com/UselessBullets/Lunacy/tree/7.1
public class armorRecipeColor extends RecipeEntryCraftingDynamic {
public static HashMap<Item, Map<Integer, Color>> dyeMap = new HashMap<>();
private static final Map<Integer, Color> vanillaDye;
static {
vanillaDye = new HashMap<>();
ItemDye.field_31002_bk[7] = 13027014;
ItemDye.field_31002_bk[15] = 16777215;
for (int color = 0; color < 16; color++) {
vanillaDye.put(color, new Color().setARGB(ItemDye.field_31002_bk[color]));
}
dyeMap.put(Item.dye, vanillaDye);
}
@Override
public ItemStack getCraftingResult(InventoryCrafting inventorycrafting) {
ItemStack armorStack = null;
List<ItemStack> dyeStacks = new ArrayList<>();
for (int x = 0; x < 3; ++x) {
for (int y = 0; y < 3; ++y) {
ItemStack stack = inventorycrafting.getItemStackAt(x, y);
if (stack == null) continue;
if (stack.getItem() instanceof IColoredArmor) {
armorStack = stack;
} else if (dyeMap.containsKey(stack.getItem())) {
dyeStacks.add(stack);
}
}
}
if (armorStack != null && !dyeStacks.isEmpty()) {
ItemStack outStack = armorStack.copy();
int r = -1;
int g = -1;
int b = -1;
int count = 0;
if (outStack.getData().containsKey("dyed_color")){
CompoundTag armorColorTag = outStack.getData().getCompound("dyed_color");
r = armorColorTag.getShort("red");
g = armorColorTag.getShort("green");
b = armorColorTag.getShort("blue");
count += 1;
}

for (ItemStack dyeStack : dyeStacks){
Color color = dyeMap.getOrDefault(dyeStack.getItem(), vanillaDye).getOrDefault(dyeStack.getMetadata(), vanillaDye.get(0));
if (r == -1 || g == -1 || b == -1){
r = (int) (color.getRed() * 0.85f);
g = (int) (color.getGreen() * 0.85f);
b = (int) (color.getBlue() * 0.85f);
} else {
r += color.getRed();
g += color.getGreen();
b += color.getBlue();
}
count += 1;
}

if (count > 0){
r /= count;
g /= count;
b /= count;
CompoundTag colorTag = new CompoundTag();
colorTag.putShort("red", (short) r);
colorTag.putShort("green", (short) g);
colorTag.putShort("blue", (short) b);
outStack.getData().putCompound("dyed_color", colorTag);
}

outStack.stackSize = 1;
return outStack;
}
return null;
}

@Override
public int getRecipeSize() {
return 9;
}

@Override
public boolean matches(InventoryCrafting crafting) {
ItemStack armorStack = null;
ItemStack dyeStack = null;
for (int x = 0; x < 3; ++x) {
for (int y = 0; y < 3; ++y) {
ItemStack stack = crafting.getItemStackAt(x, y);
if (stack == null) continue;
if (stack.getItem() instanceof IColoredArmor) {
if (armorStack != null) {
return false;
}
armorStack = stack;
continue;
}
if (dyeMap.containsKey(stack.getItem())) {
dyeStack = stack;
continue;
}
return false;
}
}
return armorStack != null && dyeStack != null;
}

@Override
public boolean matchesQuery(SearchQuery query) {
return false;
}

@Override
public ItemStack[] onCraftResult(InventoryCrafting crafting) {
ItemStack[] returnStack = new ItemStack[9];
for (int x = 0; x < 3; ++x) {
for (int y = 0; y < 3; ++y) {
ItemStack stack = crafting.getItemStackAt(x, y);
if (stack == null) continue;
--stack.stackSize;
if (stack.stackSize > 0) continue;
crafting.setSlotContentsAt(x, y, null);
}
}
return returnStack;
}
}
46 changes: 46 additions & 0 deletions src/main/java/mizurin/shieldmod/item/ArmorColored.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package mizurin.shieldmod.item;

import com.mojang.nbt.CompoundTag;
import mizurin.shieldmod.ShieldMod;
import net.minecraft.core.item.ItemArmor;
import net.minecraft.core.item.material.ArmorMaterial;
import turniplabs.halplibe.helper.TextureHelper;
import net.minecraft.core.item.ItemStack;
import useless.prismaticlibe.ColoredArmorTexture;
import useless.prismaticlibe.ColoredTexture;
import useless.prismaticlibe.IColored;
import useless.prismaticlibe.IColoredArmor;

import java.awt.*;

public class ArmorColored extends ItemArmor implements IColoredArmor, IColored {
public static final String MOD_ID = ShieldMod.MOD_ID;
public static final int[][] baseColor = new int[][] {
TextureHelper.getOrCreateItemTexture(ShieldMod.MOD_ID, "leather_helmet.png"),
TextureHelper.getOrCreateItemTexture(ShieldMod.MOD_ID, "leather_chestplate.png"),
TextureHelper.getOrCreateItemTexture(ShieldMod.MOD_ID, "leather_leggings.png"),
TextureHelper.getOrCreateItemTexture(ShieldMod.MOD_ID, "leather_boots.png")};

public ArmorColored(String name, int id, ArmorMaterial material, int armorPiece) {
super(name, id, material, armorPiece);
}
public Color getColor(ItemStack itemStack){
if (itemStack.getData().containsKey("dyed_color")){
CompoundTag colorTag = itemStack.getData().getCompound("dyed_color");
int red = colorTag.getShort("red");
int green = colorTag.getShort("green");
int blue = colorTag.getShort("blue");
return new Color(red, green, blue);
}
return new Color(255, 255,255);
}
@Override
public ColoredTexture[] getTextures(ItemStack itemStack) {
return new ColoredTexture[]{new ColoredTexture(baseColor[armorPiece], getColor(itemStack))};
}

@Override
public ColoredArmorTexture[] getArmorTextures(ItemStack itemStack) {
return new ColoredArmorTexture[]{new ColoredArmorTexture("leather", getColor(itemStack))};
}
}
10 changes: 10 additions & 0 deletions src/main/java/mizurin/shieldmod/item/Shields.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,10 @@
import turniplabs.halplibe.helper.ItemHelper;
import mizurin.shieldmod.ShieldMod;
import org.slf4j.Logger;
import useless.prismaticlibe.IColoredArmor;
import useless.prismaticlibe.debug.ItemArmorColored;
import net.minecraft.core.item.material.ArmorMaterial;
import turniplabs.halplibe.helper.ArmorHelper;

public class Shields {
public static final String MOD_ID = ShieldMod.MOD_ID;
Expand All @@ -18,5 +22,11 @@ public class Shields {
public static final Item diamondShield = ItemHelper.createItem(MOD_ID, new ShieldItem("diamond.shield", 17004, ShieldMaterials.TOOL_DIAMOND), "diamond_shield.png").withTags(ItemTags.preventCreativeMining);
public static final Item steelShield = ItemHelper.createItem(MOD_ID, new ShieldItem("steel.shield", 17005, ShieldMaterials.TOOL_STEEL), "steel_shield.png").withTags(ItemTags.preventCreativeMining);

public static final Item armorLeatherHelmet = ItemHelper.createItem(MOD_ID, new ArmorColored("Leather Cap", 16426,ArmorMaterial.LEATHER , 0 ), "armor.helmet.leather");
public static final Item armorLeatherChest = ItemHelper.createItem(MOD_ID, new ArmorColored("Leather Tunic", 16427,ArmorMaterial.LEATHER , 1 ), "armor.chestplate.leather");
public static final Item armorLeatherLeg = ItemHelper.createItem(MOD_ID, new ArmorColored("Leather Pants", 16428,ArmorMaterial.LEATHER , 2 ), "armor.leggings.leather");
public static final Item armorLeatherBoot = ItemHelper.createItem(MOD_ID, new ArmorColored("Leather Boots", 16429,ArmorMaterial.LEATHER , 3 ), "armor.boots.leather");


public void initializeItems(){}
}
2 changes: 1 addition & 1 deletion src/main/java/mizurin/shieldmod/recipes.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void onRecipesReady() {
RecipeBuilder.Shaped(MOD_ID)
.setShape(" P ","PLP"," P ")
.addInput('P', Item.leather)
.addInput('L', Block.wool)
.addInput('L', "minecraft:wools")
.create("leatherShield", Shields.leatherShield.getDefaultStack());


Expand Down
Binary file added src/main/resources/armor/cloth_1.png~
Binary file not shown.
Binary file added src/main/resources/armor/cloth_2.png~
Binary file not shown.
Binary file added src/main/resources/armor/leather_1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/armor/leather_1.png~
Binary file not shown.
Binary file added src/main/resources/armor/leather_2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added src/main/resources/armor/leather_2.png~
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
11 changes: 11 additions & 0 deletions src/main/resources/lang/shieldmod/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,17 @@ item.shieldmod.diamond.shield.name=Diamond Shield
item.shieldmod.diamond.shield.desc=A tool to block and knockback enemies!
item.shieldmod.steel.shield.name=Steel Shield
item.shieldmod.steel.shield.desc=A tool to block and knockback enemies!
item.shieldmod.armor.helmet.leather.name=Leather Cap
item.shieldmod.armor.helmet.leather.desc=A hat made from a cow's hide
item.shieldmod.armor.chestplate.leather.name=Leather Tunic
item.shieldmod.armor.chestplate.leather.desc=A tunic made from a cow's hide
item.shieldmod.armor.leggings.leather.name=Leather Pants
item.shieldmod.armor.leggings.leather.desc=A pair of trousers made from a cow's hide
item.shieldmod.armor.boots.leather.name=Leather Boots
item.shieldmod.armor.boots.leather.desc=A pair of boots made from a cow's hide



achievements.page.defense.desc=Shield achievements
achievement.shieldmod.block=Block Blocked
achievement.shieldmod.block.desc=Block an attack
Expand Down

0 comments on commit 9d18d70

Please sign in to comment.