Added documentation on the key ring and fixed some bugs with it

Backported other fixes from 1.12
This commit is contained in:
malte0811 2017-07-13 17:53:05 +02:00
parent 78bc37771a
commit 20cd180757
6 changed files with 93 additions and 57 deletions

View file

@ -94,7 +94,8 @@ public class Recipes {
RecipeSorter.register("industrialwires:coilLength", RecipeCoilLength.class, RecipeSorter.Category.SHAPELESS, "after:forge:shapelessore"); RecipeSorter.register("industrialwires:coilLength", RecipeCoilLength.class, RecipeSorter.Category.SHAPELESS, "after:forge:shapelessore");
RecipeSorter.register("industrialwires:init_pc", RecipeInitPC.class, RecipeSorter.Category.SHAPED, "after:forge:shapedore"); RecipeSorter.register("industrialwires:init_pc", RecipeInitPC.class, RecipeSorter.Category.SHAPED, "after:forge:shapedore");
GameRegistry.addRecipe(new RecipeKeyLock()); GameRegistry.addRecipe(new RecipeKeyLock());
GameRegistry.addRecipe(new RecipeKeyRing()); GameRegistry.addRecipe(new RecipeKeyRing(true));
GameRegistry.addRecipe(new RecipeKeyRing(false));
GameRegistry.addRecipe(new RecipeComponentCopy()); GameRegistry.addRecipe(new RecipeComponentCopy());
for (int i = 0; i < IC2Wiretype.IC2_TYPES.length; i++) { for (int i = 0; i < IC2Wiretype.IC2_TYPES.length; i++) {
GameRegistry.addRecipe(new RecipeCoilLength(i)); GameRegistry.addRecipe(new RecipeCoilLength(i));
@ -136,6 +137,9 @@ public class Recipes {
"rdr", " w ", 'r', "stickSteel", 'd', Items.IRON_DOOR, 'w', "wireCopper")); "rdr", " w ", 'r', "stickSteel", 'd', Items.IRON_DOOR, 'w', "wireCopper"));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(key, 1, 0), GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(key, 1, 0),
"rrp", 'r', "stickSteel", 'p', "plateSteel")); "rrp", 'r', "stickSteel", 'p', "plateSteel"));
GameRegistry.addRecipe(new ShapelessOreRecipe(new ItemStack(panelComponent, 1, 8),
"wireCopper", new ItemStack(IEContent.itemTool, 1, 2)));
GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(key, 1, 2), " r ", "r r", " r ", 'r', "stickSteel"));
} }
private static void addJacobs() { private static void addJacobs() {
ItemStack mvTransformer = IC2Items.getItem("te", "mv_transformer"); ItemStack mvTransformer = IC2Items.getItem("te", "mv_transformer");

View file

@ -212,9 +212,10 @@ public class ClientProxy extends CommonProxy {
); );
} }
Config.manual_doubleA.put("iwJacobsUsage", IWConfig.HVStuff.jacobsUsageEU); Config.manual_doubleA.put("iwJacobsUsage", IWConfig.HVStuff.jacobsUsageEU);
m.addEntry("industrialWires.jacobs", "industrialWires", Config.manual_int.put("iwKeysOnRing", IWConfig.maxKeysOnRing);
new ManualPages.CraftingMulti(m, "industrialWires.jacobs0", new ItemStack(IndustrialWires.jacobsLadder, 1, 0), new ItemStack(IndustrialWires.jacobsLadder, 1, 1), new ItemStack(IndustrialWires.jacobsLadder, 1, 2)), m.addEntry("industrialwires.jacobs", "industrialwires",
new ManualPages.Text(m, "industrialWires.jacobs1")); new ManualPages.CraftingMulti(m, "industrialwires.jacobs0", new ItemStack(IndustrialWires.jacobsLadder, 1, 0), new ItemStack(IndustrialWires.jacobsLadder, 1, 1), new ItemStack(IndustrialWires.jacobsLadder, 1, 2)),
new ManualPages.Text(m, "industrialwires.jacobs1"));
m.addEntry("industrialWires.intro", "control_panels", m.addEntry("industrialWires.intro", "control_panels",
@ -241,7 +242,8 @@ public class ClientProxy extends CommonProxy {
new ManualPages.CraftingMulti(m, "industrialwires.toggle_switch", new ItemStack(IndustrialWires.panelComponent, 1, 5), new ItemStack(IndustrialWires.panelComponent, 1, 6)), new ManualPages.CraftingMulti(m, "industrialwires.toggle_switch", new ItemStack(IndustrialWires.panelComponent, 1, 5), new ItemStack(IndustrialWires.panelComponent, 1, 6)),
new ManualPages.Text(m, "industrialwires.toggle_switch1"), new ManualPages.Text(m, "industrialwires.toggle_switch1"),
new ManualPages.Crafting(m, "industrialwires.variac", new ItemStack(IndustrialWires.panelComponent, 1, 4)), new ManualPages.Crafting(m, "industrialwires.variac", new ItemStack(IndustrialWires.panelComponent, 1, 4)),
new ManualPages.CraftingMulti(m, "industrialwires.lock", new ItemStack(IndustrialWires.panelComponent, 1, 7), new ItemStack(IndustrialWires.key)) new ManualPages.CraftingMulti(m, "industrialwires.lock", new ItemStack(IndustrialWires.panelComponent, 1, 7), new ItemStack(IndustrialWires.key)),
new ManualPages.Crafting(m, "industrialwires.lock1", new ItemStack(IndustrialWires.key, 1, 2))
); );
} }

