Add server to client config sync.
This commit is contained in:
@@ -43,7 +43,7 @@ public final class RS {
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent e) {
|
||||
config = new RSConfig(e.getSuggestedConfigurationFile());
|
||||
config = new RSConfig(null, e.getSuggestedConfigurationFile());
|
||||
|
||||
PROXY.preInit(e);
|
||||
}
|
||||
|
||||
@@ -7,12 +7,14 @@ import net.minecraftforge.fml.client.config.IConfigElement;
|
||||
import net.minecraftforge.fml.client.event.ConfigChangedEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.io.File;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public final class RSConfig {
|
||||
public class RSConfig {
|
||||
private Configuration config;
|
||||
private RSConfig originalClientVersion;
|
||||
|
||||
//region Energy
|
||||
public int controllerBaseUsage;
|
||||
@@ -119,18 +121,28 @@ public final class RSConfig {
|
||||
private static final String UPGRADES = "upgrades";
|
||||
//endregion
|
||||
|
||||
public RSConfig(File configFile) {
|
||||
config = new Configuration(configFile);
|
||||
public RSConfig(@Nullable RSConfig originalClientVersion, File configFile) {
|
||||
this(originalClientVersion, new Configuration(configFile));
|
||||
}
|
||||
|
||||
public RSConfig(@Nullable RSConfig originalClientVersion, Configuration config) {
|
||||
this.originalClientVersion = originalClientVersion;
|
||||
this.config = config;
|
||||
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
|
||||
loadConfig();
|
||||
this.loadConfig();
|
||||
}
|
||||
|
||||
public Configuration getConfig() {
|
||||
return config;
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public RSConfig getOriginalClientVersion() {
|
||||
return originalClientVersion;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onConfigChangedEvent(ConfigChangedEvent.OnConfigChangedEvent event) {
|
||||
if (event.getModID().equalsIgnoreCase(RS.ID)) {
|
||||
|
||||
@@ -109,7 +109,7 @@ public class NetworkNodeGraph implements INetworkNodeGraph {
|
||||
if (!controller.getPos().equals(otherControllerPos)) {
|
||||
IBlockState state = world.getBlockState(otherControllerPos);
|
||||
|
||||
ItemStack stackToSpawn = ItemBlockController.createStackWithNBT(new ItemStack(RSBlocks.CONTROLLER, 1, state.getBlock().getMetaFromState(state)));
|
||||
ItemStack stackToSpawn = ItemBlockController.createStack(new ItemStack(RSBlocks.CONTROLLER, 1, state.getBlock().getMetaFromState(state)));
|
||||
|
||||
world.setBlockToAir(otherControllerPos);
|
||||
|
||||
|
||||
@@ -34,7 +34,7 @@ public class BlockController extends BlockBase {
|
||||
@Override
|
||||
public void getSubBlocks(CreativeTabs tab, NonNullList<ItemStack> items) {
|
||||
for (int i = 0; i <= 1; i++) {
|
||||
items.add(ItemBlockController.createStackWithNBT(new ItemStack(this, 1, i)));
|
||||
items.add(ItemBlockController.createStack(new ItemStack(this, 1, i)));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -102,7 +102,6 @@ public class BlockController extends BlockBase {
|
||||
|
||||
stack.setTagCompound(new NBTTagCompound());
|
||||
stack.getTagCompound().setInteger(TileController.NBT_ENERGY, ((TileController) world.getTileEntity(pos)).getEnergy().getStored());
|
||||
stack.getTagCompound().setInteger(TileController.NBT_ENERGY_CAPACITY, ((TileController) world.getTileEntity(pos)).getEnergy().getCapacity());
|
||||
|
||||
drops.add(stack);
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ public class ItemBlockController extends ItemBlockBase {
|
||||
super.addInformation(stack, world, tooltip, flag);
|
||||
|
||||
if (stack.getMetadata() != ControllerType.CREATIVE.getId()) {
|
||||
tooltip.add(I18n.format("misc.refinedstorage:energy_stored", getEnergyStored(stack), getEnergyCapacity(stack)));
|
||||
tooltip.add(I18n.format("misc.refinedstorage:energy_stored", getEnergyStored(stack), RS.INSTANCE.config.controllerCapacity));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -32,18 +32,14 @@ public class ItemBlockController extends ItemBlockBase {
|
||||
return (stack.hasTagCompound() && stack.getTagCompound().hasKey(TileController.NBT_ENERGY)) ? stack.getTagCompound().getInteger(TileController.NBT_ENERGY) : 0;
|
||||
}
|
||||
|
||||
public static int getEnergyCapacity(ItemStack stack) {
|
||||
return (stack.hasTagCompound() && stack.getTagCompound().hasKey(TileController.NBT_ENERGY_CAPACITY)) ? stack.getTagCompound().getInteger(TileController.NBT_ENERGY_CAPACITY) : RS.INSTANCE.config.controllerCapacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCreated(ItemStack stack, World world, EntityPlayer player) {
|
||||
super.onCreated(stack, world, player);
|
||||
|
||||
createStackWithNBT(stack);
|
||||
createStack(stack);
|
||||
}
|
||||
|
||||
public static ItemStack createStackWithNBT(ItemStack stack) {
|
||||
public static ItemStack createStack(ItemStack stack) {
|
||||
NBTTagCompound tag = stack.getTagCompound();
|
||||
|
||||
if (tag == null) {
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.raoulvdberge.refinedstorage.network;
|
||||
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.RSConfig;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
|
||||
|
||||
public class MessageConfigSync implements IMessage, IMessageHandler<MessageConfigSync, IMessage> {
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
RSConfig serverVersion = new RSConfig(RS.INSTANCE.config, RS.INSTANCE.config.getConfig());
|
||||
|
||||
serverVersion.controllerCapacity = buf.readInt();
|
||||
|
||||
RS.INSTANCE.config = serverVersion;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeInt(RS.INSTANCE.config.controllerCapacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(MessageConfigSync message, MessageContext ctx) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -273,7 +273,7 @@ public class ProxyClient extends ProxyCommon {
|
||||
ModelLoader.setCustomStateMapper(RSBlocks.CRAFTER_MANAGER, new StateMapperCTM("refinedstorage:crafter_manager"));
|
||||
|
||||
ModelLoader.setCustomMeshDefinition(Item.getItemFromBlock(RSBlocks.CONTROLLER), stack -> {
|
||||
ControllerEnergyType energyType = stack.getItemDamage() == ControllerType.CREATIVE.getId() ? ControllerEnergyType.ON : TileController.getEnergyType(ItemBlockController.getEnergyStored(stack), ItemBlockController.getEnergyCapacity(stack));
|
||||
ControllerEnergyType energyType = stack.getItemDamage() == ControllerType.CREATIVE.getId() ? ControllerEnergyType.ON : TileController.getEnergyType(ItemBlockController.getEnergyStored(stack), RS.INSTANCE.config.controllerCapacity);
|
||||
|
||||
return new ModelResourceLocation("refinedstorage:controller" + (Loader.isModLoaded("ctm") ? "_glow" : ""), "energy_type=" + energyType);
|
||||
});
|
||||
|
||||
@@ -57,6 +57,7 @@ import net.minecraft.block.Block;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentData;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.inventory.Container;
|
||||
import net.minecraft.inventory.Slot;
|
||||
@@ -72,6 +73,7 @@ import net.minecraftforge.common.crafting.IIngredientFactory;
|
||||
import net.minecraftforge.common.crafting.JsonContext;
|
||||
import net.minecraftforge.event.RegistryEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerEvent;
|
||||
import net.minecraftforge.event.world.WorldEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
@@ -187,6 +189,7 @@ public class ProxyCommon {
|
||||
RS.INSTANCE.network.registerMessage(MessageWirelessCraftingMonitorSettings.class, MessageWirelessCraftingMonitorSettings.class, id++, Side.SERVER);
|
||||
RS.INSTANCE.network.registerMessage(MessageStorageDiskSizeRequest.class, MessageStorageDiskSizeRequest.class, id++, Side.SERVER);
|
||||
RS.INSTANCE.network.registerMessage(MessageStorageDiskSizeResponse.class, MessageStorageDiskSizeResponse.class, id++, Side.CLIENT);
|
||||
RS.INSTANCE.network.registerMessage(MessageConfigSync.class, MessageConfigSync.class, id++, Side.CLIENT);
|
||||
|
||||
NetworkRegistry.INSTANCE.registerGuiHandler(RS.INSTANCE, new GuiHandler());
|
||||
|
||||
@@ -335,6 +338,20 @@ public class ProxyCommon {
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLoginEvent(net.minecraftforge.fml.common.gameevent.PlayerEvent.PlayerLoggedInEvent e) {
|
||||
if (!e.player.world.isRemote) {
|
||||
RS.INSTANCE.network.sendTo(new MessageConfigSync(), (EntityPlayerMP) e.player);
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onPlayerLogoutEvent(WorldEvent.Unload e) {
|
||||
if (e.getWorld().isRemote && RS.INSTANCE.config.getOriginalClientVersion() != null) {
|
||||
RS.INSTANCE.config = RS.INSTANCE.config.getOriginalClientVersion();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void fixItemMappings(RegistryEvent.MissingMappings<Item> e) {
|
||||
OneSixMigrationHelper.removalHook();
|
||||
|
||||
@@ -110,7 +110,6 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
|
||||
private static final int THROTTLE_ACTIVE_TO_INACTIVE = 4;
|
||||
|
||||
public static final String NBT_ENERGY = "Energy";
|
||||
public static final String NBT_ENERGY_CAPACITY = "EnergyCapacity";
|
||||
public static final String NBT_ENERGY_TYPE = "EnergyType";
|
||||
|
||||
private static final String NBT_ITEM_STORAGE_TRACKER = "ItemStorageTracker";
|
||||
@@ -218,7 +217,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
|
||||
this.energy.setStored(0);
|
||||
}
|
||||
} else if (getType() == ControllerType.CREATIVE) {
|
||||
this.energy.setStored(this.energy.getCapacity());
|
||||
this.energy.setStored(this.energy.getCapacity());
|
||||
}
|
||||
|
||||
boolean canRun = canRun();
|
||||
@@ -602,7 +601,9 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
|
||||
@Override
|
||||
public int getEnergyUsage() {
|
||||
int usage = RS.INSTANCE.config.controllerBaseUsage;
|
||||
usage += nodeGraph.all().stream().mapToInt(x-> x.getEnergyUsage()).sum();
|
||||
|
||||
usage += nodeGraph.all().stream().mapToInt(INetworkNode::getEnergyUsage).sum();
|
||||
|
||||
return usage;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user