Cleanup network item onOpen methods

This commit is contained in:
raoulvdberge
2017-07-18 19:16:55 +02:00
parent a25fdad5bd
commit a926ca0803
7 changed files with 20 additions and 28 deletions

View File

@@ -3,7 +3,6 @@ package com.raoulvdberge.refinedstorage.api.network.item;
import com.raoulvdberge.refinedstorage.api.network.INetwork;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
/**
* Represents a network item (an item that is connected to the network somehow).
@@ -19,13 +18,12 @@ public interface INetworkItem {
/**
* Called when the network item is opened.
*
* @param network the network
* @param player the player
* @param controllerWorld the world where the controller is in
* @param hand the hand
* @param network the network
* @param player the player
* @param hand the hand
* @return true if the network item can be opened, false otherwise
*/
boolean onOpen(INetwork network, EntityPlayer player, World controllerWorld, EnumHand hand);
boolean onOpen(INetwork network, EntityPlayer player, EnumHand hand);
void onAction(NetworkItemAction action);
}

View File

@@ -2,7 +2,6 @@ package com.raoulvdberge.refinedstorage.api.network.item;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumHand;
import net.minecraft.world.World;
import javax.annotation.Nullable;
@@ -19,11 +18,10 @@ public interface INetworkItemHandler {
/**
* Called when a player opens a network item.
*
* @param player the player that opened the network item
* @param controllerWorld the world of the controller
* @param hand the hand the player opened it with
* @param player the player that opened the network item
* @param hand the hand the player opened it with
*/
void onOpen(EntityPlayer player, World controllerWorld, EnumHand hand);
void onOpen(EntityPlayer player, EnumHand hand);
/**
* Called when the player closes a network item.

View File

@@ -9,7 +9,6 @@ import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.EnumHand;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
import java.util.ArrayList;
import java.util.Iterator;
@@ -32,7 +31,7 @@ public class NetworkItemHandler implements INetworkItemHandler {
}
@Override
public void onOpen(EntityPlayer player, World controllerWorld, EnumHand hand) {
public void onOpen(EntityPlayer player, EnumHand hand) {
boolean inRange = false;
for (INetworkNode node : network.getNodeGraph().all()) {
@@ -57,7 +56,7 @@ public class NetworkItemHandler implements INetworkItemHandler {
INetworkItem item = ((INetworkItemProvider) player.getHeldItem(hand).getItem()).provide(this, player, player.getHeldItem(hand));
if (item.onOpen(network, player, controllerWorld, hand)) {
if (item.onOpen(network, player, hand)) {
items.add(item);
}
}

View File

@@ -13,7 +13,6 @@ 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;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
@@ -34,7 +33,7 @@ public class NetworkItemWirelessCraftingMonitor implements INetworkItem {
}
@Override
public boolean onOpen(INetwork network, EntityPlayer player, World controllerWorld, EnumHand hand) {
public boolean onOpen(INetwork network, EntityPlayer player, EnumHand hand) {
if (RS.INSTANCE.config.wirelessCraftingMonitorUsesEnergy && stack.getItemDamage() != ItemWirelessCraftingMonitor.TYPE_CREATIVE && stack.getCapability(CapabilityEnergy.ENERGY, null).getEnergyStored() <= RS.INSTANCE.config.wirelessCraftingMonitorOpenUsage) {
return false;
}
@@ -45,7 +44,7 @@ public class NetworkItemWirelessCraftingMonitor implements INetworkItem {
return false;
}
player.openGui(RS.INSTANCE, RSGui.WIRELESS_CRAFTING_MONITOR, player.getEntityWorld(), hand.ordinal(), controllerWorld.provider.getDimension(), 0);
player.openGui(RS.INSTANCE, RSGui.WIRELESS_CRAFTING_MONITOR, player.getEntityWorld(), hand.ordinal(), network.world().provider.getDimension(), 0);
network.sendCraftingMonitorUpdate((EntityPlayerMP) player);

View File

@@ -14,7 +14,6 @@ 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;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
@@ -35,7 +34,7 @@ public class NetworkItemWirelessFluidGrid implements INetworkItem {
}
@Override
public boolean onOpen(INetwork network, EntityPlayer player, World controllerWorld, EnumHand hand) {
public boolean onOpen(INetwork network, EntityPlayer player, EnumHand hand) {
if (RS.INSTANCE.config.wirelessFluidGridUsesEnergy && stack.getItemDamage() != ItemWirelessFluidGrid.TYPE_CREATIVE && stack.getCapability(CapabilityEnergy.ENERGY, null).getEnergyStored() <= RS.INSTANCE.config.wirelessFluidGridOpenUsage) {
return false;
}
@@ -46,7 +45,7 @@ public class NetworkItemWirelessFluidGrid implements INetworkItem {
return false;
}
API.instance().openWirelessGrid(player, hand, controllerWorld.provider.getDimension(), WirelessFluidGrid.ID);
API.instance().openWirelessGrid(player, hand, network.world().provider.getDimension(), WirelessFluidGrid.ID);
network.sendFluidStorageToClient((EntityPlayerMP) player);

View File

@@ -14,7 +14,6 @@ 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;
import net.minecraftforge.energy.CapabilityEnergy;
import net.minecraftforge.energy.IEnergyStorage;
@@ -35,7 +34,7 @@ public class NetworkItemWirelessGrid implements INetworkItem {
}
@Override
public boolean onOpen(INetwork network, EntityPlayer player, World controllerWorld, EnumHand hand) {
public boolean onOpen(INetwork network, EntityPlayer player, EnumHand hand) {
if (RS.INSTANCE.config.wirelessGridUsesEnergy && stack.getItemDamage() != ItemWirelessGrid.TYPE_CREATIVE && stack.getCapability(CapabilityEnergy.ENERGY, null).getEnergyStored() <= RS.INSTANCE.config.wirelessGridOpenUsage) {
return false;
}
@@ -46,7 +45,7 @@ public class NetworkItemWirelessGrid implements INetworkItem {
return false;
}
API.instance().openWirelessGrid(player, hand, controllerWorld.provider.getDimension(), WirelessGrid.ID);
API.instance().openWirelessGrid(player, hand, network.world().provider.getDimension(), WirelessGrid.ID);
network.sendItemStorageToClient((EntityPlayerMP) player);

View File

@@ -1,8 +1,8 @@
package com.raoulvdberge.refinedstorage.item;
import com.raoulvdberge.refinedstorage.RSBlocks;
import com.raoulvdberge.refinedstorage.api.network.INetwork;
import com.raoulvdberge.refinedstorage.api.network.item.INetworkItemProvider;
import com.raoulvdberge.refinedstorage.tile.TileController;
import net.minecraft.block.Block;
import net.minecraft.client.resources.I18n;
import net.minecraft.client.util.ITooltipFlag;
@@ -39,12 +39,12 @@ public abstract class ItemNetworkItem extends ItemEnergyItem implements INetwork
if (!isValid(stack)) {
player.sendMessage(new TextComponentTranslation("misc.refinedstorage:network_item.not_found"));
} else {
World controllerWorld = DimensionManager.getWorld(getDimensionId(stack));
World networkWorld = DimensionManager.getWorld(getDimensionId(stack));
TileEntity controller;
TileEntity network;
if (controllerWorld != null && ((controller = controllerWorld.getTileEntity(new BlockPos(getX(stack), getY(stack), getZ(stack)))) instanceof TileController)) {
((TileController) controller).getNetworkItemHandler().onOpen(player, controllerWorld, hand);
if (networkWorld != null && ((network = networkWorld.getTileEntity(new BlockPos(getX(stack), getY(stack), getZ(stack)))) instanceof INetwork)) {
((INetwork) network).getNetworkItemHandler().onOpen(player, hand);
} else {
player.sendMessage(new TextComponentTranslation("misc.refinedstorage:network_item.not_found"));
}