no more template shifting

This commit is contained in:
Boblet 2022-05-10 16:24:04 +02:00
parent 416e2e6278
commit 4628858d64
4 changed files with 263 additions and 231 deletions

View File

@ -95,6 +95,14 @@ public class AssemblerRecipes {
if(stack != null && stack.getItem() instanceof ItemAssemblyTemplate) {
ComparableStack comp = ItemAssemblyTemplate.readType(stack);
//NEW
if(comp != null) {
return comp.toStack();
}
//LEGACY
int i = stack.getItemDamage();
if(i >= 0 && i < recipeList.size()) {
return recipeList.get(i).toStack();
@ -108,8 +116,15 @@ public class AssemblerRecipes {
if(stack != null && stack.getItem() instanceof ItemAssemblyTemplate) {
int i = stack.getItemDamage();
//NEW
ComparableStack compStack = ItemAssemblyTemplate.readType(stack);
if(compStack != null) {
AStack[] ret = recipes.get(compStack);
return Arrays.asList(ret);
}
//LEGACY
int i = stack.getItemDamage();
if(i >= 0 && i < recipeList.size()) {
ItemStack out = recipeList.get(i).toStack();

View File

@ -8,7 +8,6 @@ import com.hbm.inventory.RecipesCommon.ComparableStack;
import com.hbm.inventory.RecipesCommon.OreDictStack;
import com.hbm.inventory.recipes.AssemblerRecipes;
import com.hbm.items.ModItems;
import com.hbm.lib.RefStrings;
import com.hbm.util.I18nUtil;
import cpw.mods.fml.relauncher.Side;
@ -18,263 +17,270 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.IIcon;
import net.minecraft.util.StatCollector;
import net.minecraftforge.oredict.OreDictionary;
public class ItemAssemblyTemplate extends Item {
@SideOnly(Side.CLIENT)
protected IIcon hiddenIcon;
public ItemAssemblyTemplate()
{
this.setHasSubtypes(true);
this.setMaxDamage(0);
}
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int meta) {
ComparableStack stack = AssemblerRecipes.recipeList.get(meta);
if(AssemblerRecipes.hidden.get(stack) != null)
return this.hiddenIcon;
return this.itemIcon;
}
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister reg) {
super.registerIcons(reg);
this.hiddenIcon = reg.registerIcon(this.iconString + "_secret");
}
public String getItemStackDisplayName(ItemStack stack)
{
String s = ("" + StatCollector.translateToLocal(this.getUnlocalizedName() + ".name")).trim();
ItemStack out = stack.getItemDamage() < AssemblerRecipes.recipeList.size() ? AssemblerRecipes.recipeList.get(stack.getItemDamage()).toStack() : null;
String s1 = ("" + StatCollector.translateToLocal((out != null ? out.getUnlocalizedName() : "") + ".name")).trim();
if (s1 != null)
{
s = s + " " + s1;
}
return s;
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tabs, List list) {
int count = AssemblerRecipes.recipeList.size();
for(int i = 0; i < count; i++) {
list.add(new ItemStack(item, 1, i));
}
}
public static int getProcessTime(ItemStack stack) {
if(!(stack.getItem() instanceof ItemAssemblyTemplate))
return 100;
int i = stack.getItemDamage();
if(i < 0 || i >= AssemblerRecipes.recipeList.size())
return 100;
ComparableStack out = AssemblerRecipes.recipeList.get(i);
Integer time = AssemblerRecipes.time.get(out);
if(time != null)
return time;
else
return 100;
}
protected IIcon hiddenIcon;
public ItemAssemblyTemplate() {
this.setHasSubtypes(true);
this.setMaxDamage(0);
}
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamage(int meta) {
ComparableStack stack = AssemblerRecipes.recipeList.get(meta);
if(AssemblerRecipes.hidden.get(stack) != null)
return this.hiddenIcon;
return this.itemIcon;
}
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister reg) {
super.registerIcons(reg);
this.hiddenIcon = reg.registerIcon(this.iconString + "_secret");
}
public static void writeType(ItemStack stack, ComparableStack comp) {
if(!stack.hasTagCompound())
stack.stackTagCompound = new NBTTagCompound();
stack.stackTagCompound.setInteger("id", Item.getIdFromItem(comp.item));
stack.stackTagCompound.setByte("count", (byte)comp.stacksize);
stack.stackTagCompound.setShort("meta", (short)comp.meta);
}
public static ComparableStack readType(ItemStack stack) {
if(!stack.hasTagCompound())
return null;
if(!stack.stackTagCompound.hasKey("id"))
return null;
int id = stack.stackTagCompound.getInteger("id");
int count = stack.stackTagCompound.getByte("count");
int meta = stack.stackTagCompound.getShort("meta");
return new ComparableStack(Item.getItemById(id), count, meta);
}
public String getItemStackDisplayName(ItemStack stack) {
String s = ("" + StatCollector.translateToLocal(this.getUnlocalizedName() + ".name")).trim();
ItemStack out = stack.getItemDamage() < AssemblerRecipes.recipeList.size() ? AssemblerRecipes.recipeList.get(stack.getItemDamage()).toStack() : null;
String s1 = ("" + StatCollector.translateToLocal((out != null ? out.getUnlocalizedName() : "") + ".name")).trim();
if(s1 != null) {
s = s + " " + s1;
}
return s;
}
@Override
@SideOnly(Side.CLIENT)
public void getSubItems(Item item, CreativeTabs tabs, List list) {
int count = AssemblerRecipes.recipeList.size();
for(int i = 0; i < count; i++) {
list.add(new ItemStack(item, 1, i));
}
}
public static int getProcessTime(ItemStack stack) {
if(!(stack.getItem() instanceof ItemAssemblyTemplate))
return 100;
int i = stack.getItemDamage();
if(i < 0 || i >= AssemblerRecipes.recipeList.size())
return 100;
//NEW
ComparableStack out = readType(stack);
//LEGACY
if(out == null) out = AssemblerRecipes.recipeList.get(i);
Integer time = AssemblerRecipes.time.get(out);
if(time != null)
return time;
else
return 100;
}
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean bool) {
if(!(stack.getItem() instanceof ItemAssemblyTemplate))
return;
int i = stack.getItemDamage();
if(i < 0 || i >= AssemblerRecipes.recipeList.size()) {
list.add("I AM ERROR");
return;
}
ComparableStack out = AssemblerRecipes.recipeList.get(i);
HashSet<Item> folders = AssemblerRecipes.hidden.get(out);
if(folders == null)
folders = new HashSet() {{ add(ModItems.template_folder); }};
String[] names = new String[folders.size()];
int a = 0;
for(Item folder : folders) {
names[a] = I18nUtil.resolveKey(folder.getUnlocalizedName() + ".name");
a++;
}
if(!(stack.getItem() instanceof ItemAssemblyTemplate))
return;
int i = stack.getItemDamage();
if(i < 0 || i >= AssemblerRecipes.recipeList.size()) {
list.add("I AM ERROR");
return;
}
boolean nbtType = true;
//NEW
ComparableStack out = readType(stack);
//LEGACY
if(out == null) {
out = AssemblerRecipes.recipeList.get(i);
nbtType = false;
}
Integer time = AssemblerRecipes.time.get(out);
HashSet<Item> folders = AssemblerRecipes.hidden.get(out);
if(folders == null)
folders = new HashSet() {
{
add(ModItems.template_folder);
}
};
String[] names = new String[folders.size()];
int a = 0;
for(Item folder : folders) {
names[a] = I18nUtil.resolveKey(folder.getUnlocalizedName() + ".name");
a++;
}
list.add(EnumChatFormatting.YELLOW + I18nUtil.resolveKey("info.templatefolder", String.join(" / ", names)));
if(nbtType) {
list.add(EnumChatFormatting.GREEN + "Persistent template");
} else {
list.add(EnumChatFormatting.RED + "Volatile template");
}
list.add("");
if(out == null) {
list.add("I AM ERROR");
return;
}
Object[] in = AssemblerRecipes.recipes.get(out);
if(in == null) {
list.add("I AM ERROR");
return;
}
ItemStack output = out.toStack();
if(out == null) {
list.add("I AM ERROR");
return;
}
Object[] in = AssemblerRecipes.recipes.get(out);
if(in == null) {
list.add("I AM ERROR");
return;
}
ItemStack output = out.toStack();
list.add(EnumChatFormatting.BOLD + I18nUtil.resolveKey("info.template_out"));
list.add(output.stackSize + "x " + output.getDisplayName());
list.add(EnumChatFormatting.BOLD + I18nUtil.resolveKey("info.template_in_p"));
for(Object o : in) {
if(o instanceof ComparableStack) {
ItemStack input = ((ComparableStack)o).toStack();
list.add(input.stackSize + "x " + input.getDisplayName());
} else if(o instanceof OreDictStack) {
if(o instanceof ComparableStack) {
ItemStack input = ((ComparableStack) o).toStack();
list.add(input.stackSize + "x " + input.getDisplayName());
} else if(o instanceof OreDictStack) {
OreDictStack input = (OreDictStack) o;
ArrayList<ItemStack> ores = OreDictionary.getOres(input.name);
if(ores.size() > 0) {
ItemStack inStack = ores.get((int) (Math.abs(System.currentTimeMillis() / 1000) % ores.size()));
list.add(input.stacksize + "x " + inStack.getDisplayName());
list.add(input.stacksize + "x " + inStack.getDisplayName());
} else {
list.add("I AM ERROR");
list.add("I AM ERROR");
}
}
}
list.add(EnumChatFormatting.BOLD + I18nUtil.resolveKey("info.template_time"));
list.add(Math.floor((float)(getProcessTime(stack)) / 20 * 100) / 100 + " " + I18nUtil.resolveKey("info.template_seconds"));
list.add(Math.floor((float) (getProcessTime(stack)) / 20 * 100) / 100 + " " + I18nUtil.resolveKey("info.template_seconds"));
}
/*@Override
@SideOnly(Side.CLIENT)
public boolean requiresMultipleRenderPasses()
{
return true;
}
public int getRenderPasses(int metadata)
{
return 8;
}
IIcon[] overlays;
/*
* @Override
*
* @SideOnly(Side.CLIENT) public boolean requiresMultipleRenderPasses() {
* return true; }
*
* public int getRenderPasses(int metadata) { return 8; }
*
* IIcon[] overlays;
*
* @Override
*
* @SideOnly(Side.CLIENT) public void registerIcons(IIconRegister
* p_94581_1_) { super.registerIcons(p_94581_1_);
*
* this.overlays = new IIcon[7];
*
* for(int i = 0; i < 7; i++) overlays[i] =
* p_94581_1_.registerIcon("hbm:assembly_template_" + i); }
*
* @Override
*
* @SideOnly(Side.CLIENT) public IIcon getIconFromDamageForRenderPass(int a,
* int b) { return b < 7 ? overlays[b] :
* super.getIconFromDamageForRenderPass(a, b); }
*
* @Override
*
* @SideOnly(Side.CLIENT) public int getColorFromItemStack(ItemStack stack,
* int layer) { if (layer == 7) { return 0xFFFFFF; } else if(layer < 7) {
* int j = colorFromSeed(getSeedFromMeta(stack.getItemDamage(), layer));
*
* if (j < 0) { j = 0xFFFFFF; }
*
* return j; }
*
* return 0; }
*
* private int getSeedFromMeta(int i, int count) { Random rand = new
* Random(i);
*
* int cap = 11;
*
* for(int j = 0; j < count - 1; j++) rand.nextInt(cap);
*
* return rand.nextInt(cap); }
*
* private int colorFromSeed(int i) { switch(i) { case 0: return 0x334077;
* case 1: return 0x6A298F; case 2: return 0xDF3795; case 3: return
* 0xFF0000; case 4: return 0x00FF00; case 5: return 0x0000FF; case 6:
* return 0xFFFF00; case 7: return 0x00FFFF; case 8: return 0x888888; case
* 9: return 0xFFFFFF; case 10: return 0x000000; default: return 0xFFFFFF; }
* }
*/
@Override
@SideOnly(Side.CLIENT)
public void registerIcons(IIconRegister p_94581_1_)
{
super.registerIcons(p_94581_1_);
this.overlays = new IIcon[7];
for(int i = 0; i < 7; i++)
overlays[i] = p_94581_1_.registerIcon("hbm:assembly_template_" + i);
}
@Override
@SideOnly(Side.CLIENT)
public IIcon getIconFromDamageForRenderPass(int a, int b)
{
return b < 7 ? overlays[b] : super.getIconFromDamageForRenderPass(a, b);
}
@Override
@SideOnly(Side.CLIENT)
public int getColorFromItemStack(ItemStack stack, int layer)
{
if (layer == 7)
{
return 0xFFFFFF;
}
else if(layer < 7)
{
int j = colorFromSeed(getSeedFromMeta(stack.getItemDamage(), layer));
if (j < 0)
{
j = 0xFFFFFF;
}
return j;
}
return 0;
}
private int getSeedFromMeta(int i, int count) {
Random rand = new Random(i);
int cap = 11;
for(int j = 0; j < count - 1; j++)
rand.nextInt(cap);
return rand.nextInt(cap);
}
private int colorFromSeed(int i) {
switch(i) {
case 0: return 0x334077;
case 1: return 0x6A298F;
case 2: return 0xDF3795;
case 3: return 0xFF0000;
case 4: return 0x00FF00;
case 5: return 0x0000FF;
case 6: return 0xFFFF00;
case 7: return 0x00FFFF;
case 8: return 0x888888;
case 9: return 0xFFFFFF;
case 10: return 0x000000;
default: return 0xFFFFFF;
}
}*/
/*public Motif getColorMotifFromTemplate(EnumAssemblyTemplate temp) {
//using deprecated value operator, will remove soon
if(temp.getValue() > 0) {
Motif scheme = new Motif(temp.getValue, null);
scheme.setTextureSize(16, 16);
//scheme.applyUniversalScheme();
scheme.colorCount = 4;
//universal scheme configuration for testing
//todo: get textures properly baked, display color for shield
scheme.addColor(0x334077);
scheme.addColor(0x6A298F);
scheme.addColor(0xDF3795);
scheme.addColor(0x334077);
//different test config; prpl, lprpl, cyn, prpl
scheme.unify();
return scheme;
} else {
//return null;
return Motif.defaultInstance;
}
}*/
/*
* public Motif getColorMotifFromTemplate(EnumAssemblyTemplate temp) {
*
* //using deprecated value operator, will remove soon if(temp.getValue() >
* 0) { Motif scheme = new Motif(temp.getValue, null);
* scheme.setTextureSize(16, 16); //scheme.applyUniversalScheme();
* scheme.colorCount = 4; //universal scheme configuration for testing
* //todo: get textures properly baked, display color for shield
* scheme.addColor(0x334077); scheme.addColor(0x6A298F);
* scheme.addColor(0xDF3795); scheme.addColor(0x334077);
*
* //different test config; prpl, lprpl, cyn, prpl
*
* scheme.unify(); return scheme;
*
* } else { //return null; return Motif.defaultInstance; } }
*/
}

View File

@ -1,5 +1,7 @@
package com.hbm.packet;
import com.hbm.inventory.RecipesCommon.ComparableStack;
import com.hbm.inventory.recipes.AssemblerRecipes;
import com.hbm.items.ModItems;
import com.hbm.items.machine.ItemAssemblyTemplate;
import com.hbm.items.machine.ItemCassette;
@ -146,6 +148,15 @@ public class ItemFolderPacket implements IMessage {
}
}
if(output.getItem() == ModItems.assembly_template) {
ComparableStack out = AssemblerRecipes.recipeList.get(output.getItemDamage());
if(out != null) {
out.meta = 0;
ItemAssemblyTemplate.writeType(output, out);
}
}
if(!player.inventory.addItemStackToInventory(output))
player.dropPlayerItemWithRandomChoice(output, true);
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 4.2 KiB