Moved more parts of ME over

This commit is contained in:
Sebastian Hartte
2020-07-01 01:04:53 +02:00
parent 529d03fa9e
commit 007c7ceb56
61 changed files with 322 additions and 264 deletions
+18 -14
View File
@@ -23,19 +23,16 @@
package appeng.api.parts; package appeng.api.parts;
import java.io.IOException;
import java.util.List;
import java.util.Random;
import javax.annotation.Nonnull;
import alexiil.mc.lib.attributes.AttributeList; import alexiil.mc.lib.attributes.AttributeList;
import appeng.api.networking.IGridNode;
import appeng.api.util.AECableType;
import appeng.api.util.AEColor;
import appeng.api.util.AEPartLocation;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.render.VertexConsumerProvider; import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
@@ -43,15 +40,16 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.crash.CrashReportSection;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.Vec3d;
import net.minecraft.world.BlockView; import net.minecraft.world.BlockView;
import net.minecraft.world.World; import net.minecraft.world.World;
import appeng.api.networking.IGridNode; import javax.annotation.Nonnull;
import appeng.api.util.AECableType; import java.io.IOException;
import appeng.api.util.AEColor; import java.util.List;
import appeng.api.util.AEPartLocation; import java.util.Random;
public interface IPart extends ICustomCableConnection { public interface IPart extends ICustomCableConnection {
@@ -343,8 +341,6 @@ public interface IPart extends ICustomCableConnection {
* side. * side.
* *
* @see alexiil.mc.lib.attributes.AttributeProvider * @see alexiil.mc.lib.attributes.AttributeProvider
*
* @return The capability or null.
*/ */
default void addAllAttributes(AttributeList<?> to) {} default void addAllAttributes(AttributeList<?> to) {}
@@ -355,4 +351,12 @@ public interface IPart extends ICustomCableConnection {
*/ */
void getBoxes(final IPartCollisionHelper bch); void getBoxes(final IPartCollisionHelper bch);
/**
* This will be used by the core to add information about this part to a crash
* report if it is attached to a host that caused a crash during tick processing.
* @param section The crash report section the information will be added to.
*/
default void addEntityCrashInfo(CrashReportSection section) {
}
} }
@@ -8,9 +8,13 @@ import appeng.client.render.effects.*;
import appeng.client.render.tesr.SkyChestTESR; import appeng.client.render.tesr.SkyChestTESR;
import appeng.core.Api; import appeng.core.Api;
import appeng.core.ApiDefinitions; import appeng.core.ApiDefinitions;
import appeng.core.AppEng;
import appeng.core.AppEngBase; import appeng.core.AppEngBase;
import appeng.core.sync.network.ClientNetworkHandler; import appeng.core.sync.network.ClientNetworkHandler;
import appeng.entity.*; import appeng.entity.*;
import appeng.hooks.ClientTickHandler;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry; import net.fabricmc.fabric.api.client.particle.v1.ParticleFactoryRegistry;
import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry; import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry;
import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback; import net.fabricmc.fabric.api.event.client.ClientSpriteRegistryCallback;
@@ -34,17 +38,25 @@ import java.util.Random;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import java.util.stream.Stream; import java.util.stream.Stream;
@Environment(EnvType.CLIENT)
public final class AppEngClient extends AppEngBase { public final class AppEngClient extends AppEngBase {
private final MinecraftClient client; private final MinecraftClient client;
private final ClientNetworkHandler networkHandler; private final ClientNetworkHandler networkHandler;
private final ClientTickHandler tickHandler;
public static AppEngClient instance() {
return (AppEngClient) AppEng.instance();
}
public AppEngClient() { public AppEngClient() {
super(); super();
client = MinecraftClient.getInstance(); client = MinecraftClient.getInstance();
networkHandler = new ClientNetworkHandler(); networkHandler = new ClientNetworkHandler();
tickHandler = new ClientTickHandler();
ModelsReloadCallback.EVENT.register(this::onModelsReloaded); ModelsReloadCallback.EVENT.register(this::onModelsReloaded);
@@ -94,9 +106,21 @@ public final class AppEngClient extends AppEngBase {
return null; return null;
} }
@Override
public void triggerUpdates() { public void triggerUpdates() {
if (client.player == null || client.world == null) {
return;
}
final PlayerEntity player = client.player;
final int x = (int) player.getX();
final int y = (int) player.getY();
final int z = (int) player.getZ();
final int range = 16 * 16;
client.worldRenderer.scheduleBlockRenders(x - range, y - range, z - range, x + range, y + range,
z + range);
} }
@Override @Override
@@ -18,23 +18,19 @@
package appeng.container; package appeng.container;
import appeng.api.util.AEPartLocation;
import com.google.common.base.Preconditions; import com.google.common.base.Preconditions;
import io.netty.handler.codec.DecoderException; import io.netty.handler.codec.DecoderException;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext; import net.minecraft.item.ItemUsageContext;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.math.Direction;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import appeng.api.parts.IPartHost; import net.minecraft.world.World;
import appeng.api.util.AEPartLocation;
import appeng.api.util.DimensionalCoord;
import appeng.parts.AEBasePart;
/** /**
* Describes how a container the player has opened was originally located. This * Describes how a container the player has opened was originally located. This
@@ -62,14 +58,18 @@ public final class ContainerLocator {
private final Type type; private final Type type;
private final int itemIndex; private final int itemIndex;
private final int dimensionId; private final Identifier worldId;
private final BlockPos blockPos; private final BlockPos blockPos;
private final AEPartLocation side; private final AEPartLocation side;
private ContainerLocator(Type type, int itemIndex, int dimensionId, BlockPos blockPos, AEPartLocation side) { private ContainerLocator(Type type, int itemIndex, World world, BlockPos blockPos, AEPartLocation side) {
this(type, itemIndex, world.getRegistryKey().getValue(), blockPos, side);
}
private ContainerLocator(Type type, int itemIndex, Identifier worldId, BlockPos blockPos, AEPartLocation side) {
this.type = type; this.type = type;
this.itemIndex = itemIndex; this.itemIndex = itemIndex;
this.dimensionId = dimensionId; this.worldId = worldId;
this.blockPos = blockPos; this.blockPos = blockPos;
this.side = side; this.side = side;
} }
@@ -78,16 +78,14 @@ public final class ContainerLocator {
if (te.getWorld() == null) { if (te.getWorld() == null) {
throw new IllegalArgumentException("Cannot open a block entity that is not in a world"); throw new IllegalArgumentException("Cannot open a block entity that is not in a world");
} }
int dimensionId = te.getWorld().getDimension().getType().getId(); return new ContainerLocator(Type.BLOCK, -1, te.getWorld(), te.getPos(), null);
return new ContainerLocator(Type.BLOCK, -1, dimensionId, te.getPos(), null);
} }
public static ContainerLocator forTileEntitySide(BlockEntity te, Direction side) { public static ContainerLocator forTileEntitySide(BlockEntity te, Direction side) {
if (te.getWorld() == null) { if (te.getWorld() == null) {
throw new IllegalArgumentException("Cannot open a block entity that is not in a world"); throw new IllegalArgumentException("Cannot open a block entity that is not in a world");
} }
int dimensionId = te.getWorld().getDimension().getType().getId(); return new ContainerLocator(Type.PART, -1, te.getWorld(), te.getPos(), AEPartLocation.fromFacing(side));
return new ContainerLocator(Type.PART, -1, dimensionId, te.getPos(), AEPartLocation.fromFacing(side));
} }
/** /**
@@ -100,16 +98,15 @@ public final class ContainerLocator {
if (player == null) { if (player == null) {
throw new IllegalArgumentException("Cannot open a container without a player"); throw new IllegalArgumentException("Cannot open a container without a player");
} }
int dimensionId = player.world.getDimension().getType().getId();
int slot = getPlayerInventorySlotFromHand(player, context.getHand()); int slot = getPlayerInventorySlotFromHand(player, context.getHand());
AEPartLocation side = AEPartLocation.fromFacing(context.getFace()); AEPartLocation side = AEPartLocation.fromFacing(context.getSide());
return new ContainerLocator(Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT, slot, dimensionId, context.getBlockPos(), return new ContainerLocator(Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT, slot, player.world, context.getBlockPos(),
side); side);
} }
public static ContainerLocator forHand(PlayerEntity player, Hand hand) { public static ContainerLocator forHand(PlayerEntity player, Hand hand) {
int slot = getPlayerInventorySlotFromHand(player, hand); int slot = getPlayerInventorySlotFromHand(player, hand);
return new ContainerLocator(Type.PLAYER_INVENTORY, slot, -1, null, null); return new ContainerLocator(Type.PLAYER_INVENTORY, slot, (Identifier) null, null, null);
} }
private static int getPlayerInventorySlotFromHand(PlayerEntity player, Hand hand) { private static int getPlayerInventorySlotFromHand(PlayerEntity player, Hand hand) {
@@ -126,12 +123,12 @@ public final class ContainerLocator {
throw new IllegalArgumentException("Could not find item held in hand " + hand + " in player inventory"); throw new IllegalArgumentException("Could not find item held in hand " + hand + " in player inventory");
} }
public static ContainerLocator forPart(AEBasePart part) { // FIXME FABRIC public static ContainerLocator forPart(AEBasePart part) {
IPartHost host = part.getHost(); // FIXME FABRIC IPartHost host = part.getHost();
DimensionalCoord pos = host.getLocation(); // FIXME FABRIC DimensionalCoord pos = host.getLocation();
return new ContainerLocator(Type.PART, -1, pos.getWorld().getDimension().getType().getId(), pos.getBlockPos(), // FIXME FABRIC return new ContainerLocator(Type.PART, -1, pos.getWorld().getDimension().getType().getId(), pos.getBlockPos(),
part.getSide()); // FIXME FABRIC part.getSide());
} // FIXME FABRIC }
public boolean hasItemIndex() { public boolean hasItemIndex() {
return type == Type.PLAYER_INVENTORY || type == Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT; return type == Type.PLAYER_INVENTORY || type == Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT;
@@ -142,8 +139,8 @@ public final class ContainerLocator {
return itemIndex; return itemIndex;
} }
public int getDimensionId() { public Identifier getWorldId() {
return dimensionId; return worldId;
} }
public boolean hasBlockPos() { public boolean hasBlockPos() {
@@ -173,18 +170,18 @@ public final class ContainerLocator {
case PLAYER_INVENTORY_WITH_BLOCK_CONTEXT: case PLAYER_INVENTORY_WITH_BLOCK_CONTEXT:
buf.writeByte(1); buf.writeByte(1);
buf.writeInt(itemIndex); buf.writeInt(itemIndex);
buf.writeInt(dimensionId); buf.writeIdentifier(worldId);
buf.writeBlockPos(blockPos); buf.writeBlockPos(blockPos);
buf.writeByte(side.ordinal()); buf.writeByte(side.ordinal());
break; break;
case BLOCK: case BLOCK:
buf.writeByte(2); buf.writeByte(2);
buf.writeInt(dimensionId); buf.writeIdentifier(worldId);
buf.writeBlockPos(blockPos); buf.writeBlockPos(blockPos);
break; break;
case PART: case PART:
buf.writeByte(3); buf.writeByte(3);
buf.writeInt(dimensionId); buf.writeIdentifier(worldId);
buf.writeBlockPos(blockPos); buf.writeBlockPos(blockPos);
buf.writeByte(side.ordinal()); buf.writeByte(side.ordinal());
break; break;
@@ -197,14 +194,14 @@ public final class ContainerLocator {
byte type = buf.readByte(); byte type = buf.readByte();
switch (type) { switch (type) {
case 0: case 0:
return new ContainerLocator(Type.PLAYER_INVENTORY, buf.readInt(), -1, null, null); return new ContainerLocator(Type.PLAYER_INVENTORY, buf.readInt(), (Identifier) null, null, null);
case 1: case 1:
return new ContainerLocator(Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT, buf.readInt(), buf.readInt(), return new ContainerLocator(Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT, buf.readInt(), buf.readIdentifier(),
buf.readBlockPos(), AEPartLocation.values()[buf.readByte()]); buf.readBlockPos(), AEPartLocation.values()[buf.readByte()]);
case 2: case 2:
return new ContainerLocator(Type.BLOCK, -1, buf.readInt(), buf.readBlockPos(), null); return new ContainerLocator(Type.BLOCK, -1, buf.readIdentifier(), buf.readBlockPos(), null);
case 3: case 3:
return new ContainerLocator(Type.PART, -1, buf.readInt(), buf.readBlockPos(), return new ContainerLocator(Type.PART, -1, buf.readIdentifier(), buf.readBlockPos(),
AEPartLocation.values()[buf.readByte()]); AEPartLocation.values()[buf.readByte()]);
default: default:
throw new DecoderException("ContainerLocator type out of range: " + type); throw new DecoderException("ContainerLocator type out of range: " + type);
@@ -219,7 +216,7 @@ public final class ContainerLocator {
result.append("slot=").append(itemIndex).append(','); result.append("slot=").append(itemIndex).append(',');
} }
if (hasBlockPos()) { if (hasBlockPos()) {
result.append("dim=").append(dimensionId).append(','); result.append("dim=").append(worldId).append(',');
result.append("pos=").append(blockPos).append(','); result.append("pos=").append(blockPos).append(',');
} }
if (hasSide()) { if (hasSide()) {
+3 -2
View File
@@ -22,6 +22,7 @@ import appeng.api.parts.CableRenderMode;
import appeng.block.AEBaseBlock; import appeng.block.AEBaseBlock;
import appeng.client.ActionKey; import appeng.client.ActionKey;
import appeng.client.EffectType; import appeng.client.EffectType;
import appeng.core.stats.AdvancementTriggers;
import appeng.core.sync.BasePacket; import appeng.core.sync.BasePacket;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.InputUtil;
@@ -50,6 +51,8 @@ public interface AppEng {
return new Identifier(MOD_ID, id); return new Identifier(MOD_ID, id);
} }
AdvancementTriggers getAdvancementTriggers();
Stream<? extends PlayerEntity> getPlayers(); Stream<? extends PlayerEntity> getPlayers();
void sendToAllNearExcept(PlayerEntity p, double x, double y, double z, double dist, World w, void sendToAllNearExcept(PlayerEntity p, double x, double y, double z, double dist, World w,
@@ -66,8 +69,6 @@ public interface AppEng {
CableRenderMode getRenderMode(); CableRenderMode getRenderMode();
void triggerUpdates();
void updateRenderMode(PlayerEntity player); void updateRenderMode(PlayerEntity player);
boolean isActionKey(@Nonnull final ActionKey key, InputUtil.Key input); boolean isActionKey(@Nonnull final ActionKey key, InputUtil.Key input);
@@ -12,6 +12,7 @@ import appeng.core.stats.AeStats;
import appeng.core.sync.BasePacket; import appeng.core.sync.BasePacket;
import appeng.core.sync.network.NetworkHandler; import appeng.core.sync.network.NetworkHandler;
import appeng.core.sync.network.TargetPoint; import appeng.core.sync.network.TargetPoint;
import appeng.hooks.TickHandler;
import appeng.hooks.ToolItemHook; import appeng.hooks.ToolItemHook;
import appeng.mixins.CriteriaRegisterMixin; import appeng.mixins.CriteriaRegisterMixin;
import appeng.recipes.handlers.*; import appeng.recipes.handlers.*;
@@ -112,6 +113,11 @@ public abstract class AppEngBase implements AppEng {
// FIXME FABRIC FacadeRecipe.getSerializer(facadeItem)); // FIXME FABRIC FacadeRecipe.getSerializer(facadeItem));
} }
@Override
public AdvancementTriggers getAdvancementTriggers() {
return advancementTriggers;
}
@Override @Override
public void sendToAllNearExcept(final PlayerEntity p, final double x, final double y, final double z, public void sendToAllNearExcept(final PlayerEntity p, final double x, final double y, final double z,
final double dist, final World w, final BasePacket packet) { final double dist, final World w, final BasePacket packet) {
@@ -0,0 +1,8 @@
package appeng.crafting;
// FIXME FABRIC DUMMY
public class CraftingJob {
public boolean simulateFor(int simTime) {
return false;
}
}
@@ -18,20 +18,17 @@
package appeng.entity; package appeng.entity;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.TntMinecartEntityRenderer;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.block.Blocks;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.render.block.BlockRenderManager;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.util.Identifier;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.block.Blocks;
import net.minecraft.client.render.VertexConsumerProvider;
import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.client.render.entity.TntMinecartEntityRenderer;
import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.client.util.math.Vector3f;
import net.minecraft.util.Identifier;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class TinyTNTPrimedRenderer extends EntityRenderer<TinyTNTPrimedEntity> { public class TinyTNTPrimedRenderer extends EntityRenderer<TinyTNTPrimedEntity> {
@@ -44,7 +41,6 @@ public class TinyTNTPrimedRenderer extends EntityRenderer<TinyTNTPrimedEntity> {
@Override @Override
public void render(TinyTNTPrimedEntity tnt, float entityYaw, float partialTicks, MatrixStack mStack, public void render(TinyTNTPrimedEntity tnt, float entityYaw, float partialTicks, MatrixStack mStack,
VertexConsumerProvider buffers, int packedLight) { VertexConsumerProvider buffers, int packedLight) {
final BlockRenderManager blockrendererdispatcher = MinecraftClient.getInstance().getBlockRenderManager();
mStack.push(); mStack.push();
mStack.translate(0, 0.25F, 0); mStack.translate(0, 0.25F, 0);
float f2; float f2;
@@ -67,7 +63,6 @@ public class TinyTNTPrimedRenderer extends EntityRenderer<TinyTNTPrimedEntity> {
} }
mStack.scale(0.5f, 0.5f, 0.5f); mStack.scale(0.5f, 0.5f, 0.5f);
f2 = (1.0F - (tnt.getFuse() - partialTicks + 1.0F) / 100.0F) * 0.8F;
mStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(-90.0F)); mStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(-90.0F));
mStack.translate(-0.5D, -0.5D, 0.5D); mStack.translate(-0.5D, -0.5D, 0.5D);
mStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(90.0F)); mStack.multiply(Vector3f.POSITIVE_Y.getDegreesQuaternion(90.0F));
@@ -0,0 +1,41 @@
package appeng.hooks;
import appeng.api.AEApi;
import appeng.api.parts.CableRenderMode;
import appeng.client.AppEngClient;
import appeng.util.Platform;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
import net.minecraft.client.MinecraftClient;
import java.util.HashMap;
@Environment(EnvType.CLIENT)
public class ClientTickHandler extends TickHandler {
private final HashMap<Integer, PlayerColor> cliPlayerColors = new HashMap<>();
private CableRenderMode crm = CableRenderMode.STANDARD;
public ClientTickHandler() {
ClientTickEvents.START_CLIENT_TICK.register(this::onBeforeClientTick);
}
@Override
public HashMap<Integer, PlayerColor> getPlayerColors() {
if (!Platform.isServer()) {
return this.cliPlayerColors;
}
return super.getPlayerColors();
}
private void onBeforeClientTick(MinecraftClient client) {
this.tickColors(this.cliPlayerColors);
final CableRenderMode currentMode = AEApi.instance().partHelper().getCableRenderMode();
if (currentMode != this.crm) {
this.crm = currentMode;
AppEngClient.instance().triggerUpdates();
}
}
}
@@ -18,43 +18,26 @@
package appeng.hooks; package appeng.hooks;
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.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.WorldAccess;
import net.minecraft.world.World;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.TickEvent.Phase;
import net.minecraftforge.event.TickEvent.Type;
import net.minecraftforge.event.TickEvent.WorldTickEvent;
import net.minecraftforge.event.world.WorldEvent;
import appeng.api.AEApi;
import appeng.api.networking.IGridNode;
import appeng.api.parts.CableRenderMode;
import appeng.api.util.AEColor; import appeng.api.util.AEColor;
import appeng.core.AEConfig; import appeng.core.AEConfig;
import appeng.core.AELog; import appeng.core.AELog;
import appeng.core.AppEng;
import appeng.core.sync.packets.PaintedEntityPacket; import appeng.core.sync.packets.PaintedEntityPacket;
import appeng.crafting.CraftingJob; import appeng.crafting.CraftingJob;
import appeng.me.Grid; import appeng.me.Grid;
import appeng.tile.AEBaseBlockEntity; import appeng.tile.AEBaseBlockEntity;
import appeng.util.IWorldCallable; import appeng.util.IWorldCallable;
import appeng.util.Platform; 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.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.*;
import java.util.concurrent.TimeUnit;
public class TickHandler { public class TickHandler {
@@ -64,15 +47,18 @@ public class TickHandler {
private final WeakHashMap<WorldAccess, Queue<IWorldCallable<?>>> callQueue = new WeakHashMap<>(); private final WeakHashMap<WorldAccess, Queue<IWorldCallable<?>>> callQueue = new WeakHashMap<>();
private final HandlerRep server = new HandlerRep(); private final HandlerRep server = new HandlerRep();
private final HandlerRep client = new HandlerRep(); private final HandlerRep client = new HandlerRep();
private final HashMap<Integer, PlayerColor> cliPlayerColors = new HashMap<>();
private final HashMap<Integer, PlayerColor> srvPlayerColors = new HashMap<>(); private final HashMap<Integer, PlayerColor> srvPlayerColors = new HashMap<>();
private CableRenderMode crm = CableRenderMode.STANDARD;
public TickHandler() {
// 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);
}
public HashMap<Integer, PlayerColor> getPlayerColors() { public HashMap<Integer, PlayerColor> getPlayerColors() {
if (Platform.isServer()) { return this.srvPlayerColors;
return this.srvPlayerColors;
}
return this.cliPlayerColors;
} }
public void addCallable(final WorldAccess w, final IWorldCallable<?> c) { public void addCallable(final WorldAccess w, final IWorldCallable<?> c) {
@@ -126,86 +112,71 @@ public class TickHandler {
this.getRepo().clear(); this.getRepo().clear();
} }
public void unloadWorld(final WorldEvent.Unload ev) { // FIXME FABRIC It does not look like worlds can ever unload in Fabric.
if (Platform.isServer()) // for no there is no reason to care about this on the client... // FIXME FABRIC public void unloadWorld(final WorldEvent.Unload ev) {
{ // FIXME FABRIC if (Platform.isServer()) // for no there is no reason to care about this on the client...
final List<IGridNode> toDestroy = new ArrayList<>(); // FIXME FABRIC {
// FIXME FABRIC final List<IGridNode> toDestroy = new ArrayList<>();
// FIXME FABRIC
// FIXME FABRIC this.getRepo().updateNetworks();
// FIXME FABRIC for (final Grid g : this.getRepo().networks) {
// FIXME FABRIC for (final IGridNode n : g.getNodes()) {
// FIXME FABRIC if (n.getWorld() == ev.getWorld()) {
// FIXME FABRIC toDestroy.add(n);
// FIXME FABRIC }
// FIXME FABRIC }
// FIXME FABRIC }
// FIXME FABRIC
// FIXME FABRIC for (final IGridNode n : toDestroy) {
// FIXME FABRIC n.destroy();
// FIXME FABRIC }
// FIXME FABRIC }
// FIXME FABRIC }
this.getRepo().updateNetworks(); private void onBeforeWorldTick(ServerWorld world) {
for (final Grid g : this.getRepo().networks) { final Queue<IWorldCallable<?>> queue = this.callQueue.get(world);
for (final IGridNode n : g.getNodes()) { this.processQueue(queue, world);
if (n.getWorld() == ev.getWorld()) {
toDestroy.add(n);
}
}
}
for (final IGridNode n : toDestroy) {
n.destroy();
}
}
} }
public void onTick(final TickEvent ev) { private void onAfterWorldTick(ServerWorld world) {
synchronized (this.craftingJobs) {
if (ev.type == Type.CLIENT && ev.phase == Phase.START) { final Collection<CraftingJob> jobSet = this.craftingJobs.get(world);
this.tickColors(this.cliPlayerColors); if (!jobSet.isEmpty()) {
final CableRenderMode currentMode = AEApi.instance().partHelper().getCableRenderMode(); final int simTime = Math.max(1,
if (currentMode != this.crm) { AEConfig.instance().getCraftingCalculationTimePerTick() / jobSet.size());
this.crm = currentMode; final Iterator<CraftingJob> i = jobSet.iterator();
AppEng.proxy.triggerUpdates(); while (i.hasNext()) {
} final CraftingJob cj = i.next();
} if (!cj.simulateFor(simTime)) {
i.remove();
if (ev.type == Type.WORLD && ev.phase == Phase.END) {
final WorldTickEvent wte = (WorldTickEvent) ev;
synchronized (this.craftingJobs) {
final Collection<CraftingJob> jobSet = this.craftingJobs.get(wte.world);
if (!jobSet.isEmpty()) {
final int simTime = Math.max(1,
AEConfig.instance().getCraftingCalculationTimePerTick() / jobSet.size());
final Iterator<CraftingJob> i = jobSet.iterator();
while (i.hasNext()) {
final CraftingJob cj = i.next();
if (!cj.simulateFor(simTime)) {
i.remove();
}
} }
} }
} }
} }
// for no there is no reason to care about this on the client...
else if (ev.type == Type.SERVER && ev.phase == Phase.END) {
this.tickColors(this.srvPlayerColors);
// ready tiles.
final HandlerRep repo = this.getRepo();
while (!repo.tiles.isEmpty()) {
final AEBaseBlockEntity bt = repo.tiles.poll();
if (!bt.isRemoved()) {
bt.onReady();
}
}
// tick networks.
this.getRepo().updateNetworks();
for (final Grid g : this.getRepo().networks) {
g.update();
}
// cross world queue.
this.processQueue(this.serverQueue, null);
}
// world synced queue(s)
if (ev.type == Type.WORLD && ev.phase == Phase.START) {
final World world = ((WorldTickEvent) ev).world;
final Queue<IWorldCallable<?>> queue = this.callQueue.get(world);
this.processQueue(queue, world);
}
} }
private void tickColors(final HashMap<Integer, PlayerColor> playerSet) { private void onAfterServerTick(MinecraftServer server) {
this.tickColors(this.srvPlayerColors);
// ready tiles.
final HandlerRep repo = this.getRepo();
while (!repo.tiles.isEmpty()) {
final AEBaseBlockEntity bt = repo.tiles.poll();
if (!bt.isRemoved()) {
bt.onReady();
}
}
// tick networks.
this.getRepo().updateNetworks();
for (final Grid g : this.getRepo().networks) {
g.update();
}
// cross world queue.
this.processQueue(this.serverQueue, null);
}
protected void tickColors(final HashMap<Integer, PlayerColor> playerSet) {
final Iterator<PlayerColor> i = playerSet.values().iterator(); final Iterator<PlayerColor> i = playerSet.values().iterator();
while (i.hasNext()) { while (i.hasNext()) {
final PlayerColor pc = i.next(); final PlayerColor pc = i.next();
@@ -18,6 +18,7 @@
package appeng.items.tools.quartz; package appeng.items.tools.quartz;
import appeng.container.ContainerLocator;
import appeng.mixins.RemainderSetter; import appeng.mixins.RemainderSetter;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
@@ -47,7 +48,7 @@ public class QuartzCuttingKnifeItem extends AEBaseItem implements IGuiItem {
@Override @Override
public TypedActionResult<ItemStack> use(final World w, final PlayerEntity p, final Hand hand) { public TypedActionResult<ItemStack> use(final World w, final PlayerEntity p, final Hand hand) {
if (Platform.isServer()) { if (Platform.isServer()) {
// FIXME FABRIC ContainerOpener.openContainer(QuartzKnifeContainer.TYPE, p, ContainerLocator.forHand(p, hand)); // FIXME FABRIC ContainerOpener.openContainer(QuartzKnifeContainer.TYPE, p, ContainerLocator.forHand(p, hand));
throw new IllegalStateException(); throw new IllegalStateException();
} }
p.swingHand(hand); p.swingHand(hand);
@@ -20,6 +20,7 @@ package appeng.me.cache.helpers;
import javax.annotation.Nonnull; import javax.annotation.Nonnull;
import appeng.api.parts.IPart;
import net.minecraft.util.crash.CrashReportSection; import net.minecraft.util.crash.CrashReportSection;
import appeng.api.networking.IGridNode; import appeng.api.networking.IGridNode;
@@ -27,8 +28,6 @@ import appeng.api.networking.ticking.IGridTickable;
import appeng.api.networking.ticking.TickingRequest; import appeng.api.networking.ticking.TickingRequest;
import appeng.api.util.DimensionalCoord; import appeng.api.util.DimensionalCoord;
import appeng.me.cache.TickManagerCache; import appeng.me.cache.TickManagerCache;
import appeng.parts.AEBasePart;
import net.minecraft.util.crash.CrashReportSection;
public class TickTracker implements Comparable<TickTracker> { public class TickTracker implements Comparable<TickTracker> {
@@ -73,8 +72,8 @@ public class TickTracker implements Comparable<TickTracker> {
} }
public void addEntityCrashInfo(final CrashReportSection section) { public void addEntityCrashInfo(final CrashReportSection section) {
if (this.getGridTickable() instanceof AEBasePart) { if (this.getGridTickable() instanceof IPart) {
final AEBasePart part = (AEBasePart) this.getGridTickable(); final IPart part = (IPart) this.getGridTickable();
part.addEntityCrashInfo(section); part.addEntityCrashInfo(section);
} }
@@ -6,6 +6,7 @@ import appeng.client.ActionKey;
import appeng.client.EffectType; import appeng.client.EffectType;
import appeng.core.AppEngBase; import appeng.core.AppEngBase;
import appeng.core.sync.network.ServerNetworkHandler; import appeng.core.sync.network.ServerNetworkHandler;
import appeng.hooks.TickHandler;
import net.fabricmc.fabric.api.server.PlayerStream; import net.fabricmc.fabric.api.server.PlayerStream;
import net.minecraft.block.entity.BlockEntity; import net.minecraft.block.entity.BlockEntity;
import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.InputUtil;
@@ -25,9 +26,12 @@ public final class AppEngServer extends AppEngBase {
private final ServerNetworkHandler networkHandler; private final ServerNetworkHandler networkHandler;
private final TickHandler tickHandler;
public AppEngServer(MinecraftServer server) { public AppEngServer(MinecraftServer server) {
this.server = server; this.server = server;
this.networkHandler = new ServerNetworkHandler(); this.networkHandler = new ServerNetworkHandler();
this.tickHandler = new TickHandler();
} }
@Override @Override
@@ -60,11 +64,6 @@ public final class AppEngServer extends AppEngBase {
return null; return null;
} }
@Override
public void triggerUpdates() {
}
@Override @Override
public void updateRenderMode(PlayerEntity player) { public void updateRenderMode(PlayerEntity player) {
@@ -0,0 +1,34 @@
package appeng.tile.networking;
import appeng.api.networking.IGridHost;
import appeng.api.networking.IGridNode;
import appeng.api.util.AECableType;
import appeng.api.util.AEPartLocation;
import net.minecraft.util.math.BlockPos;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
// FIXME FABRIC DUMMY
public class ControllerBlockEntity implements IGridHost {
@Nullable
@Override
public IGridNode getGridNode(@Nonnull AEPartLocation dir) {
return null;
}
@Nonnull
@Override
public AECableType getCableConnectionType(@Nonnull AEPartLocation dir) {
return null;
}
@Override
public void securityBreak() {
}
public BlockPos getPos() {
return null;
}
}
+59 -57
View File
@@ -48,6 +48,8 @@ import appeng.core.AEConfig;
import appeng.core.AELog; import appeng.core.AELog;
import appeng.core.stats.AeStats; import appeng.core.stats.AeStats;
import appeng.fluids.util.AEFluidStack; import appeng.fluids.util.AEFluidStack;
import appeng.me.GridAccessException;
import appeng.me.GridNode;
import appeng.util.helpers.ItemComparisonHelper; import appeng.util.helpers.ItemComparisonHelper;
import appeng.util.helpers.P2PHelper; import appeng.util.helpers.P2PHelper;
import appeng.util.item.AEItemStack; import appeng.util.item.AEItemStack;
@@ -882,43 +884,43 @@ public class Platform {
} }
} }
// FIXME FABRIC public static boolean securityCheck(final GridNode a, final GridNode b) { public static boolean securityCheck(final GridNode a, final GridNode b) {
// FIXME FABRIC if (a.getLastSecurityKey() == -1 && b.getLastSecurityKey() == -1) { if (a.getLastSecurityKey() == -1 && b.getLastSecurityKey() == -1) {
// FIXME FABRIC return true; return true;
// FIXME FABRIC } else if (a.getLastSecurityKey() == b.getLastSecurityKey()) { } else if (a.getLastSecurityKey() == b.getLastSecurityKey()) {
// FIXME FABRIC return true; return true;
// FIXME FABRIC } }
// FIXME FABRIC
// FIXME FABRIC final boolean a_isSecure = isPowered(a.getGrid()) && a.getLastSecurityKey() != -1; final boolean a_isSecure = isPowered(a.getGrid()) && a.getLastSecurityKey() != -1;
// FIXME FABRIC final boolean b_isSecure = isPowered(b.getGrid()) && b.getLastSecurityKey() != -1; final boolean b_isSecure = isPowered(b.getGrid()) && b.getLastSecurityKey() != -1;
// FIXME FABRIC
// FIXME FABRIC if (AEConfig.instance().isFeatureEnabled(AEFeature.LOG_SECURITY_AUDITS)) { if (AEConfig.instance().isFeatureEnabled(AEFeature.LOG_SECURITY_AUDITS)) {
// FIXME FABRIC final String locationA = a.getGridBlock().isWorldAccessible() ? a.getGridBlock().getLocation().toString() final String locationA = a.getGridBlock().isWorldAccessible() ? a.getGridBlock().getLocation().toString()
// FIXME FABRIC : "notInWorld"; : "notInWorld";
// FIXME FABRIC final String locationB = b.getGridBlock().isWorldAccessible() ? b.getGridBlock().getLocation().toString() final String locationB = b.getGridBlock().isWorldAccessible() ? b.getGridBlock().getLocation().toString()
// FIXME FABRIC : "notInWorld"; : "notInWorld";
// FIXME FABRIC
// FIXME FABRIC AELog.info( AELog.info(
// FIXME FABRIC "Audit: Node A [isSecure=%b, key=%d, playerID=%d, location={%s}] vs Node B[isSecure=%b, key=%d, playerID=%d, location={%s}]", "Audit: Node A [isSecure=%b, key=%d, playerID=%d, location={%s}] vs Node B[isSecure=%b, key=%d, playerID=%d, location={%s}]",
// FIXME FABRIC a_isSecure, a.getLastSecurityKey(), a.getPlayerID(), locationA, b_isSecure, b.getLastSecurityKey(), a_isSecure, a.getLastSecurityKey(), a.getPlayerID(), locationA, b_isSecure, b.getLastSecurityKey(),
// FIXME FABRIC b.getPlayerID(), locationB); b.getPlayerID(), locationB);
// FIXME FABRIC } }
// FIXME FABRIC
// FIXME FABRIC // can't do that son... // can't do that son...
// FIXME FABRIC if (a_isSecure && b_isSecure) { if (a_isSecure && b_isSecure) {
// FIXME FABRIC return false; return false;
// FIXME FABRIC } }
// FIXME FABRIC
// FIXME FABRIC if (!a_isSecure && b_isSecure) { if (!a_isSecure && b_isSecure) {
// FIXME FABRIC return checkPlayerPermissions(b.getGrid(), a.getPlayerID()); return checkPlayerPermissions(b.getGrid(), a.getPlayerID());
// FIXME FABRIC } }
// FIXME FABRIC
// FIXME FABRIC if (a_isSecure && !b_isSecure) { if (a_isSecure && !b_isSecure) {
// FIXME FABRIC return checkPlayerPermissions(a.getGrid(), b.getPlayerID()); return checkPlayerPermissions(a.getGrid(), b.getPlayerID());
// FIXME FABRIC } }
// FIXME FABRIC
// FIXME FABRIC return true; return true;
// FIXME FABRIC } }
private static boolean isPowered(final IGrid grid) { private static boolean isPowered(final IGrid grid) {
if (grid == null) { if (grid == null) {
@@ -980,26 +982,26 @@ public class Platform {
yaw, pitch); yaw, pitch);
} }
// FIXME FABRIC public static boolean canAccess(final AENetworkProxy gridProxy, final IActionSource src) { // FIXME public static boolean canAccess(final AENetworkProxy gridProxy, final IActionSource src) {
// FIXME FABRIC try { // FIXME try {
// FIXME FABRIC if (src.player().isPresent()) { // FIXME if (src.player().isPresent()) {
// FIXME FABRIC return gridProxy.getSecurity().hasPermission(src.player().get(), SecurityPermissions.BUILD); // FIXME return gridProxy.getSecurity().hasPermission(src.player().get(), SecurityPermissions.BUILD);
// FIXME FABRIC } else if (src.machine().isPresent()) { // FIXME } else if (src.machine().isPresent()) {
// FIXME FABRIC final IActionHost te = src.machine().get(); // FIXME final IActionHost te = src.machine().get();
// FIXME FABRIC final IGridNode n = te.getActionableNode(); // FIXME final IGridNode n = te.getActionableNode();
// FIXME FABRIC if (n == null) { // FIXME if (n == null) {
// FIXME FABRIC return false; // FIXME return false;
// FIXME FABRIC } // FIXME }
// FIXME FABRIC // FIXME
// FIXME FABRIC final int playerID = n.getPlayerID(); // FIXME final int playerID = n.getPlayerID();
// FIXME FABRIC return gridProxy.getSecurity().hasPermission(playerID, SecurityPermissions.BUILD); // FIXME return gridProxy.getSecurity().hasPermission(playerID, SecurityPermissions.BUILD);
// FIXME FABRIC } else { // FIXME } else {
// FIXME FABRIC return false; // FIXME return false;
// FIXME FABRIC } // FIXME }
// FIXME FABRIC } catch (final GridAccessException gae) { // FIXME } catch (final GridAccessException gae) {
// FIXME FABRIC return false; // FIXME return false;
// FIXME FABRIC } // FIXME }
// FIXME FABRIC } // FIXME }
public static ItemStack extractItemsByRecipe(final IEnergySource energySrc, final IActionSource mySrc, public static ItemStack extractItemsByRecipe(final IEnergySource energySrc, final IActionSource mySrc,
final IMEMonitor<IAEItemStack> src, final World w, final Recipe<CraftingInventory> r, final IMEMonitor<IAEItemStack> src, final World w, final Recipe<CraftingInventory> r,
@@ -134,24 +134,6 @@ public class ClientHelper extends ServerHelper {
return this.renderModeForPlayer(player); return this.renderModeForPlayer(player);
} }
@Override
public void triggerUpdates() {
final MinecraftClient mc = MinecraftClient.getInstance();
if (mc.player == null || mc.world == null) {
return;
}
final PlayerEntity player = mc.player;
final int x = (int) player.getX();
final int y = (int) player.getY();
final int z = (int) player.getZ();
final int range = 16 * 16;
mc.worldRenderer.markBlockRangeForRenderUpdate(x - range, y - range, z - range, x + range, y + range,
z + range);
}
private void postPlayerRender(final RenderLivingEvent.Pre p) { private void postPlayerRender(final RenderLivingEvent.Pre p) {
// FIXME final PlayerColor player = TickHandler.INSTANCE.getPlayerColors().get( p.getEntity().getEntityId() ); // FIXME final PlayerColor player = TickHandler.INSTANCE.getPlayerColors().get( p.getEntity().getEntityId() );
@@ -56,8 +56,6 @@ public abstract class CommonHelper {
public abstract CableRenderMode getRenderMode(); public abstract CableRenderMode getRenderMode();
public abstract void triggerUpdates();
public abstract void updateRenderMode(PlayerEntity player); public abstract void updateRenderMode(PlayerEntity player);
public abstract boolean isActionKey(@Nonnull final ActionKey key, InputUtil.Key input); public abstract boolean isActionKey(@Nonnull final ActionKey key, InputUtil.Key input);
@@ -182,6 +182,7 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost,
return this.getItemStack().hasCustomName(); return this.getItemStack().hasCustomName();
} }
@Override
public void addEntityCrashInfo(final CrashReportSection section) { public void addEntityCrashInfo(final CrashReportSection section) {
section.add("Part Side", this.getSide()); section.add("Part Side", this.getSide());
} }
@@ -113,7 +113,7 @@ public class CableAnchorPart implements IPart {
@Override @Override
public boolean isLadder(final LivingEntity entity) { public boolean isLadder(final LivingEntity entity) {
return this.mySide.yOffset == 0 && (entity.collidedHorizontally || !entity.onGround); return this.mySide.yOffset == 0 && (entity.horizontalCollision || !entity.isOnGround());
} }
@Override @Override
@@ -121,11 +121,6 @@ public class ServerHelper extends CommonHelper {
return this.renderModeForPlayer(this.renderModeBased); return this.renderModeForPlayer(this.renderModeBased);
} }
@Override
public void triggerUpdates() {
}
@Override @Override
public void updateRenderMode(final PlayerEntity player) { public void updateRenderMode(final PlayerEntity player) {
this.renderModeBased = player; this.renderModeBased = player;