Added Funky Locomotion integration, fixes #1336
This commit is contained in:
@@ -38,6 +38,7 @@ public abstract class NetworkNode implements INetworkNode, INetworkNodeVisitor,
|
||||
|
||||
private EnumFacing direction;
|
||||
|
||||
private boolean throttlingDisabled;
|
||||
private boolean couldUpdate;
|
||||
private int ticksSinceUpdateChanged;
|
||||
|
||||
@@ -104,6 +105,10 @@ public abstract class NetworkNode implements INetworkNode, INetworkNodeVisitor,
|
||||
return 4;
|
||||
}
|
||||
|
||||
public void setThrottlingDisabled() {
|
||||
throttlingDisabled = true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
++ticks;
|
||||
@@ -113,9 +118,10 @@ public abstract class NetworkNode implements INetworkNode, INetworkNodeVisitor,
|
||||
if (couldUpdate != canUpdate) {
|
||||
++ticksSinceUpdateChanged;
|
||||
|
||||
if (canUpdate ? (ticksSinceUpdateChanged > getUpdateThrottleInactiveToActive()) : (ticksSinceUpdateChanged > getUpdateThrottleActiveToInactive())) {
|
||||
if ((canUpdate ? (ticksSinceUpdateChanged > getUpdateThrottleInactiveToActive()) : (ticksSinceUpdateChanged > getUpdateThrottleActiveToInactive())) || throttlingDisabled) {
|
||||
ticksSinceUpdateChanged = 0;
|
||||
couldUpdate = canUpdate;
|
||||
throttlingDisabled = false;
|
||||
|
||||
if (hasConnectivityState()) {
|
||||
WorldUtils.updateBlock(world, pos);
|
||||
|
||||
@@ -5,6 +5,8 @@ import com.google.gson.JsonSyntaxException;
|
||||
import com.raoulvdberge.refinedstorage.RS;
|
||||
import com.raoulvdberge.refinedstorage.RSBlocks;
|
||||
import com.raoulvdberge.refinedstorage.RSItems;
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNode;
|
||||
import com.raoulvdberge.refinedstorage.api.network.node.INetworkNodeManager;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.API;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.craftingmonitor.*;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.autocrafting.preview.CraftingPreviewElementFluidStack;
|
||||
@@ -20,6 +22,7 @@ import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriter
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.network.readerwriter.ReaderWriterHandlerRedstone;
|
||||
import com.raoulvdberge.refinedstorage.apiimpl.solderer.SoldererRecipeLoader;
|
||||
import com.raoulvdberge.refinedstorage.block.BlockBase;
|
||||
import com.raoulvdberge.refinedstorage.block.BlockNode;
|
||||
import com.raoulvdberge.refinedstorage.capability.CapabilityNetworkNodeProxy;
|
||||
import com.raoulvdberge.refinedstorage.gui.GuiHandler;
|
||||
import com.raoulvdberge.refinedstorage.integration.craftingtweaks.IntegrationCraftingTweaks;
|
||||
@@ -37,7 +40,10 @@ import com.raoulvdberge.refinedstorage.tile.grid.WirelessGrid;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.PortableGrid;
|
||||
import com.raoulvdberge.refinedstorage.tile.grid.portable.TilePortableGrid;
|
||||
import com.raoulvdberge.refinedstorage.util.StackUtils;
|
||||
import com.rwtema.funkylocomotion.api.FunkyRegistry;
|
||||
import com.rwtema.funkylocomotion.api.IMoveFactory;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentData;
|
||||
import net.minecraft.init.Items;
|
||||
@@ -45,8 +51,13 @@ import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemEnchantedBook;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.Ingredient;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.JsonUtils;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.crafting.CraftingHelper;
|
||||
import net.minecraftforge.common.crafting.IIngredientFactory;
|
||||
@@ -264,7 +275,62 @@ public class ProxyCommon {
|
||||
|
||||
@SubscribeEvent
|
||||
public void registerBlocks(RegistryEvent.Register<Block> e) {
|
||||
blocksToRegister.forEach(e.getRegistry()::register);
|
||||
blocksToRegister.forEach(b -> {
|
||||
if (b instanceof BlockNode && FunkyRegistry.INSTANCE != null) {
|
||||
FunkyRegistry.INSTANCE.registerMoveFactoryBlock(b, new IMoveFactory() {
|
||||
@Override
|
||||
public NBTTagCompound destroyBlock(World world, BlockPos pos) {
|
||||
INetworkNodeManager manager = API.instance().getNetworkNodeManager(world);
|
||||
|
||||
INetworkNode node = manager.getNode(pos);
|
||||
|
||||
TileNode tile = (TileNode) world.getTileEntity(pos);
|
||||
|
||||
NBTTagCompound tag = new NBTTagCompound();
|
||||
|
||||
tag.setInteger("Direction", tile.getDirection().ordinal());
|
||||
tag.setTag("Node", node.write(new NBTTagCompound()));
|
||||
tag.setString("NodeID", node.getId());
|
||||
|
||||
// Funky Locomotion requires this
|
||||
IBlockState state = world.getBlockState(pos);
|
||||
tag.setString("Block", Block.REGISTRY.getNameForObject(state.getBlock()).toString());
|
||||
tag.setInteger("Meta", state.getBlock().getMetaFromState(state));
|
||||
tag.setTag("Tile", tile.writeToNBT(new NBTTagCompound()));
|
||||
|
||||
manager.removeNode(pos); // Avoid inventory dropping
|
||||
manager.markForSaving();
|
||||
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
@SuppressWarnings("deprecation")
|
||||
public boolean recreateBlock(World world, BlockPos pos, NBTTagCompound tag) {
|
||||
NetworkNode node = (NetworkNode) API.instance().getNetworkNodeRegistry().get(tag.getString("NodeID")).create(tag.getCompoundTag("Node"), world, pos);
|
||||
node.setThrottlingDisabled();
|
||||
|
||||
INetworkNodeManager manager = API.instance().getNetworkNodeManager(world);
|
||||
|
||||
manager.setNode(pos, node);
|
||||
manager.markForSaving();
|
||||
|
||||
Block block = Block.REGISTRY.getObject(new ResourceLocation(tag.getString("Block")));
|
||||
world.setBlockState(pos, block.getStateFromMeta(tag.getInteger("Meta")));
|
||||
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
if (tile instanceof TileNode) {
|
||||
((TileNode) tile).setDirection(EnumFacing.getFront(tag.getInteger("Direction")));
|
||||
tile.markDirty();
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
e.getRegistry().register(b);
|
||||
});
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
|
||||
@@ -149,6 +149,7 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
|
||||
|
||||
private EnergyForge energy = new EnergyForge(RS.INSTANCE.config.controllerCapacity);
|
||||
|
||||
private boolean throttlingDisabled = true; // Will be enabled after first update
|
||||
private boolean couldRun;
|
||||
private int ticksSinceUpdateChanged;
|
||||
|
||||
@@ -236,9 +237,10 @@ public class TileController extends TileBase implements ITickable, INetwork, IRe
|
||||
if (couldRun != canRun) {
|
||||
++ticksSinceUpdateChanged;
|
||||
|
||||
if (canRun ? (ticksSinceUpdateChanged > THROTTLE_INACTIVE_TO_ACTIVE) : (ticksSinceUpdateChanged > THROTTLE_ACTIVE_TO_INACTIVE)) {
|
||||
if ((canRun ? (ticksSinceUpdateChanged > THROTTLE_INACTIVE_TO_ACTIVE) : (ticksSinceUpdateChanged > THROTTLE_ACTIVE_TO_INACTIVE)) || throttlingDisabled) {
|
||||
ticksSinceUpdateChanged = 0;
|
||||
couldRun = canRun;
|
||||
throttlingDisabled = false;
|
||||
|
||||
nodeGraph.rebuild();
|
||||
securityManager.rebuild();
|
||||
|
||||
@@ -0,0 +1,19 @@
|
||||
package com.rwtema.funkylocomotion.api;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraftforge.common.capabilities.Capability;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
public abstract class FunkyRegistry {
|
||||
@Nullable
|
||||
public static FunkyRegistry INSTANCE = null;
|
||||
|
||||
public abstract void registerMoveFactoryBlock(Block b, IMoveFactory factory);
|
||||
|
||||
public abstract void registerMoveFactoryTileEntityClass(Class<?> tile, IMoveFactory factory);
|
||||
|
||||
public abstract void registerMoveFactoryBlockClass(Class<? extends Block> b, IMoveFactory factory);
|
||||
|
||||
public abstract <T> void registerProxy(Object object, Capability<T> capability, T type);
|
||||
}
|
||||
@@ -0,0 +1,11 @@
|
||||
package com.rwtema.funkylocomotion.api;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IMoveFactory {
|
||||
NBTTagCompound destroyBlock(World world, BlockPos pos);
|
||||
|
||||
boolean recreateBlock(World world, BlockPos pos, NBTTagCompound tag);
|
||||
}
|
||||
@@ -0,0 +1,4 @@
|
||||
@API(apiVersion = "2.0", owner = "funkylocomotion", provides = "funkylocomotion_api")
|
||||
package com.rwtema.funkylocomotion.api;
|
||||
|
||||
import net.minecraftforge.fml.common.API;
|
||||
Reference in New Issue
Block a user