Fixes for the previous commits

This commit is contained in:
malte0811 2017-05-26 13:26:15 +02:00
parent 55e03ab8a4
commit b11ca376a3
7 changed files with 40 additions and 30 deletions

View file

@ -30,7 +30,7 @@ public class IWConfig {
@Comment({"Set this to false to completely disable any conversion between IF and EU (default: true)"}) @Comment({"Set this to false to completely disable any conversion between IF and EU (default: true)"})
public static boolean enableConversion = true; public static boolean enableConversion = true;
public static MechConversion mech; public static MechConversion mech = new MechConversion();
public static class MechConversion { public static class MechConversion {
@Comment({"The amount of EU that would be produced by an ideal converter from 1 IF (default: 0.25)"}) @Comment({"The amount of EU that would be produced by an ideal converter from 1 IF (default: 0.25)"})
@ -54,7 +54,7 @@ public class IWConfig {
public static double kinToRotEfficiency = .8; public static double kinToRotEfficiency = .8;
} }
public static HVStuff hv; public static HVStuff hv = new HVStuff();
public static class HVStuff { public static class HVStuff {
@Comment({"The amount of EU a Jacobs Ladder uses per tick, sorted by size of the ladder"}) @Comment({"The amount of EU a Jacobs Ladder uses per tick, sorted by size of the ladder"})

View file

@ -45,11 +45,13 @@ public class GuiRenameKey extends GuiContainer {
@Override @Override
public void initGui() { public void initGui() {
super.initGui(); super.initGui();
field = new GuiTextField(0, mc.fontRenderer, (width-58)/2, (height-12)/2, 58, 12); field = new GuiTextField(0, mc.fontRendererObj, (width-58)/2, (height-12)/2, 58, 12);
ItemStack held = mc.player.getHeldItem(hand); ItemStack held = mc.thePlayer.getHeldItem(hand);
NBTTagCompound nbt = held.getTagCompound(); if (held!=null) {
if (nbt!=null&&nbt.hasKey("name")) { NBTTagCompound nbt = held.getTagCompound();
field.setText(nbt.getString("name")); if (nbt != null && nbt.hasKey("name")) {
field.setText(nbt.getString("name"));
}
} }
xSize = 64; xSize = 64;
ySize = 64; ySize = 64;

View file

@ -165,15 +165,15 @@ public class Lock extends PanelComponent implements IConfigurableComponent {
if (keyNBT == null) { if (keyNBT == null) {
for (EnumHand hand : EnumHand.values()) { for (EnumHand hand : EnumHand.values()) {
ItemStack held = player.getHeldItem(hand); ItemStack held = player.getHeldItem(hand);
if (held.getItem() == IndustrialWires.key && ItemKey.idForKey(held) == lockID) { if (held!=null && held.getItem() == IndustrialWires.key && ItemKey.idForKey(held) == lockID) {
keyNBT = held.serializeNBT(); keyNBT = held.serializeNBT();
player.setHeldItem(hand, ItemStack.EMPTY); player.setHeldItem(hand, null);
break; break;
} }
} }
} else if (!turned) { } else if (!turned) {
if (player.isSneaking() && player.getHeldItemMainhand().isEmpty()) { if (player.isSneaking() && player.getHeldItemMainhand()== null) {
player.setHeldItem(EnumHand.MAIN_HAND, new ItemStack(keyNBT)); player.setHeldItem(EnumHand.MAIN_HAND, ItemStack.loadItemStackFromNBT(keyNBT));
keyNBT = null; keyNBT = null;
} else { } else {
turned = true; turned = true;

View file

@ -25,10 +25,11 @@ import malte0811.industrialWires.items.ItemPanelComponent;
import net.minecraft.inventory.InventoryCrafting; import net.minecraft.inventory.InventoryCrafting;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.IRecipe; import net.minecraft.item.crafting.IRecipe;
import net.minecraft.util.NonNullList;
import net.minecraft.world.World; import net.minecraft.world.World;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import javax.annotation.Nullable;
//TODO JEI //TODO JEI
public class RecipeKeyLock implements IRecipe { public class RecipeKeyLock implements IRecipe {
@ -40,7 +41,11 @@ public class RecipeKeyLock implements IRecipe {
@Nonnull @Nonnull
@Override @Override
public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) { public ItemStack getCraftingResult(@Nonnull InventoryCrafting inv) {
ItemStack ret = getKey(inv).copy(); ItemStack key = getKey(inv);
if (key==null) {
return null;
}
ItemStack ret = key.copy();
ItemKey.setId(ret, getLockId(inv)); ItemKey.setId(ret, getLockId(inv));
return ret; return ret;
} }
@ -58,12 +63,12 @@ public class RecipeKeyLock implements IRecipe {
@Nonnull @Nonnull
@Override @Override
public NonNullList<ItemStack> getRemainingItems(@Nonnull InventoryCrafting inv) { public ItemStack[] getRemainingItems(@Nonnull InventoryCrafting inv) {
NonNullList<ItemStack> ret = NonNullList.withSize(inv.getSizeInventory(), ItemStack.EMPTY); ItemStack[] ret = new ItemStack[inv.getSizeInventory()];
for (int i = 0; i < ret.size(); i++) { for (int i = 0; i < ret.length; i++) {
ItemStack here = inv.getStackInSlot(i); ItemStack here = inv.getStackInSlot(i);
if (here.getItem() == IndustrialWires.panelComponent) { if (here!=null && here.getItem() == IndustrialWires.panelComponent) {
ret.set(i, here); ret[i] = here;
} }
} }
return ret; return ret;
@ -74,12 +79,12 @@ public class RecipeKeyLock implements IRecipe {
boolean hasKey = false; boolean hasKey = false;
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.getItem() == IndustrialWires.key) { if (here!=null && here.getItem() == IndustrialWires.key) {
if (hasKey || ItemKey.idForKey(here) != 0) {//too many keys or non-blanks if (hasKey || ItemKey.idForKey(here) != 0) {//too many keys or non-blanks
return 0; return 0;
} }
hasKey = true; hasKey = true;
} else if (here.getItem() == IndustrialWires.panelComponent) { } else if (here != null && here.getItem() == IndustrialWires.panelComponent) {
if (id != 0) {//too many locks/components if (id != 0) {//too many locks/components
return 0; return 0;
} }
@ -97,15 +102,15 @@ public class RecipeKeyLock implements IRecipe {
return id; return id;
} }
@Nonnull @Nullable
//assumes that the recipe is valid //assumes that the recipe is valid
private ItemStack getKey(@Nonnull InventoryCrafting inv) { private ItemStack getKey(@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.getItem() == IndustrialWires.key) { if (here!=null && here.getItem() == IndustrialWires.key) {
return here; return here;
} }
} }
return ItemStack.EMPTY; return null;
} }
} }

View file

@ -40,7 +40,10 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagInt; import net.minecraft.nbt.NBTTagInt;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.*; import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.util.text.TextComponentTranslation;

View file

@ -86,13 +86,13 @@ public class ItemKey extends Item implements INetGUIItem {
return 1; return 1;
} }
@Override
@Nonnull @Nonnull
public ActionResult<ItemStack> onItemRightClick(World worldIn, EntityPlayer playerIn, @Nonnull EnumHand hand) { @Override
public ActionResult<ItemStack> onItemRightClick(@Nonnull ItemStack stack, World worldIn, EntityPlayer playerIn, @Nonnull EnumHand hand) {
if (!worldIn.isRemote) { if (!worldIn.isRemote) {
playerIn.openGui(IndustrialWires.MODID, 1, worldIn, 0, 0, hand == EnumHand.MAIN_HAND ? 1 : 0); playerIn.openGui(IndustrialWires.MODID, 1, worldIn, 0, 0, hand == EnumHand.MAIN_HAND ? 1 : 0);
} }
return new ActionResult<>(EnumActionResult.SUCCESS, playerIn.getHeldItem(hand)); return new ActionResult<>(EnumActionResult.SUCCESS, stack);
} }
@Override @Override

View file

@ -56,10 +56,10 @@ public class MessageItemSync implements IMessage {
public static class HandlerServer implements IMessageHandler<MessageItemSync, IMessage> { public static class HandlerServer implements IMessageHandler<MessageItemSync, IMessage> {
@Override @Override
public IMessage onMessage(MessageItemSync message, MessageContext ctx) { public IMessage onMessage(MessageItemSync message, MessageContext ctx) {
EntityPlayer player = ctx.getServerHandler().player; EntityPlayer player = ctx.getServerHandler().playerEntity;
ItemStack held = player.getHeldItem(message.hand); ItemStack held = player.getHeldItem(message.hand);
if (held.getItem() instanceof INetGUIItem) { if (held!=null && held.getItem() instanceof INetGUIItem) {
ctx.getServerHandler().player.getServerWorld().addScheduledTask(() -> ctx.getServerHandler().playerEntity.getServerWorld().addScheduledTask(() ->
((INetGUIItem)held.getItem()).onChange(message.data, player, message.hand)); ((INetGUIItem)held.getItem()).onChange(message.data, player, message.hand));
} }
return null; return null;