Lots of fixes
This commit is contained in:
@@ -1,13 +1,24 @@
|
||||
package appeng.hooks;
|
||||
|
||||
import alexiil.mc.lib.attributes.fluid.FluidAttributes;
|
||||
import alexiil.mc.lib.attributes.fluid.volume.FluidVolume;
|
||||
import appeng.client.render.DummyFluidBakedModel;
|
||||
import appeng.fluids.items.FluidDummyItem;
|
||||
import appeng.items.misc.EncodedPatternItem;
|
||||
import appeng.mixins.ItemRendererAccessor;
|
||||
import com.google.common.collect.ImmutableList;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.render.item.ItemRenderer;
|
||||
import net.minecraft.client.render.model.BakedModel;
|
||||
import net.minecraft.client.texture.Sprite;
|
||||
import net.minecraft.client.texture.SpriteAtlasTexture;
|
||||
import net.minecraft.client.util.SpriteIdentifier;
|
||||
import net.minecraft.client.util.math.AffineTransformation;
|
||||
import net.minecraft.client.world.ClientWorld;
|
||||
import net.minecraft.fluid.Fluids;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.Identifier;
|
||||
|
||||
public final class ItemRendererHooks {
|
||||
|
||||
@@ -22,7 +33,11 @@ public final class ItemRendererHooks {
|
||||
* if shift is held.
|
||||
*/
|
||||
public static boolean onRenderGuiItemModel(ItemRenderer renderer, ItemStack stack, int x, int y, BakedModel model) {
|
||||
if (stack.getItem() instanceof EncodedPatternItem && OVERRIDING_FOR.get() != stack) {
|
||||
if (OVERRIDING_FOR.get() == stack) {
|
||||
return false; // Don't allow recursive model replacements
|
||||
}
|
||||
|
||||
if (stack.getItem() instanceof EncodedPatternItem) {
|
||||
boolean shiftHeld = Screen.hasShiftDown();
|
||||
ClientWorld world = MinecraftClient.getInstance().world;
|
||||
if (shiftHeld && world != null) {
|
||||
@@ -31,18 +46,28 @@ public final class ItemRendererHooks {
|
||||
if (!output.isEmpty()) {
|
||||
BakedModel realModel = MinecraftClient.getInstance().getItemRenderer().getModels()
|
||||
.getModel(output);
|
||||
ItemRendererAccessor self = (ItemRendererAccessor) renderer;
|
||||
OVERRIDING_FOR.set(stack);
|
||||
try {
|
||||
self.callRenderGuiItemModel(stack, x, y, realModel);
|
||||
} finally {
|
||||
OVERRIDING_FOR.remove();
|
||||
}
|
||||
renderInstead(renderer, stack, x, y, realModel);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
} else if (stack.getItem() instanceof FluidDummyItem) {
|
||||
FluidDummyItem itemFacade = (FluidDummyItem) stack.getItem();
|
||||
FluidVolume fluidStack = itemFacade.getFluidStack(stack);
|
||||
renderInstead(renderer, stack, x, y, new DummyFluidBakedModel(fluidStack));
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private static void renderInstead(ItemRenderer renderer, ItemStack stack, int x, int y, BakedModel realModel) {
|
||||
ItemRendererAccessor self = (ItemRendererAccessor) renderer;
|
||||
OVERRIDING_FOR.set(stack);
|
||||
try {
|
||||
self.callRenderGuiItemModel(stack, x, y, realModel);
|
||||
} finally {
|
||||
OVERRIDING_FOR.remove();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,23 +18,7 @@
|
||||
|
||||
package appeng.hooks;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.core.AEConfig;
|
||||
import appeng.core.AELog;
|
||||
@@ -44,14 +28,32 @@ import appeng.me.Grid;
|
||||
import appeng.tile.AEBaseBlockEntity;
|
||||
import appeng.util.IWorldCallable;
|
||||
import appeng.util.Platform;
|
||||
import com.google.common.base.Stopwatch;
|
||||
import com.google.common.collect.LinkedListMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents;
|
||||
import net.fabricmc.fabric.api.event.lifecycle.v1.ServerTickEvents;
|
||||
import net.minecraft.server.MinecraftServer;
|
||||
import net.minecraft.server.world.ServerWorld;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldAccess;
|
||||
|
||||
import java.util.ArrayDeque;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Queue;
|
||||
import java.util.Set;
|
||||
import java.util.WeakHashMap;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
public class TickHandler {
|
||||
|
||||
private static final TickHandler INSTANCE = new TickHandler();
|
||||
private static TickHandler INSTANCE;
|
||||
private final Queue<IWorldCallable<?>> serverQueue = new ArrayDeque<>();
|
||||
private final Multimap<World, CraftingJob> craftingJobs = LinkedListMultimap.create();
|
||||
private final Map<WorldAccess, Queue<IWorldCallable<?>>> callQueue = new WeakHashMap<>();
|
||||
@@ -60,11 +62,16 @@ public class TickHandler {
|
||||
private final HashMap<Integer, PlayerColor> srvPlayerColors = new HashMap<>();
|
||||
|
||||
public TickHandler() {
|
||||
if (INSTANCE != null) {
|
||||
throw new IllegalStateException("There can only be a single tick handler.");
|
||||
}
|
||||
INSTANCE = this;
|
||||
|
||||
// Register for all the tick events we care about
|
||||
ServerTickEvents.END_SERVER_TICK.register(this::onAfterServerTick);
|
||||
ServerTickEvents.START_WORLD_TICK.register(this::onBeforeWorldTick);
|
||||
ServerTickEvents.END_WORLD_TICK.register(this::onAfterWorldTick);
|
||||
|
||||
ServerLifecycleEvents.SERVER_STOPPING.register(this::onServerStopping);
|
||||
}
|
||||
|
||||
public static TickHandler instance() {
|
||||
@@ -147,6 +154,27 @@ public class TickHandler {
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC }
|
||||
|
||||
/**
|
||||
* This is primarily useful for an integrated server being stopped, and can be fully replaced by the event
|
||||
* above once world unload events hit.
|
||||
*/
|
||||
private void onServerStopping(MinecraftServer server) {
|
||||
final List<IGridNode> toDestroy = new ArrayList<>();
|
||||
this.server.updateNetworks();
|
||||
for (final Grid g : this.server.networks) {
|
||||
for (final IGridNode n : g.getNodes()) {
|
||||
WorldAccess nodeWorld = n.getWorld();
|
||||
if (nodeWorld instanceof ServerWorld && ((ServerWorld) nodeWorld).getServer() == server) {
|
||||
toDestroy.add(n);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (final IGridNode n : toDestroy) {
|
||||
n.destroy();
|
||||
}
|
||||
}
|
||||
|
||||
private void onBeforeWorldTick(ServerWorld world) {
|
||||
final Queue<IWorldCallable<?>> queue = this.callQueue.get(world);
|
||||
this.processQueue(queue, world);
|
||||
|
||||
Reference in New Issue
Block a user