Added textures for the key+lock switch

Renaming a key to an empty name returns it to its unnamed state
This commit is contained in:
malte0811 2017-05-20 17:14:43 +02:00
parent 65ba8acbec
commit 9ba2dcb0b6
12 changed files with 41 additions and 10 deletions

View file

@ -129,5 +129,4 @@ public class IndustrialWires {
public void postInit(FMLPostInitializationEvent e) {
proxy.postInit();
}
}

View file

@ -42,6 +42,7 @@ import malte0811.industrialWires.client.panelmodel.PanelModelLoader;
import malte0811.industrialWires.client.render.TileRenderJacobsLadder;
import malte0811.industrialWires.controlpanel.PanelComponent;
import malte0811.industrialWires.items.ItemIC2Coil;
import malte0811.industrialWires.items.ItemKey;
import malte0811.industrialWires.items.ItemPanelComponent;
import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
@ -118,6 +119,11 @@ public class ClientProxy extends CommonProxy {
ModelBakery.registerItemVariants(IndustrialWires.panelComponent, loc);
ModelLoader.setCustomModelResourceLocation(IndustrialWires.panelComponent, meta, new ModelResourceLocation(loc, "inventory"));
}
for (int meta = 0; meta < ItemKey.types.length; meta++) {
ResourceLocation loc = new ResourceLocation(IndustrialWires.MODID, "key/" + ItemKey.types[meta]);
ModelBakery.registerItemVariants(IndustrialWires.key, loc);
ModelLoader.setCustomModelResourceLocation(IndustrialWires.key, meta, new ModelResourceLocation(loc, "inventory"));
}
Block[] blocks = {IndustrialWires.ic2conn, IndustrialWires.mechConv, IndustrialWires.jacobsLadder, IndustrialWires.panel};
for (Block b : blocks) {

View file

@ -98,11 +98,9 @@ public class GuiRenameKey extends GuiContainer {
@Override
public void onGuiClosed() {
super.onGuiClosed();
if (!field.getText().isEmpty()) {
NBTTagCompound nbt = new NBTTagCompound();
nbt.setString("name", field.getText());
IndustrialWires.packetHandler.sendToServer(new MessageItemSync(hand, nbt));
}
}
}

View file

@ -39,14 +39,13 @@ public class RecipeKeyLock implements IRecipe {
return getLockId(inv) != 0;
}
@Nonnull
@Override
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
ItemStack key = getKey(inv);
if (key==null) {
return null;
}
ItemStack ret = key.copy();
ItemStack ret = new ItemStack(IndustrialWires.key, 1, 1);
ItemKey.setId(ret, getLockId(inv));
return ret;
}
@ -59,7 +58,7 @@ public class RecipeKeyLock implements IRecipe {
@Nonnull
@Override
public ItemStack getRecipeOutput() {
return new ItemStack(IndustrialWires.key);
return new ItemStack(IndustrialWires.key, 1, 1);
}
@Nonnull

View file

@ -64,7 +64,7 @@ public class ItemIC2Coil extends Item implements IWireCoil {
setHasSubtypes(true);
this.setCreativeTab(IndustrialWires.creativeTab);
setMaxStackSize(64);
setRegistryName(new ResourceLocation(IndustrialWires.MODID, "ic2WireCoil"));
setRegistryName(new ResourceLocation(IndustrialWires.MODID, "ic2_wire_coil"));
GameRegistry.register(this);
}

View file

@ -25,6 +25,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagInt;
import net.minecraft.nbt.NBTTagString;
import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand;
@ -37,6 +38,7 @@ import javax.annotation.Nullable;
public class ItemKey extends Item implements INetGUIItem {
private static final String lockId = "lockId";
public static final String[] types = {"blank_key", "key"};
public ItemKey() {
setUnlocalizedName(IndustrialWires.MODID + ".key");
@ -72,7 +74,7 @@ public class ItemKey extends Item implements INetGUIItem {
}
public static int idForKey(@Nullable ItemStack held) {
if (held==null||held.getItem()!=IndustrialWires.key) {
if (held==null||held.getItem()!=IndustrialWires.key||held.getMetadata()==0) {
return 0;
}
NBTTagCompound nbt = held.getTagCompound();
@ -90,7 +92,8 @@ public class ItemKey extends Item implements INetGUIItem {
@Nonnull
@Override
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack stack, World worldIn, EntityPlayer playerIn, @Nonnull EnumHand hand) {
if (!worldIn.isRemote&&idForKey(playerIn.getHeldItem(hand))!=0) {
ItemStack held = playerIn.getHeldItem(hand);
if (!worldIn.isRemote&&idForKey(held)!=0) {
playerIn.openGui(IndustrialWires.MODID, 1, worldIn, 0, 0, hand == EnumHand.MAIN_HAND ? 1 : 0);
}
return new ActionResult<>(EnumActionResult.SUCCESS, stack);
@ -99,6 +102,14 @@ public class ItemKey extends Item implements INetGUIItem {
@Override
public void onChange(NBTTagCompound nbt, EntityPlayer p, EnumHand hand) {
ItemStack held = p.getHeldItem(hand);
held.setTagInfo("name", nbt.getTag("name"));
String name = nbt.getString("name");
if (!name.trim().isEmpty()) {
held.setTagInfo("name", new NBTTagString(name));
} else {
NBTTagCompound heldNBT = held.getTagCompound();
if (heldNBT!=null) {
heldNBT.removeTag("name");
}
}
}
}

View file

@ -0,0 +1,6 @@
{
"parent":"item/generated",
"textures": {
"layer0":"industrialwires:items/blank_key"
}
}

View file

@ -0,0 +1,6 @@
{
"parent":"item/generated",
"textures": {
"layer0":"industrialwires:items/key"
}
}

View file

@ -0,0 +1,6 @@
{
"parent":"item/generated",
"textures": {
"layer0":"industrialwires:items/lock_switch"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 321 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 334 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 497 B