add generic dyeing

This commit is contained in:
Sen 2025-07-06 22:19:14 +02:00
parent b14a99dc05
commit 97b708bb23
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
7 changed files with 80 additions and 133 deletions

View file

@ -12,7 +12,6 @@ import common.item.CheatTab;
import common.item.Item;
import common.item.ItemStack;
import common.item.block.ItemSmallBlock;
import common.item.tool.ItemArmor;
import common.model.Model;
import common.model.ModelProvider;
import common.properties.Property;
@ -538,17 +537,12 @@ public class BlockCauldron extends Block
}
else
{
if (i > 0 && item instanceof ItemArmor)
if (i > 0 && item.canBeDyed() && itemstack.hasColor())
{
ItemArmor itemarmor = (ItemArmor)item;
if (itemarmor.getArmorMaterial().canBeDyed() && itemarmor.hasColor(itemstack))
{
itemarmor.removeColor(itemstack);
this.setWaterLevel(worldIn, pos, state, i - 1);
itemstack.removeColor();
this.setWaterLevel(worldIn, pos, state, i - 1);
// playerIn.triggerAchievement(StatRegistry.armorCleanedStat);
return true;
}
return true;
}
return false;

View file

@ -20,7 +20,6 @@ import common.inventory.InventoryCrafting;
import common.item.Item;
import common.item.ItemStack;
import common.item.material.ItemDye;
import common.item.tool.ItemArmor;
public abstract class CraftingRegistry
{
@ -206,7 +205,7 @@ public abstract class CraftingRegistry
add(new ItemStack(BlockCarpet.getByColor(color).getItem(), 3), "##", '#', BlockWool.getByColor(color).getItem());
}
recipes.add(new RecipesArmorDyes());
recipes.add(new RecipesDyes());
recipes.add(new RecipeRepairItem());
add(new ItemStack(Items.paper, 3), "###", '#', Items.reeds);
@ -624,7 +623,7 @@ public abstract class CraftingRegistry
}
}
private static class RecipesArmorDyes implements IRecipe
private static class RecipesDyes implements IRecipe
{
/**
* Used to check if a recipe matches current crafting inventory
@ -640,11 +639,9 @@ public abstract class CraftingRegistry
if (itemstack1 != null)
{
if (itemstack1.getItem() instanceof ItemArmor)
if (itemstack1.getItem().canBeDyed())
{
ItemArmor itemarmor = (ItemArmor)itemstack1.getItem();
if (!itemarmor.getArmorMaterial().canBeDyed() || itemstack != null)
if (itemstack != null)
{
return false;
}
@ -675,7 +672,6 @@ public abstract class CraftingRegistry
int[] aint = new int[3];
int i = 0;
int j = 0;
ItemArmor itemarmor = null;
for (int k = 0; k < inv.getSizeInventory(); ++k)
{
@ -683,11 +679,9 @@ public abstract class CraftingRegistry
if (itemstack1 != null)
{
if (itemstack1.getItem() instanceof ItemArmor)
if (itemstack1.getItem().canBeDyed())
{
itemarmor = (ItemArmor)itemstack1.getItem();
if (!itemarmor.getArmorMaterial().canBeDyed() || itemstack != null)
if (itemstack != null)
{
return null;
}
@ -695,9 +689,9 @@ public abstract class CraftingRegistry
itemstack = itemstack1.copy();
itemstack.size = 1;
if (itemarmor.hasColor(itemstack1))
if (itemstack1.hasColor())
{
int l = itemarmor.getArmorColor(itemstack);
int l = itemstack.getDyeColor();
float f = (float)(l >> 16 & 255) / 255.0F;
float f1 = (float)(l >> 8 & 255) / 255.0F;
float f2 = (float)(l & 255) / 255.0F;
@ -728,7 +722,7 @@ public abstract class CraftingRegistry
}
}
if (itemarmor == null)
if (itemstack == null)
{
return null;
}
@ -744,7 +738,7 @@ public abstract class CraftingRegistry
k1 = (int)((float)k1 * f3 / f4);
int lvt_12_3_ = (i1 << 8) + j1;
lvt_12_3_ = (lvt_12_3_ << 8) + k1;
itemarmor.setColor(itemstack, lvt_12_3_);
itemstack.setColor(lvt_12_3_);
return itemstack;
}
}

View file

@ -252,7 +252,7 @@ public abstract class ItemRegistry {
register("leather", (new Item()).setDisplay("Leder").setTab(CheatTab.MATERIALS));
register("brick", (new Item()).setDisplay("Ziegel").setTab(CheatTab.MATERIALS));
register("clay_ball", (new Item()).setDisplay("Ton").setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.L));
register("paper", (new Item()).setDisplay("Papier").setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.XL));
register("paper", (new Item()).setDisplay("Papier").setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.XL).setDefaultColor(0xffffff));
register("book", (new ItemBook()).setDisplay("Buch").setTab(CheatTab.MISC));
register("slime_ball", (new Item()).setDisplay("Schleimball").setTab(CheatTab.MATERIALS).setMaxAmount(StackSize.L));
register("egg", (new ItemEgg()).setDisplay("Ei").setMaxAmount(StackSize.L));

View file

@ -30,6 +30,7 @@ public class Item {
private String display;
private CheatTab tab;
private TextColor color = null;
private int defColor = 0xffffffff;
public final Item setUnstackable() {
this.maxAmount = 1;
@ -185,7 +186,10 @@ public class Item {
}
public int getColorFromItemStack(ItemStack stack, int renderPass) {
return 16777215;
if(renderPass > 0)
return 16777215;
int i = stack.getDyeColor();
return i < 0 ? 16777215 : i;
}
public ItemAction getItemUseAction(ItemStack stack) {
@ -277,4 +281,17 @@ public class Item {
public int getDispenseSoundId() {
return 1000;
}
public final boolean canBeDyed() {
return this.defColor != 0xffffffff;
}
public final int getDefaultColor() {
return this.defColor;
}
public final Item setDefaultColor(int color) {
this.defColor = color;
return this;
}
}

View file

@ -30,7 +30,6 @@ public final class ItemStack
public int size;
private Item item;
private int color;
private TagObject tag;
public ItemStack(Item item)
@ -513,6 +512,8 @@ public final class ItemStack
s = s + TextColor.RESET;
list.add(s);
this.item.addInformation(this, playerIn, list);
if(this.item.canBeDyed())
list.add("Farbe: #" + Integer.toHexString(this.getDyeColor()).toUpperCase());
if (this.hasTag())
{
@ -752,4 +753,46 @@ public final class ItemStack
{
this.item = newItem;
}
public boolean hasColor()
{
return this.item.canBeDyed() && this.tag != null && this.tag.hasInt("color");
}
public int getDyeColor()
{
if (!this.item.canBeDyed())
return -1;
if (this.tag != null && this.tag.hasInt("color"))
{
return this.tag.getInt("color");
}
return this.item.getDefaultColor();
}
public void removeColor()
{
if (!this.item.canBeDyed())
throw new UnsupportedOperationException("Kann diesen Gegenstand nicht entfärben!");
if (this.tag != null)
{
if (this.tag.hasInt("color"))
{
this.tag.remove("color");
if(this.tag.isEmpty())
this.tag = null;
}
}
}
public void setColor(int color)
{
if (!this.item.canBeDyed())
throw new UnsupportedOperationException("Kann diesen Gegenstand nicht einfärben!");
if (this.tag == null)
this.tag = new TagObject();
this.tag.setInt("color", color);
}
}

View file

@ -15,7 +15,6 @@ import common.item.ItemStack;
import common.model.Model;
import common.model.ModelProvider;
import common.model.Transforms;
import common.tags.TagObject;
import common.tileentity.TileEntity;
import common.util.BlockPos;
import common.util.BoundingBox;
@ -54,25 +53,8 @@ public class ItemArmor extends Item
this.damageReduceAmount = material.getDamageReduction(armorType);
this.setMaxDamage(material.getDurability(armorType));
this.setTab(CheatTab.ARMOR);
}
public int getColorFromItemStack(ItemStack stack, int renderPass)
{
if (renderPass > 0)
{
return 16777215;
}
else
{
int i = this.getArmorColor(stack);
if (i < 0)
{
i = 16777215;
}
return i;
}
if(this.material.canBeDyed())
this.setDefaultColor(this.material.getDefaultColor());
}
/**
@ -96,80 +78,6 @@ public class ItemArmor extends Item
return this.texture;
}
/**
* Return whether the specified armor ItemStack has a color.
*/
public boolean hasColor(ItemStack stack)
{
return this.material.canBeDyed() && stack.hasTag() && stack.getTag().hasInt("color");
}
/**
* Return the color for the specified armor ItemStack.
*/
public int getArmorColor(ItemStack stack)
{
if (!this.material.canBeDyed())
{
return -1;
}
else
{
TagObject nbttagcompound = stack.getTag();
if (nbttagcompound != null && nbttagcompound.hasInt("color"))
{
return nbttagcompound.getInt("color");
}
return this.material.getDefaultColor();
}
}
/**
* Remove the color from the specified armor ItemStack.
*/
public void removeColor(ItemStack stack)
{
if (this.material.canBeDyed())
{
TagObject nbttagcompound = stack.getTag();
if (nbttagcompound != null)
{
if (nbttagcompound.hasInt("color"))
{
nbttagcompound.remove("color");
if(nbttagcompound.isEmpty())
stack.setTag(null);
}
}
}
}
/**
* Sets the color of the specified armor ItemStack
*/
public void setColor(ItemStack stack, int color)
{
if (!this.material.canBeDyed())
{
throw new UnsupportedOperationException("Kann diese Rüstung nicht färben!");
}
else
{
TagObject nbttagcompound = stack.getTag();
if (nbttagcompound == null)
{
nbttagcompound = new TagObject();
stack.setTag(nbttagcompound);
}
nbttagcompound.setInt("color", color);
}
}
/**
* Return whether this item is repairable in an anvil.
*/
@ -224,15 +132,6 @@ public class ItemArmor extends Item
else
return super.getModel(provider, name);
}
public void addInformation(ItemStack stack, EntityNPC playerIn, List<String> tooltip) {
if(this.material.canBeDyed()) {
int color = this.material.getDefaultColor();
if(stack.hasTag() && stack.getTag().hasInt("color"))
color = stack.getTag().getInt("color");
tooltip.add("Farbe: #" + Integer.toHexString(color).toUpperCase());
}
}
// public Set<String> getValidTags() {
// return Sets.newHashSet("color");