View file

@ -25,9 +25,11 @@ import net.minecraft.item.crafting.IRecipe;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import javax.annotation.Nonnull;
public class RecipeCoilLength implements IRecipe { public class RecipeCoilLength implements IRecipe {
public final ItemStack coil; private final ItemStack coil;
public final ItemStack cable; private final ItemStack cable;
private final int maxLength; private final int maxLength;
public RecipeCoilLength(int meta) { public RecipeCoilLength(int meta) {
@ -37,13 +39,13 @@ public class RecipeCoilLength implements IRecipe {
} }
@Override @Override
public boolean matches(InventoryCrafting inv, World worldIn) { public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
int l = getLength(inv); int l = getLength(inv);
return l > 0; return l > 0;
} }
@Override @Override
public ItemStack getCraftingResult(InventoryCrafting inv) { public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
ItemStack ret = new ItemStack(IndustrialWires.coil, 1, coil.getItemDamage()); ItemStack ret = new ItemStack(IndustrialWires.coil, 1, coil.getItemDamage());
ItemIC2Coil.setLength(ret, Math.min(maxLength, getLength(inv))); ItemIC2Coil.setLength(ret, Math.min(maxLength, getLength(inv)));
return ret; return ret;
@ -59,8 +61,9 @@ public class RecipeCoilLength implements IRecipe {
return null; return null;
} }
@Nonnull
@Override @Override
public ItemStack[] getRemainingItems(InventoryCrafting inv) { public ItemStack[] getRemainingItems(@Nonnull InventoryCrafting inv) {
ItemStack[] ret = new ItemStack[inv.getSizeInventory()]; ItemStack[] ret = new ItemStack[inv.getSizeInventory()];
int length = Math.min(getLength(inv), maxLength); int length = Math.min(getLength(inv), maxLength);
for (int i = 0;i<ret.length&&length>0;i++) { for (int i = 0;i<ret.length&&length>0;i++) {
@ -68,7 +71,7 @@ public class RecipeCoilLength implements IRecipe {
if (OreDictionary.itemMatches(curr, coil, false)) { if (OreDictionary.itemMatches(curr, coil, false)) {
length-=ItemIC2Coil.getLength(curr); length-=ItemIC2Coil.getLength(curr);
if (length<0) { if (length<0) {
ret[i] = new ItemStack(IndustrialWires.coil, 1); ret[i] = coil.copy();
ItemIC2Coil.setLength(ret[i], -length); ItemIC2Coil.setLength(ret[i], -length);
} }
} else if (OreDictionary.itemMatches(curr, cable, false)) { } else if (OreDictionary.itemMatches(curr, cable, false)) {

View file

@ -27,52 +27,57 @@ import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import static malte0811.industrialWires.items.ItemKey.*; import static malte0811.industrialWires.items.ItemKey.*;
public class RecipeKeyRing implements IRecipe { public class RecipeKeyRing implements IRecipe {
private final boolean addToRing;
public RecipeKeyRing(boolean add) {
addToRing = add;
}
@Override @Override
public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) { public boolean matches(@Nonnull InventoryCrafting inv, @Nonnull World worldIn) {
return getType(inv) != null; return isValid(inv);
} }
@Override @Override
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) { public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
Boolean recipeType = getType(inv); if (isValid(inv)) {
if (recipeType==Boolean.TRUE) {//add key to ring if (addToRing) {//add key to ring
ItemStack ring = inv.getStackInSlot(getRingPos(inv)).copy(); ItemStack ring = inv.getStackInSlot(getRingPos(inv)).copy();
NBTTagCompound nbt = ring.getTagCompound(); NBTTagCompound nbt = ring.getTagCompound();
ItemStack key = inv.getStackInSlot(getKeyPos(inv)); ItemStack key = inv.getStackInSlot(getKeyPos(inv));
NBTTagCompound keyNBT = key.getTagCompound(); NBTTagCompound keyNBT = key.getTagCompound();
if (nbt==null) { if (nbt == null) {
nbt = new NBTTagCompound(); nbt = new NBTTagCompound();
ring.setTagCompound(nbt); ring.setTagCompound(nbt);
}
if (!nbt.hasKey(RING_KEYS)) {
nbt.setTag(RING_KEYS, new NBTTagList());
}
if (keyNBT!=null) {
NBTTagList keys = nbt.getTagList(RING_KEYS, 10);
if (keys.tagCount()>= IWConfig.maxKeysOnRing) {
return null;
} }
keys.appendTag(keyNBT.copy()); if (!nbt.hasKey(RING_KEYS)) {
nbt.setInteger(LOCK_ID, keyNBT.getInteger(LOCK_ID)); nbt.setTag(RING_KEYS, new NBTTagList());
nbt.setString(NAME, keyNBT.getString(NAME)); }
} if (keyNBT != null) {
return ring; NBTTagList keys = nbt.getTagList(RING_KEYS, 10);
} else {//remove key from ring if (keys.tagCount() >= IWConfig.maxKeysOnRing) {
ItemStack ring = inv.getStackInSlot(getRingPos(inv)).copy(); return null;
NBTTagCompound nbt = ring.getTagCompound(); }
ItemStack key = new ItemStack(IndustrialWires.key, 1, 1); keys.appendTag(keyNBT.copy());
if (nbt!=null) { nbt.setInteger(LOCK_ID, keyNBT.getInteger(LOCK_ID));
NBTTagList keys = nbt.getTagList(RING_KEYS, 10); nbt.setString(NAME, keyNBT.getString(NAME));
if (keys.tagCount()>0) { }
NBTTagCompound first = keys.getCompoundTagAt(keys.tagCount()-1); return ring;
key.setTagCompound(first); } else {//remove key from ring
return key; ItemStack ring = inv.getStackInSlot(getRingPos(inv)).copy();
NBTTagCompound nbt = ring.getTagCompound();
ItemStack key = new ItemStack(IndustrialWires.key, 1, 1);
if (nbt != null) {
NBTTagList keys = nbt.getTagList(RING_KEYS, 10);
if (keys.tagCount() > 0) {
NBTTagCompound first = keys.getCompoundTagAt(keys.tagCount() - 1);
key.setTagCompound(first);
return key;
}
} }
} }
} }
@ -81,19 +86,20 @@ public class RecipeKeyRing implements IRecipe {
@Override @Override
public int getRecipeSize() { public int getRecipeSize() {
return 2; return 1;
} }
@Nonnull
@Override @Override
public ItemStack getRecipeOutput() { public ItemStack getRecipeOutput() {
return null; return new ItemStack(IndustrialWires.key, 1, addToRing?2:1);
} }
@Nonnull @Nonnull
@Override @Override
public ItemStack[] getRemainingItems(@Nonnull InventoryCrafting inv) { public ItemStack[] getRemainingItems(@Nonnull InventoryCrafting inv) {
ItemStack[] ret = new ItemStack[inv.getSizeInventory()]; ItemStack[] ret = new ItemStack[inv.getSizeInventory()];
if (getType(inv)==Boolean.FALSE) { if (!addToRing) {
int ringId = getRingPos(inv); int ringId = getRingPos(inv);
ItemStack ring = inv.getStackInSlot(ringId).copy(); ItemStack ring = inv.getStackInSlot(ringId).copy();
NBTTagCompound nbt = ring.getTagCompound(); NBTTagCompound nbt = ring.getTagCompound();
@ -102,6 +108,8 @@ public class RecipeKeyRing implements IRecipe {
keys.removeTag(keys.tagCount()-1); keys.removeTag(keys.tagCount()-1);
if (keys.tagCount() > 0) { if (keys.tagCount() > 0) {
NBTTagCompound first = keys.getCompoundTagAt(0); NBTTagCompound first = keys.getCompoundTagAt(0);
keys.removeTag(0);
keys.appendTag(first);
nbt.setInteger(LOCK_ID, first.getInteger(LOCK_ID)); nbt.setInteger(LOCK_ID, first.getInteger(LOCK_ID));
nbt.setString(NAME, first.getString(NAME)); nbt.setString(NAME, first.getString(NAME));
} else { } else {
@ -114,8 +122,7 @@ public class RecipeKeyRing implements IRecipe {
return ret; return ret;
} }
@Nullable private boolean isValid(@Nonnull InventoryCrafting inv) {
private Boolean getType(@Nonnull InventoryCrafting inv) {
boolean hasRing = false; boolean hasRing = false;
boolean hasKey = false; boolean hasKey = false;
for (int i = 0;i<inv.getSizeInventory();i++) { for (int i = 0;i<inv.getSizeInventory();i++) {
@ -128,18 +135,22 @@ public class RecipeKeyRing implements IRecipe {
hasRing = true; hasRing = true;
continue; continue;
} }
return null; return false;
} else if (here!=null) { } else if (here!=null) {
return null; return false;
} }
} }
return hasRing?hasKey:null; if (addToRing) {
return hasKey&&hasRing;
} else {
return !hasKey&&hasRing;
}
} }
private int getRingPos(@Nonnull InventoryCrafting inv) { private int getRingPos(@Nonnull InventoryCrafting inv) {
for (int i = 0;i<inv.getSizeInventory();i++) { for (int i = 0;i<inv.getSizeInventory();i++) {
ItemStack here = inv.getStackInSlot(i); ItemStack here = inv.getStackInSlot(i);
if (here!=null&& here.getItem()==IndustrialWires.key&&here.getMetadata()==2) { if (here!=null&&here.getItem()==IndustrialWires.key&&here.getMetadata()==2) {
return i; return i;
} }
} }
@ -148,7 +159,7 @@ public class RecipeKeyRing implements IRecipe {
private int getKeyPos(@Nonnull InventoryCrafting inv) { private int getKeyPos(@Nonnull InventoryCrafting inv) {
for (int i = 0;i<inv.getSizeInventory();i++) { for (int i = 0;i<inv.getSizeInventory();i++) {
ItemStack here = inv.getStackInSlot(i); ItemStack here = inv.getStackInSlot(i);
if (here!=null && here.getItem()==IndustrialWires.key&&here.getMetadata()==1) { if (here!=null&&here.getItem()==IndustrialWires.key&&here.getMetadata()==1) {
return i; return i;
} }
} }

View file

@ -67,10 +67,20 @@ public class ItemKey extends Item implements INetGUIItem {
subItems.add(new ItemStack(this, 1, 2)); subItems.add(new ItemStack(this, 1, 2));
} }
@Override
public void addInformation(ItemStack stack, EntityPlayer player, List<String> tooltip, boolean advanced) {
super.addInformation(stack, player, tooltip, advanced);
if (stack.getMetadata()==2&&stack.getTagCompound()!=null) {
NBTTagList keys = stack.getTagCompound().getTagList(RING_KEYS, 10);
for (int i = 0;i< keys.tagCount()-1;i++) {
tooltip.add(I18n.format("item."+IndustrialWires.MODID+".key.key_named.name")+" "+keys.getCompoundTagAt(i).getString(NAME));
}
}
}
@Nonnull @Nonnull
@Override @Override
public String getUnlocalizedName(ItemStack stack) { public String getUnlocalizedName(ItemStack stack) {
NBTTagCompound nbt = stack.getTagCompound();
return "item."+IndustrialWires.MODID+".key."+types[stack.getMetadata()]; return "item."+IndustrialWires.MODID+".key."+types[stack.getMetadata()];
} }

View file

@ -132,4 +132,10 @@ ie.manual.entry.industrialwires.slider=A sliding switch that can set an output r
ie.manual.entry.industrialwires.toggle_switch=A switch to turn a signal on or off. The covered version includes a cover to prevent accidental activation: When clicked for the first time the cover will open, the signal will be turned on by clicking once again. Another click will close the cover and turn off the output signal. If the cover was opened by accident it can be closed by shift-right-clicking ie.manual.entry.industrialwires.toggle_switch=A switch to turn a signal on or off. The covered version includes a cover to prevent accidental activation: When clicked for the first time the cover will open, the signal will be turned on by clicking once again. Another click will close the cover and turn off the output signal. If the cover was opened by accident it can be closed by shift-right-clicking
ie.manual.entry.industrialwires.toggle_switch1=the switch. The color of the cover can be configured. ie.manual.entry.industrialwires.toggle_switch1=the switch. The color of the cover can be configured.
ie.manual.entry.industrialwires.variac=A Variac® is a variable autotransformer. The output signal of the transformer increases as the knob is turned to the right. The signal strenght can only be increased by one unit per click. ie.manual.entry.industrialwires.variac=A Variac® is a variable autotransformer. The output signal of the transformer increases as the knob is turned to the right. The signal strenght can only be increased by one unit per click.
ie.manual.entry.industrialwires.lock=A lock switch activates a redstone signal when a key is inserted and turned. A newly crafted lock will have a unique key configuration. By placing a blank key and a lock in a crafting table a key for the lock can be created. Multiple locks fitting the same key can be created using component copying (see page 1). Keys can be named in a GUI opened by right-clicking with them. <<<<<<< HEAD
ie.manual.entry.industrialwires.lock=A lock switch activates a redstone signal when a key is inserted and turned. A newly crafted lock will have a unique key configuration. By placing a blank key and a lock in a crafting table a key for the lock can be created. Multiple locks fitting the same key can be created using component copying (see page 1). Keys can be named in a GUI opened by right-clicking with them.
=======
ie.manual.entry.industrialwires.lock=A lock switch activates a redstone signal when a key is inserted and turned. A newly crafted lock will have a unique key configuration. By placing a blank key and a lock in a crafting table a key for the lock can be created. Multiple locks fitting the same key can be created using component copying (see page 1). Keys can be named in a GUI opened by right-clicking with them.
ie.manual.entry.industrialwires.lock1=Up to <config;I;iwKeysOnRing> can be combined on a key ring. Keys are added to the ring by placing both in a crafting table. Shift-right-click the key ring to cycle through the keys on the ring. The selected key can be removed from the ring by placing the ring in a crafting table. The key ring will work just as the selected key would on lock switches.
ie.manual.entry.industrialwires.panel_meter=A panel meter can be used to show display analog redstone signals with some accuracy. Panel meters are available in two different formats, wide and narrow. The wide format gives a slightly bigger angle between redstone level 0 and 15, but is more typical for Multimeters that for panel meters.
>>>>>>> 9b9d3ed... Added documentation on the key ring and fixed some bugs with it