Clean up inventory code, chat message changes

Remove support for non-existing ISidedInventory from Forge
Fixed sending chat message to player - 1.6 changes
This commit is contained in:
Adam Rosadzinski 2013-07-16 15:40:35 +02:00
parent 0b5d898469
commit 81886bc8d7
6 changed files with 11 additions and 51 deletions

View file

@ -6,6 +6,7 @@ import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommand; import net.minecraft.command.ICommand;
import net.minecraft.command.ICommandSender; import net.minecraft.command.ICommandSender;
import net.minecraft.command.WrongUsageException; import net.minecraft.command.WrongUsageException;
import net.minecraft.util.ChatMessageComponent;
public class CommandBuildCraft extends CommandBase { public class CommandBuildCraft extends CommandBase {
@ -45,9 +46,9 @@ public class CommandBuildCraft extends CommandBase {
commandVersion(sender, arguments); commandVersion(sender, arguments);
return; return;
} else if (arguments[0].matches("help")) { } else if (arguments[0].matches("help")) {
sender.sendChatToPlayer("Format: '" + this.getCommandName() + " <command> <arguments>'"); sender.sendChatToPlayer(ChatMessageComponent.func_111066_d("Format: '" + this.getCommandName() + " <command> <arguments>'"));
sender.sendChatToPlayer("Available commands:"); sender.sendChatToPlayer(ChatMessageComponent.func_111066_d("Available commands:"));
sender.sendChatToPlayer("- version : Version information."); sender.sendChatToPlayer(ChatMessageComponent.func_111066_d("- version : Version information."));
return; return;
} }
@ -57,11 +58,11 @@ public class CommandBuildCraft extends CommandBase {
private void commandVersion(ICommandSender sender, String[] arguments) { private void commandVersion(ICommandSender sender, String[] arguments) {
String colour = Version.isOutdated() ? "\u00A7c" : "\u00A7a"; String colour = Version.isOutdated() ? "\u00A7c" : "\u00A7a";
sender.sendChatToPlayer(String.format(colour + "BuildCraft %s for Minecraft %s (Latest: %s).", Version.getVersion(), sender.sendChatToPlayer(ChatMessageComponent.func_111066_d(String.format(colour + "BuildCraft %s for Minecraft %s (Latest: %s).", Version.getVersion(),
CoreProxy.proxy.getMinecraftVersion(), Version.getRecommendedVersion())); CoreProxy.proxy.getMinecraftVersion(), Version.getRecommendedVersion())));
if (Version.isOutdated()) { if (Version.isOutdated()) {
for (String updateLine : Version.getChangelog()) { for (String updateLine : Version.getChangelog()) {
sender.sendChatToPlayer("\u00A79" + updateLine); sender.sendChatToPlayer(ChatMessageComponent.func_111066_d("\u00A79" + updateLine));
} }
} }
} }

View file

@ -25,12 +25,12 @@ public class TickHandlerCoreClient implements ITickHandler {
// if(!Config.disableVersionCheck) { // if(!Config.disableVersionCheck) {
if (Version.needsUpdateNoticeAndMarkAsSeen()) { if (Version.needsUpdateNoticeAndMarkAsSeen()) {
player.sendChatToPlayer(String.format("\u00A7cNew version of BuildCraft available: %s for Minecraft %s", Version.getRecommendedVersion(), player.addChatMessage(String.format("\u00A7cNew version of BuildCraft available: %s for Minecraft %s", Version.getRecommendedVersion(),
CoreProxy.proxy.getMinecraftVersion())); CoreProxy.proxy.getMinecraftVersion()));
for (String updateLine : Version.getChangelog()) { for (String updateLine : Version.getChangelog()) {
player.sendChatToPlayer("\u00A79" + updateLine); player.addChatMessage("\u00A79" + updateLine);
} }
player.sendChatToPlayer("\u00A7cThis message only displays once. Type '/buildcraft version' if you want to see it again."); player.addChatMessage("\u00A7cThis message only displays once. Type '/buildcraft version' if you want to see it again.");
} }
// } // }

View file

@ -21,9 +21,7 @@ public class InventoryIterator {
if (inv instanceof ISidedInventory) { if (inv instanceof ISidedInventory) {
return new InventoryIteratorSided((ISidedInventory) inv, side); return new InventoryIteratorSided((ISidedInventory) inv, side);
} }
if (inv instanceof net.minecraftforge.common.ISidedInventory) {
return new InventoryIteratorSided(InventoryWrapper.getWrappedInventory(inv), side);
}
return new InventoryIteratorSimple(inv); return new InventoryIteratorSimple(inv);
} }

View file

@ -33,8 +33,6 @@ public abstract class InventoryWrapper implements ISidedInventory {
public static ISidedInventory getWrappedInventory(Object inventory) { public static ISidedInventory getWrappedInventory(Object inventory) {
if(inventory instanceof ISidedInventory) if(inventory instanceof ISidedInventory)
return (ISidedInventory)inventory; return (ISidedInventory)inventory;
else if(inventory instanceof net.minecraftforge.common.ISidedInventory)
return new InventoryWrapperForge((net.minecraftforge.common.ISidedInventory)inventory);
else if(inventory instanceof IInventory) else if(inventory instanceof IInventory)
return new InventoryWrapperSimple(Utils.getInventory((IInventory)inventory)); return new InventoryWrapperSimple(Utils.getInventory((IInventory)inventory));
else else

View file

@ -1,35 +0,0 @@
package buildcraft.core.inventory;
import buildcraft.core.utils.Utils;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.ForgeDirection;
public class InventoryWrapperForge extends InventoryWrapper {
private int[][] sidemap;
public InventoryWrapperForge(net.minecraftforge.common.ISidedInventory inventory) {
super(inventory);
sidemap = new int[ForgeDirection.VALID_DIRECTIONS.length][];
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS) {
sidemap[direction.ordinal()] = Utils.createSlotArray(inventory.getStartInventorySide(direction), inventory.getSizeInventorySide(direction));
}
}
@Override
public int[] getAccessibleSlotsFromSide(int side) {
return sidemap[side];
}
@Override
public boolean canInsertItem(int slotIndex, ItemStack itemstack, int side) {
return true;
}
@Override
public boolean canExtractItem(int slotIndex, ItemStack itemstack, int side) {
return true;
}
}

View file

@ -24,8 +24,6 @@ public abstract class Transactor implements ITransactor {
return new TransactorSpecial((ISpecialInventory) object); return new TransactorSpecial((ISpecialInventory) object);
else if (object instanceof ISidedInventory) else if (object instanceof ISidedInventory)
return new TransactorSimple((ISidedInventory) object); return new TransactorSimple((ISidedInventory) object);
else if (object instanceof net.minecraftforge.common.ISidedInventory)
return new TransactorSimple(InventoryWrapper.getWrappedInventory(object));
else if (object instanceof IInventory) else if (object instanceof IInventory)
return new TransactorSimple(Utils.getInventory((IInventory) object)); return new TransactorSimple(Utils.getInventory((IInventory) object));