Wireless Crafting Monitor done!

This commit is contained in:
Raoul Van den Berge
2016-11-04 14:22:29 +01:00
parent bb0818ef18
commit 284f4ed653
22 changed files with 232 additions and 14 deletions

View File

@@ -64,6 +64,13 @@ public final class RSConfig {
public int wirelessGridInsertUsage;
//endregion
//region Wireless Crafting Monitor
public boolean wirelessCraftingMonitorUsesEnergy;
public int wirelessCraftingMonitorOpenUsage;
public int wirelessCraftingMonitorCancelUsage;
public int wirelessCraftingMonitorCancelAllUsage;
//endregion
//region Upgrades
public int rangeUpgradeUsage;
public int speedUpgradeUsage;
@@ -79,6 +86,7 @@ public final class RSConfig {
private static final String CONTROLLER = "controller";
private static final String WIRELESS_TRANSMITTER = "wirelessTransmitter";
private static final String WIRELESS_GRID = "wirelessGrid";
private static final String WIRELESS_CRAFTING_MONITOR = "wirelessCraftingMonitor";
private static final String UPGRADES = "upgrades";
private static final String MISC = "misc";
//endregion
@@ -153,6 +161,13 @@ public final class RSConfig {
wirelessGridExtractUsage = config.getInt("extract", WIRELESS_GRID, 3, 0, Integer.MAX_VALUE, "The energy used by the Wireless Grid to extract items");
//endregion
//region Wireless Grid
wirelessCraftingMonitorUsesEnergy = config.getBoolean("usesEnergy", WIRELESS_CRAFTING_MONITOR, true, "Whether the Wireless Crafting Monitor uses energy");
wirelessCraftingMonitorOpenUsage = config.getInt("open", WIRELESS_CRAFTING_MONITOR, 35, 0, Integer.MAX_VALUE, "The energy used by the Wireless Crafting Monitor to open");
wirelessCraftingMonitorCancelUsage = config.getInt("cancel", WIRELESS_CRAFTING_MONITOR, 4, 0, Integer.MAX_VALUE, "The energy used by the Wireless Crafting Monitor to cancel a task");
wirelessCraftingMonitorCancelAllUsage = config.getInt("cancelAll", WIRELESS_CRAFTING_MONITOR, 5, 0, Integer.MAX_VALUE, "The energy used by the Wireless Crafting Monitor to cancel all tasks");
//endregion
//region Upgrades
rangeUpgradeUsage = config.getInt("range", UPGRADES, 8, 0, Integer.MAX_VALUE, "The additional energy used per Range Upgrade");
speedUpgradeUsage = config.getInt("speed", UPGRADES, 2, 0, Integer.MAX_VALUE, "The additional energy used per Speed Upgrade");

View File

@@ -24,4 +24,5 @@ public final class RSGui {
public static final int EXTERNAL_STORAGE = 20;
public static final int FLUID_STORAGE = 21;
public static final int DISK_MANIPULATOR = 22;
public static final int WIRELESS_CRAFTING_MONITOR = 23;
}

View File

@@ -18,4 +18,5 @@ public final class RSItems {
public static final ItemFluidStorageDisk FLUID_STORAGE_DISK = new ItemFluidStorageDisk();
public static final ItemFluidStoragePart FLUID_STORAGE_PART = new ItemFluidStoragePart();
public static final ItemWrench WRENCH = new ItemWrench();
public static final ItemWirelessCraftingMonitor WIRELESS_CRAFTING_MONITOR = new ItemWirelessCraftingMonitor();
}

View File

@@ -60,7 +60,8 @@ public interface IItemGridHandler {
/**
* Called when a player wants to cancel a crafting task.
*
* @param id the task id, or -1 to cancel all tasks
* @param player the player that requested the cance
* @param id the task id, or -1 to cancel all tasks
*/
void onCraftingCancelRequested(int id);
void onCraftingCancelRequested(EntityPlayerMP player, int id);
}

View File

@@ -7,6 +7,7 @@ import com.raoulvdberge.refinedstorage.api.network.grid.IItemGridHandler;
import com.raoulvdberge.refinedstorage.api.network.item.INetworkItem;
import com.raoulvdberge.refinedstorage.apiimpl.API;
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.task.CraftingTask;
import com.raoulvdberge.refinedstorage.apiimpl.network.item.NetworkItemWirelessCraftingMonitor;
import com.raoulvdberge.refinedstorage.apiimpl.network.item.NetworkItemWirelessGrid;
import com.raoulvdberge.refinedstorage.network.MessageGridCraftingPreviewResponse;
import net.minecraft.entity.player.EntityPlayerMP;
@@ -169,7 +170,7 @@ public class ItemGridHandler implements IItemGridHandler {
}
@Override
public void onCraftingCancelRequested(int id) {
public void onCraftingCancelRequested(EntityPlayerMP player, int id) {
if (id >= 0 && id < network.getCraftingTasks().size()) {
network.cancelCraftingTask(network.getCraftingTasks().get(id));
} else if (id == -1) {
@@ -177,5 +178,11 @@ public class ItemGridHandler implements IItemGridHandler {
network.cancelCraftingTask(task);
}
}
INetworkItem networkItem = network.getNetworkItemHandler().getItem(player);
if (networkItem != null && networkItem instanceof NetworkItemWirelessCraftingMonitor) {
((NetworkItemWirelessCraftingMonitor) networkItem).drainEnergy(id == -1 ? RS.INSTANCE.config.wirelessCraftingMonitorCancelAllUsage : RS.INSTANCE.config.wirelessCraftingMonitorCancelUsage);
}
}
}

View File

@@ -60,10 +60,10 @@ public class NetworkItemHandler implements INetworkItemHandler {
if (item.onOpen(network, player, controllerWorld, hand)) {
items.add(item);
return false;
return true;
}
return true;
return false;
}
@Override

View File

@@ -0,0 +1,61 @@
package com.raoulvdberge.refinedstorage.apiimpl.network.item;
import com.raoulvdberge.refinedstorage.RS;
import com.raoulvdberge.refinedstorage.RSGui;
import com.raoulvdberge.refinedstorage.RSItems;
import com.raoulvdberge.refinedstorage.api.network.INetworkMaster;
import com.raoulvdberge.refinedstorage.api.network.item.INetworkItem;
import com.raoulvdberge.refinedstorage.api.network.item.INetworkItemHandler;
import com.raoulvdberge.refinedstorage.item.ItemWirelessCraftingMonitor;
import com.raoulvdberge.refinedstorage.item.ItemWirelessGrid;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
public class NetworkItemWirelessCraftingMonitor implements INetworkItem {
private INetworkItemHandler handler;
private EntityPlayer player;
private ItemStack stack;
public NetworkItemWirelessCraftingMonitor(INetworkItemHandler handler, EntityPlayer player, ItemStack stack) {
this.handler = handler;
this.player = player;
this.stack = stack;
}
@Override
public EntityPlayer getPlayer() {
return player;
}
@Override
public boolean onOpen(INetworkMaster network, EntityPlayer player, World controllerWorld, EnumHand hand) {
if (RS.INSTANCE.config.wirelessCraftingMonitorUsesEnergy && stack.getItemDamage() != ItemWirelessCraftingMonitor.TYPE_CREATIVE && RSItems.WIRELESS_CRAFTING_MONITOR.getEnergyStored(stack) <= RS.INSTANCE.config.wirelessCraftingMonitorOpenUsage) {
return false;
}
player.openGui(RS.INSTANCE, RSGui.WIRELESS_CRAFTING_MONITOR, player.worldObj, hand.ordinal(), controllerWorld.provider.getDimension(), 0);
network.sendCraftingMonitorUpdate((EntityPlayerMP) player);
drainEnergy(RS.INSTANCE.config.wirelessCraftingMonitorOpenUsage);
return true;
}
public void drainEnergy(int energy) {
if (RS.INSTANCE.config.wirelessCraftingMonitorUsesEnergy && stack.getItemDamage() != ItemWirelessCraftingMonitor.TYPE_CREATIVE) {
ItemWirelessGrid item = RSItems.WIRELESS_GRID;
item.extractEnergy(stack, energy, false);
if (item.getEnergyStored(stack) <= 0) {
handler.onClose(player);
player.closeScreen();
}
}
}
}

View File

@@ -5,6 +5,7 @@ import com.raoulvdberge.refinedstorage.container.*;
import com.raoulvdberge.refinedstorage.gui.grid.GuiGrid;
import com.raoulvdberge.refinedstorage.tile.*;
import com.raoulvdberge.refinedstorage.tile.craftingmonitor.TileCraftingMonitor;
import com.raoulvdberge.refinedstorage.tile.craftingmonitor.WirelessCraftingMonitor;
import com.raoulvdberge.refinedstorage.tile.externalstorage.TileExternalStorage;
import com.raoulvdberge.refinedstorage.tile.grid.TileGrid;
import com.raoulvdberge.refinedstorage.tile.grid.WirelessGrid;
@@ -72,6 +73,8 @@ public class GuiHandler implements IGuiHandler {
return getWirelessGridContainer(player, x, y);
} else if (ID == RSGui.GRID_FILTER) {
return getGridFilterContainer(player, x);
} else if (ID == RSGui.WIRELESS_CRAFTING_MONITOR) {
return getWirelessCraftingMonitorContainer(player, x, y);
}
return getContainer(ID, player, world.getTileEntity(new BlockPos(x, y, z)));
@@ -128,6 +131,8 @@ public class GuiHandler implements IGuiHandler {
return new GuiStorage((ContainerFluidStorage) getContainer(ID, player, tile), (TileFluidStorage) tile);
case RSGui.DISK_MANIPULATOR:
return new GuiDiskManipulator((ContainerDiskManipulator) getContainer(ID, player, tile));
case RSGui.WIRELESS_CRAFTING_MONITOR:
return getWirelessCraftingMonitorGui(player, x, y);
default:
return null;
}
@@ -147,6 +152,20 @@ public class GuiHandler implements IGuiHandler {
return new ContainerGrid(getWirelessGrid(player, hand, controllerDimension), player);
}
private WirelessCraftingMonitor getWirelessCraftingMonitor(EntityPlayer player, int hand, int controllerDimension) {
return new WirelessCraftingMonitor(controllerDimension, player.getHeldItem(EnumHand.values()[hand]));
}
private GuiCraftingMonitor getWirelessCraftingMonitorGui(EntityPlayer player, int hand, int controllerDimension) {
WirelessCraftingMonitor craftingMonitor = getWirelessCraftingMonitor(player, hand, controllerDimension);
return new GuiCraftingMonitor(new ContainerCraftingMonitor(craftingMonitor, player));
}
private ContainerCraftingMonitor getWirelessCraftingMonitorContainer(EntityPlayer player, int hand, int controllerDimension) {
return new ContainerCraftingMonitor(getWirelessCraftingMonitor(player, hand, controllerDimension), player);
}
private ContainerGridFilter getGridFilterContainer(EntityPlayer player, int hand) {
return new ContainerGridFilter(player, player.getHeldItem(EnumHand.values()[hand]));
}

View File

@@ -0,0 +1,18 @@
package com.raoulvdberge.refinedstorage.item;
import com.raoulvdberge.refinedstorage.api.network.item.INetworkItem;
import com.raoulvdberge.refinedstorage.api.network.item.INetworkItemHandler;
import com.raoulvdberge.refinedstorage.apiimpl.network.item.NetworkItemWirelessCraftingMonitor;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public class ItemWirelessCraftingMonitor extends ItemNetworkItem {
public ItemWirelessCraftingMonitor() {
super("wireless_crafting_monitor");
}
@Override
public INetworkItem provide(INetworkItemHandler handler, EntityPlayer player, ItemStack stack) {
return new NetworkItemWirelessCraftingMonitor(handler, player, stack);
}
}

View File

@@ -28,7 +28,7 @@ public class MessageCraftingMonitorCancel extends MessageHandlerPlayerToServer<M
@Override
public void handle(MessageCraftingMonitorCancel message, EntityPlayerMP player) {
if (player.openContainer instanceof ContainerCraftingMonitor) {
((ContainerCraftingMonitor) player.openContainer).getCraftingMonitor().onCancelled(message.id);
((ContainerCraftingMonitor) player.openContainer).getCraftingMonitor().onCancelled(player, message.id);
}
}
}

View File

@@ -150,6 +150,7 @@ public class ProxyClient extends ProxyCommon {
ModelLoader.setCustomModelResourceLocation(RSItems.CORE, ItemCore.TYPE_DESTRUCTION, new ModelResourceLocation("refinedstorage:destruction_core", "inventory"));
ModelLoader.setCustomModelResourceLocation(RSItems.WIRELESS_GRID, 0, new ModelResourceLocation("refinedstorage:wireless_grid", "inventory"));
ModelLoader.setCustomModelResourceLocation(RSItems.WIRELESS_CRAFTING_MONITOR, 0, new ModelResourceLocation("refinedstorage:wireless_crafting_monitor", "inventory"));
ModelLoader.setCustomModelResourceLocation(RSItems.PATTERN, 0, new ModelResourceLocation("refinedstorage:pattern", "inventory"));
ModelLoader.setCustomModelResourceLocation(RSItems.STORAGE_HOUSING, 0, new ModelResourceLocation("refinedstorage:storage_housing", "inventory"));
ModelLoader.setCustomModelResourceLocation(RSItems.GRID_FILTER, 0, new ModelResourceLocation("refinedstorage:grid_filter", "inventory"));

View File

@@ -166,6 +166,7 @@ public class ProxyCommon {
registerItem(RSItems.GRID_FILTER);
registerItem(RSItems.NETWORK_CARD);
registerItem(RSItems.WRENCH);
registerItem(RSItems.WIRELESS_CRAFTING_MONITOR);
OreDictionary.registerOre("itemSilicon", RSItems.SILICON);
@@ -309,11 +310,23 @@ public class ProxyCommon {
// Wireless Grid
GameRegistry.addRecipe(new ItemStack(RSItems.WIRELESS_GRID, 1, ItemWirelessGrid.TYPE_NORMAL),
"EPE",
"EGE",
"EAE",
"EEE",
'E', new ItemStack(RSItems.QUARTZ_ENRICHED_IRON),
'P', new ItemStack(Items.ENDER_PEARL),
'A', new ItemStack(RSItems.PROCESSOR, 1, ItemProcessor.TYPE_ADVANCED),
'E', new ItemStack(RSItems.QUARTZ_ENRICHED_IRON)
'G', new ItemStack(RSBlocks.GRID, 1, EnumGridType.NORMAL.getId()),
'A', new ItemStack(RSItems.PROCESSOR, 1, ItemProcessor.TYPE_ADVANCED)
);
// Wireless Crafting Monitor
GameRegistry.addRecipe(new ItemStack(RSItems.WIRELESS_CRAFTING_MONITOR, 1, ItemWirelessCraftingMonitor.TYPE_NORMAL),
"EPE",
"EME",
"EAE",
'E', new ItemStack(RSItems.QUARTZ_ENRICHED_IRON),
'P', new ItemStack(Items.ENDER_PEARL),
'M', new ItemStack(RSBlocks.CRAFTING_MONITOR),
'A', new ItemStack(RSItems.PROCESSOR, 1, ItemProcessor.TYPE_ADVANCED)
);
// Crafter

View File

@@ -329,7 +329,7 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
@Override
public void sendCraftingMonitorUpdate() {
List<ICraftingMonitorElement> elements = craftingTasks.stream().flatMap(t -> t.getCraftingMonitorElements().stream()).collect(Collectors.toList());
List<ICraftingMonitorElement> elements = getElements();
worldObj.getMinecraftServer().getPlayerList().getPlayerList().stream()
.filter(player -> player.openContainer instanceof ContainerCraftingMonitor)
@@ -338,7 +338,11 @@ public class TileController extends TileBase implements INetworkMaster, IEnergyR
@Override
public void sendCraftingMonitorUpdate(EntityPlayerMP player) {
RS.INSTANCE.network.sendTo(new MessageCraftingMonitorElements(craftingTasks.stream().flatMap(t -> t.getCraftingMonitorElements().stream()).collect(Collectors.toList())), player);
RS.INSTANCE.network.sendTo(new MessageCraftingMonitorElements(getElements()), player);
}
private List<ICraftingMonitorElement> getElements() {
return craftingTasks.stream().flatMap(t -> t.getCraftingMonitorElements().stream()).collect(Collectors.toList());
}
@Override

View File

@@ -1,5 +1,7 @@
package com.raoulvdberge.refinedstorage.tile.craftingmonitor;
import net.minecraft.entity.player.EntityPlayerMP;
public interface ICraftingMonitor {
void onCancelled(int id);
void onCancelled(EntityPlayerMP player, int id);
}

View File

@@ -21,9 +21,9 @@ public class TileCraftingMonitor extends TileNode implements ICraftingMonitor {
}
@Override
public void onCancelled(int id) {
public void onCancelled(EntityPlayerMP player, int id) {
if (isConnected()) {
network.getItemGridHandler().onCraftingCancelRequested(id);
network.getItemGridHandler().onCraftingCancelRequested(player, id);
}
}

View File

@@ -0,0 +1,41 @@
package com.raoulvdberge.refinedstorage.tile.craftingmonitor;
import com.raoulvdberge.refinedstorage.item.ItemWirelessCraftingMonitor;
import com.raoulvdberge.refinedstorage.tile.TileController;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.common.DimensionManager;
public class WirelessCraftingMonitor implements ICraftingMonitor {
private int controllerDimension;
private BlockPos controller;
public WirelessCraftingMonitor(int controllerDimension, ItemStack stack) {
this.controllerDimension = controllerDimension;
this.controller = new BlockPos(ItemWirelessCraftingMonitor.getX(stack), ItemWirelessCraftingMonitor.getY(stack), ItemWirelessCraftingMonitor.getZ(stack));
}
@Override
public void onCancelled(EntityPlayerMP player, int id) {
TileController controller = getController();
if (controller != null) {
controller.getItemGridHandler().onCraftingCancelRequested(player, id);
}
}
private TileController getController() {
World world = DimensionManager.getWorld(controllerDimension);
if (world != null) {
TileEntity tile = world.getTileEntity(controller);
return tile instanceof TileController ? (TileController) tile : null;
}
return null;
}
}

View File

@@ -194,6 +194,8 @@ item.refinedstorage:fluid_storage_disk.4.name=Creative Fluid Storage Disk
item.refinedstorage:fluid_storage_disk.5.name=Debug Fluid Storage Disk
item.refinedstorage:wireless_grid.0.name=Wireless Grid
item.refinedstorage:wireless_grid.1.name=Creative Wireless Grid
item.refinedstorage:wireless_crafting_monitor.0.name=Wireless Crafting Monitor
item.refinedstorage:wireless_crafting_monitor.1.name=Creative Wireless Crafting Monitor
item.refinedstorage:quartz_enriched_iron.name=Quartz Enriched Iron
item.refinedstorage:core.0.name=Construction Core
item.refinedstorage:core.1.name=Destruction Core

View File

@@ -0,0 +1,20 @@
{
"parent": "item/generated",
"textures": {
"layer0": "refinedstorage:items/wireless_crafting_monitor_disconnected"
},
"overrides": [
{
"predicate": {
"connected": 0
},
"model": "refinedstorage:item/wireless_crafting_monitor_disconnected"
},
{
"predicate": {
"connected": 1
},
"model": "refinedstorage:item/wireless_crafting_monitor_connected"
}
]
}

View File

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

View File

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

Binary file not shown.

After

Width:  |  Height:  |  Size: 230 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 218 B