Moved more parts of ME over
This commit is contained in:
@@ -23,19 +23,16 @@
|
||||
|
||||
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 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.Environment;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.render.VertexConsumerProvider;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.LivingEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@@ -43,15 +40,16 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.crash.CrashReportSection;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.BlockView;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import appeng.api.networking.IGridNode;
|
||||
import appeng.api.util.AECableType;
|
||||
import appeng.api.util.AEColor;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import javax.annotation.Nonnull;
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
public interface IPart extends ICustomCableConnection {
|
||||
|
||||
@@ -343,8 +341,6 @@ public interface IPart extends ICustomCableConnection {
|
||||
* side.
|
||||
*
|
||||
* @see alexiil.mc.lib.attributes.AttributeProvider
|
||||
*
|
||||
* @return The capability or null.
|
||||
*/
|
||||
default void addAllAttributes(AttributeList<?> to) {}
|
||||
|
||||
@@ -355,4 +351,12 @@ public interface IPart extends ICustomCableConnection {
|
||||
*/
|
||||
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.core.Api;
|
||||
import appeng.core.ApiDefinitions;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.AppEngBase;
|
||||
import appeng.core.sync.network.ClientNetworkHandler;
|
||||
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.rendereregistry.v1.EntityRendererRegistry;
|
||||
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.Stream;
|
||||
|
||||
@Environment(EnvType.CLIENT)
|
||||
public final class AppEngClient extends AppEngBase {
|
||||
|
||||
private final MinecraftClient client;
|
||||
|
||||
private final ClientNetworkHandler networkHandler;
|
||||
|
||||
private final ClientTickHandler tickHandler;
|
||||
|
||||
public static AppEngClient instance() {
|
||||
return (AppEngClient) AppEng.instance();
|
||||
}
|
||||
|
||||
public AppEngClient() {
|
||||
super();
|
||||
|
||||
client = MinecraftClient.getInstance();
|
||||
networkHandler = new ClientNetworkHandler();
|
||||
tickHandler = new ClientTickHandler();
|
||||
|
||||
ModelsReloadCallback.EVENT.register(this::onModelsReloaded);
|
||||
|
||||
@@ -94,9 +106,21 @@ public final class AppEngClient extends AppEngBase {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
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
|
||||
|
||||
+32
-35
@@ -18,23 +18,19 @@
|
||||
|
||||
package appeng.container;
|
||||
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
import io.netty.handler.codec.DecoderException;
|
||||
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemUsageContext;
|
||||
import net.minecraft.network.PacketByteBuf;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.util.Hand;
|
||||
import net.minecraft.util.Identifier;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
import appeng.api.parts.IPartHost;
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.parts.AEBasePart;
|
||||
import net.minecraft.util.math.Direction;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
/**
|
||||
* 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 int itemIndex;
|
||||
private final int dimensionId;
|
||||
private final Identifier worldId;
|
||||
private final BlockPos blockPos;
|
||||
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.itemIndex = itemIndex;
|
||||
this.dimensionId = dimensionId;
|
||||
this.worldId = worldId;
|
||||
this.blockPos = blockPos;
|
||||
this.side = side;
|
||||
}
|
||||
@@ -78,16 +78,14 @@ public final class ContainerLocator {
|
||||
if (te.getWorld() == null) {
|
||||
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, dimensionId, te.getPos(), null);
|
||||
return new ContainerLocator(Type.BLOCK, -1, te.getWorld(), te.getPos(), null);
|
||||
}
|
||||
|
||||
public static ContainerLocator forTileEntitySide(BlockEntity te, Direction side) {
|
||||
if (te.getWorld() == null) {
|
||||
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, dimensionId, te.getPos(), AEPartLocation.fromFacing(side));
|
||||
return new ContainerLocator(Type.PART, -1, te.getWorld(), te.getPos(), AEPartLocation.fromFacing(side));
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -100,16 +98,15 @@ public final class ContainerLocator {
|
||||
if (player == null) {
|
||||
throw new IllegalArgumentException("Cannot open a container without a player");
|
||||
}
|
||||
int dimensionId = player.world.getDimension().getType().getId();
|
||||
int slot = getPlayerInventorySlotFromHand(player, context.getHand());
|
||||
AEPartLocation side = AEPartLocation.fromFacing(context.getFace());
|
||||
return new ContainerLocator(Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT, slot, dimensionId, context.getBlockPos(),
|
||||
AEPartLocation side = AEPartLocation.fromFacing(context.getSide());
|
||||
return new ContainerLocator(Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT, slot, player.world, context.getBlockPos(),
|
||||
side);
|
||||
}
|
||||
|
||||
public static ContainerLocator forHand(PlayerEntity player, Hand 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) {
|
||||
@@ -126,12 +123,12 @@ public final class ContainerLocator {
|
||||
throw new IllegalArgumentException("Could not find item held in hand " + hand + " in player inventory");
|
||||
}
|
||||
|
||||
public static ContainerLocator forPart(AEBasePart part) {
|
||||
IPartHost host = part.getHost();
|
||||
DimensionalCoord pos = host.getLocation();
|
||||
return new ContainerLocator(Type.PART, -1, pos.getWorld().getDimension().getType().getId(), pos.getBlockPos(),
|
||||
part.getSide());
|
||||
}
|
||||
// FIXME FABRIC public static ContainerLocator forPart(AEBasePart part) {
|
||||
// FIXME FABRIC IPartHost host = part.getHost();
|
||||
// FIXME FABRIC DimensionalCoord pos = host.getLocation();
|
||||
// FIXME FABRIC return new ContainerLocator(Type.PART, -1, pos.getWorld().getDimension().getType().getId(), pos.getBlockPos(),
|
||||
// FIXME FABRIC part.getSide());
|
||||
// FIXME FABRIC }
|
||||
|
||||
public boolean hasItemIndex() {
|
||||
return type == Type.PLAYER_INVENTORY || type == Type.PLAYER_INVENTORY_WITH_BLOCK_CONTEXT;
|
||||
@@ -142,8 +139,8 @@ public final class ContainerLocator {
|
||||
return itemIndex;
|
||||
}
|
||||
|
||||
public int getDimensionId() {
|
||||
return dimensionId;
|
||||
public Identifier getWorldId() {
|
||||
return worldId;
|
||||
}
|
||||
|
||||
public boolean hasBlockPos() {
|
||||
@@ -173,18 +170,18 @@ public final class ContainerLocator {
|
||||
case PLAYER_INVENTORY_WITH_BLOCK_CONTEXT:
|
||||
buf.writeByte(1);
|
||||
buf.writeInt(itemIndex);
|
||||
buf.writeInt(dimensionId);
|
||||
buf.writeIdentifier(worldId);
|
||||
buf.writeBlockPos(blockPos);
|
||||
buf.writeByte(side.ordinal());
|
||||
break;
|
||||
case BLOCK:
|
||||
buf.writeByte(2);
|
||||
buf.writeInt(dimensionId);
|
||||
buf.writeIdentifier(worldId);
|
||||
buf.writeBlockPos(blockPos);
|
||||
break;
|
||||
case PART:
|
||||
buf.writeByte(3);
|
||||
buf.writeInt(dimensionId);
|
||||
buf.writeIdentifier(worldId);
|
||||
buf.writeBlockPos(blockPos);
|
||||
buf.writeByte(side.ordinal());
|
||||
break;
|
||||
@@ -197,14 +194,14 @@ public final class ContainerLocator {
|
||||
byte type = buf.readByte();
|
||||
switch (type) {
|
||||
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:
|
||||
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()]);
|
||||
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:
|
||||
return new ContainerLocator(Type.PART, -1, buf.readInt(), buf.readBlockPos(),
|
||||
return new ContainerLocator(Type.PART, -1, buf.readIdentifier(), buf.readBlockPos(),
|
||||
AEPartLocation.values()[buf.readByte()]);
|
||||
default:
|
||||
throw new DecoderException("ContainerLocator type out of range: " + type);
|
||||
@@ -219,7 +216,7 @@ public final class ContainerLocator {
|
||||
result.append("slot=").append(itemIndex).append(',');
|
||||
}
|
||||
if (hasBlockPos()) {
|
||||
result.append("dim=").append(dimensionId).append(',');
|
||||
result.append("dim=").append(worldId).append(',');
|
||||
result.append("pos=").append(blockPos).append(',');
|
||||
}
|
||||
if (hasSide()) {
|
||||
@@ -22,6 +22,7 @@ import appeng.api.parts.CableRenderMode;
|
||||
import appeng.block.AEBaseBlock;
|
||||
import appeng.client.ActionKey;
|
||||
import appeng.client.EffectType;
|
||||
import appeng.core.stats.AdvancementTriggers;
|
||||
import appeng.core.sync.BasePacket;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
@@ -50,6 +51,8 @@ public interface AppEng {
|
||||
return new Identifier(MOD_ID, id);
|
||||
}
|
||||
|
||||
AdvancementTriggers getAdvancementTriggers();
|
||||
|
||||
Stream<? extends PlayerEntity> getPlayers();
|
||||
|
||||
void sendToAllNearExcept(PlayerEntity p, double x, double y, double z, double dist, World w,
|
||||
@@ -66,8 +69,6 @@ public interface AppEng {
|
||||
|
||||
CableRenderMode getRenderMode();
|
||||
|
||||
void triggerUpdates();
|
||||
|
||||
void updateRenderMode(PlayerEntity player);
|
||||
|
||||
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.network.NetworkHandler;
|
||||
import appeng.core.sync.network.TargetPoint;
|
||||
import appeng.hooks.TickHandler;
|
||||
import appeng.hooks.ToolItemHook;
|
||||
import appeng.mixins.CriteriaRegisterMixin;
|
||||
import appeng.recipes.handlers.*;
|
||||
@@ -112,6 +113,11 @@ public abstract class AppEngBase implements AppEng {
|
||||
// FIXME FABRIC FacadeRecipe.getSerializer(facadeItem));
|
||||
}
|
||||
|
||||
@Override
|
||||
public AdvancementTriggers getAdvancementTriggers() {
|
||||
return advancementTriggers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void sendToAllNearExcept(final PlayerEntity p, final double x, final double y, final double z,
|
||||
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;
|
||||
|
||||
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.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)
|
||||
public class TinyTNTPrimedRenderer extends EntityRenderer<TinyTNTPrimedEntity> {
|
||||
@@ -44,7 +41,6 @@ public class TinyTNTPrimedRenderer extends EntityRenderer<TinyTNTPrimedEntity> {
|
||||
@Override
|
||||
public void render(TinyTNTPrimedEntity tnt, float entityYaw, float partialTicks, MatrixStack mStack,
|
||||
VertexConsumerProvider buffers, int packedLight) {
|
||||
final BlockRenderManager blockrendererdispatcher = MinecraftClient.getInstance().getBlockRenderManager();
|
||||
mStack.push();
|
||||
mStack.translate(0, 0.25F, 0);
|
||||
float f2;
|
||||
@@ -67,7 +63,6 @@ public class TinyTNTPrimedRenderer extends EntityRenderer<TinyTNTPrimedEntity> {
|
||||
}
|
||||
|
||||
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.translate(-0.5D, -0.5D, 0.5D);
|
||||
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();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
+76
-105
@@ -18,43 +18,26 @@
|
||||
|
||||
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.core.AEConfig;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.AppEng;
|
||||
import appeng.core.sync.packets.PaintedEntityPacket;
|
||||
import appeng.crafting.CraftingJob;
|
||||
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.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 {
|
||||
|
||||
@@ -64,15 +47,18 @@ public class TickHandler {
|
||||
private final WeakHashMap<WorldAccess, Queue<IWorldCallable<?>>> callQueue = new WeakHashMap<>();
|
||||
private final HandlerRep server = 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 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() {
|
||||
if (Platform.isServer()) {
|
||||
return this.srvPlayerColors;
|
||||
}
|
||||
return this.cliPlayerColors;
|
||||
return this.srvPlayerColors;
|
||||
}
|
||||
|
||||
public void addCallable(final WorldAccess w, final IWorldCallable<?> c) {
|
||||
@@ -126,86 +112,71 @@ public class TickHandler {
|
||||
this.getRepo().clear();
|
||||
}
|
||||
|
||||
public void unloadWorld(final WorldEvent.Unload ev) {
|
||||
if (Platform.isServer()) // for no there is no reason to care about this on the client...
|
||||
{
|
||||
final List<IGridNode> toDestroy = new ArrayList<>();
|
||||
// FIXME FABRIC It does not look like worlds can ever unload in Fabric.
|
||||
// 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...
|
||||
// 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();
|
||||
for (final Grid g : this.getRepo().networks) {
|
||||
for (final IGridNode n : g.getNodes()) {
|
||||
if (n.getWorld() == ev.getWorld()) {
|
||||
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);
|
||||
}
|
||||
|
||||
public void onTick(final TickEvent ev) {
|
||||
|
||||
if (ev.type == Type.CLIENT && ev.phase == Phase.START) {
|
||||
this.tickColors(this.cliPlayerColors);
|
||||
final CableRenderMode currentMode = AEApi.instance().partHelper().getCableRenderMode();
|
||||
if (currentMode != this.crm) {
|
||||
this.crm = currentMode;
|
||||
AppEng.proxy.triggerUpdates();
|
||||
}
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
private void onAfterWorldTick(ServerWorld world) {
|
||||
synchronized (this.craftingJobs) {
|
||||
final Collection<CraftingJob> jobSet = this.craftingJobs.get(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();
|
||||
while (i.hasNext()) {
|
||||
final PlayerColor pc = i.next();
|
||||
@@ -18,6 +18,7 @@
|
||||
|
||||
package appeng.items.tools.quartz;
|
||||
|
||||
import appeng.container.ContainerLocator;
|
||||
import appeng.mixins.RemainderSetter;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
import net.minecraft.item.Item;
|
||||
@@ -47,7 +48,7 @@ public class QuartzCuttingKnifeItem extends AEBaseItem implements IGuiItem {
|
||||
@Override
|
||||
public TypedActionResult<ItemStack> use(final World w, final PlayerEntity p, final Hand hand) {
|
||||
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();
|
||||
}
|
||||
p.swingHand(hand);
|
||||
|
||||
+3
-4
@@ -20,6 +20,7 @@ package appeng.me.cache.helpers;
|
||||
|
||||
import javax.annotation.Nonnull;
|
||||
|
||||
import appeng.api.parts.IPart;
|
||||
import net.minecraft.util.crash.CrashReportSection;
|
||||
|
||||
import appeng.api.networking.IGridNode;
|
||||
@@ -27,8 +28,6 @@ import appeng.api.networking.ticking.IGridTickable;
|
||||
import appeng.api.networking.ticking.TickingRequest;
|
||||
import appeng.api.util.DimensionalCoord;
|
||||
import appeng.me.cache.TickManagerCache;
|
||||
import appeng.parts.AEBasePart;
|
||||
import net.minecraft.util.crash.CrashReportSection;
|
||||
|
||||
public class TickTracker implements Comparable<TickTracker> {
|
||||
|
||||
@@ -73,8 +72,8 @@ public class TickTracker implements Comparable<TickTracker> {
|
||||
}
|
||||
|
||||
public void addEntityCrashInfo(final CrashReportSection section) {
|
||||
if (this.getGridTickable() instanceof AEBasePart) {
|
||||
final AEBasePart part = (AEBasePart) this.getGridTickable();
|
||||
if (this.getGridTickable() instanceof IPart) {
|
||||
final IPart part = (IPart) this.getGridTickable();
|
||||
part.addEntityCrashInfo(section);
|
||||
}
|
||||
|
||||
@@ -6,6 +6,7 @@ import appeng.client.ActionKey;
|
||||
import appeng.client.EffectType;
|
||||
import appeng.core.AppEngBase;
|
||||
import appeng.core.sync.network.ServerNetworkHandler;
|
||||
import appeng.hooks.TickHandler;
|
||||
import net.fabricmc.fabric.api.server.PlayerStream;
|
||||
import net.minecraft.block.entity.BlockEntity;
|
||||
import net.minecraft.client.util.InputUtil;
|
||||
@@ -25,9 +26,12 @@ public final class AppEngServer extends AppEngBase {
|
||||
|
||||
private final ServerNetworkHandler networkHandler;
|
||||
|
||||
private final TickHandler tickHandler;
|
||||
|
||||
public AppEngServer(MinecraftServer server) {
|
||||
this.server = server;
|
||||
this.networkHandler = new ServerNetworkHandler();
|
||||
this.tickHandler = new TickHandler();
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -60,11 +64,6 @@ public final class AppEngServer extends AppEngBase {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void triggerUpdates() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -48,6 +48,8 @@ import appeng.core.AEConfig;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.stats.AeStats;
|
||||
import appeng.fluids.util.AEFluidStack;
|
||||
import appeng.me.GridAccessException;
|
||||
import appeng.me.GridNode;
|
||||
import appeng.util.helpers.ItemComparisonHelper;
|
||||
import appeng.util.helpers.P2PHelper;
|
||||
import appeng.util.item.AEItemStack;
|
||||
@@ -882,43 +884,43 @@ public class Platform {
|
||||
}
|
||||
}
|
||||
|
||||
// FIXME FABRIC public static boolean securityCheck(final GridNode a, final GridNode b) {
|
||||
// FIXME FABRIC if (a.getLastSecurityKey() == -1 && b.getLastSecurityKey() == -1) {
|
||||
// FIXME FABRIC return true;
|
||||
// FIXME FABRIC } else if (a.getLastSecurityKey() == b.getLastSecurityKey()) {
|
||||
// FIXME FABRIC return true;
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC final boolean a_isSecure = isPowered(a.getGrid()) && a.getLastSecurityKey() != -1;
|
||||
// FIXME FABRIC final boolean b_isSecure = isPowered(b.getGrid()) && b.getLastSecurityKey() != -1;
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC if (AEConfig.instance().isFeatureEnabled(AEFeature.LOG_SECURITY_AUDITS)) {
|
||||
// FIXME FABRIC final String locationA = a.getGridBlock().isWorldAccessible() ? a.getGridBlock().getLocation().toString()
|
||||
// FIXME FABRIC : "notInWorld";
|
||||
// FIXME FABRIC final String locationB = b.getGridBlock().isWorldAccessible() ? b.getGridBlock().getLocation().toString()
|
||||
// FIXME FABRIC : "notInWorld";
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC 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}]",
|
||||
// FIXME FABRIC a_isSecure, a.getLastSecurityKey(), a.getPlayerID(), locationA, b_isSecure, b.getLastSecurityKey(),
|
||||
// FIXME FABRIC b.getPlayerID(), locationB);
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC // can't do that son...
|
||||
// FIXME FABRIC if (a_isSecure && b_isSecure) {
|
||||
// FIXME FABRIC return false;
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC if (!a_isSecure && b_isSecure) {
|
||||
// FIXME FABRIC return checkPlayerPermissions(b.getGrid(), a.getPlayerID());
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC if (a_isSecure && !b_isSecure) {
|
||||
// FIXME FABRIC return checkPlayerPermissions(a.getGrid(), b.getPlayerID());
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC return true;
|
||||
// FIXME FABRIC }
|
||||
public static boolean securityCheck(final GridNode a, final GridNode b) {
|
||||
if (a.getLastSecurityKey() == -1 && b.getLastSecurityKey() == -1) {
|
||||
return true;
|
||||
} else if (a.getLastSecurityKey() == b.getLastSecurityKey()) {
|
||||
return true;
|
||||
}
|
||||
|
||||
final boolean a_isSecure = isPowered(a.getGrid()) && a.getLastSecurityKey() != -1;
|
||||
final boolean b_isSecure = isPowered(b.getGrid()) && b.getLastSecurityKey() != -1;
|
||||
|
||||
if (AEConfig.instance().isFeatureEnabled(AEFeature.LOG_SECURITY_AUDITS)) {
|
||||
final String locationA = a.getGridBlock().isWorldAccessible() ? a.getGridBlock().getLocation().toString()
|
||||
: "notInWorld";
|
||||
final String locationB = b.getGridBlock().isWorldAccessible() ? b.getGridBlock().getLocation().toString()
|
||||
: "notInWorld";
|
||||
|
||||
AELog.info(
|
||||
"Audit: Node A [isSecure=%b, key=%d, playerID=%d, location={%s}] vs Node B[isSecure=%b, key=%d, playerID=%d, location={%s}]",
|
||||
a_isSecure, a.getLastSecurityKey(), a.getPlayerID(), locationA, b_isSecure, b.getLastSecurityKey(),
|
||||
b.getPlayerID(), locationB);
|
||||
}
|
||||
|
||||
// can't do that son...
|
||||
if (a_isSecure && b_isSecure) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (!a_isSecure && b_isSecure) {
|
||||
return checkPlayerPermissions(b.getGrid(), a.getPlayerID());
|
||||
}
|
||||
|
||||
if (a_isSecure && !b_isSecure) {
|
||||
return checkPlayerPermissions(a.getGrid(), b.getPlayerID());
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
private static boolean isPowered(final IGrid grid) {
|
||||
if (grid == null) {
|
||||
@@ -980,26 +982,26 @@ public class Platform {
|
||||
yaw, pitch);
|
||||
}
|
||||
|
||||
// FIXME FABRIC public static boolean canAccess(final AENetworkProxy gridProxy, final IActionSource src) {
|
||||
// FIXME FABRIC try {
|
||||
// FIXME FABRIC if (src.player().isPresent()) {
|
||||
// FIXME FABRIC return gridProxy.getSecurity().hasPermission(src.player().get(), SecurityPermissions.BUILD);
|
||||
// FIXME FABRIC } else if (src.machine().isPresent()) {
|
||||
// FIXME FABRIC final IActionHost te = src.machine().get();
|
||||
// FIXME FABRIC final IGridNode n = te.getActionableNode();
|
||||
// FIXME FABRIC if (n == null) {
|
||||
// FIXME FABRIC return false;
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC
|
||||
// FIXME FABRIC final int playerID = n.getPlayerID();
|
||||
// FIXME FABRIC return gridProxy.getSecurity().hasPermission(playerID, SecurityPermissions.BUILD);
|
||||
// FIXME FABRIC } else {
|
||||
// FIXME FABRIC return false;
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC } catch (final GridAccessException gae) {
|
||||
// FIXME FABRIC return false;
|
||||
// FIXME FABRIC }
|
||||
// FIXME FABRIC }
|
||||
// FIXME public static boolean canAccess(final AENetworkProxy gridProxy, final IActionSource src) {
|
||||
// FIXME try {
|
||||
// FIXME if (src.player().isPresent()) {
|
||||
// FIXME return gridProxy.getSecurity().hasPermission(src.player().get(), SecurityPermissions.BUILD);
|
||||
// FIXME } else if (src.machine().isPresent()) {
|
||||
// FIXME final IActionHost te = src.machine().get();
|
||||
// FIXME final IGridNode n = te.getActionableNode();
|
||||
// FIXME if (n == null) {
|
||||
// FIXME return false;
|
||||
// FIXME }
|
||||
// FIXME
|
||||
// FIXME final int playerID = n.getPlayerID();
|
||||
// FIXME return gridProxy.getSecurity().hasPermission(playerID, SecurityPermissions.BUILD);
|
||||
// FIXME } else {
|
||||
// FIXME return false;
|
||||
// FIXME }
|
||||
// FIXME } catch (final GridAccessException gae) {
|
||||
// FIXME return false;
|
||||
// FIXME }
|
||||
// FIXME }
|
||||
|
||||
public static ItemStack extractItemsByRecipe(final IEnergySource energySrc, final IActionSource mySrc,
|
||||
final IMEMonitor<IAEItemStack> src, final World w, final Recipe<CraftingInventory> r,
|
||||
|
||||
@@ -134,24 +134,6 @@ public class ClientHelper extends ServerHelper {
|
||||
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) {
|
||||
// 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 void triggerUpdates();
|
||||
|
||||
public abstract void updateRenderMode(PlayerEntity player);
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addEntityCrashInfo(final CrashReportSection section) {
|
||||
section.add("Part Side", this.getSide());
|
||||
}
|
||||
|
||||
@@ -113,7 +113,7 @@ public class CableAnchorPart implements IPart {
|
||||
|
||||
@Override
|
||||
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
|
||||
|
||||
@@ -121,11 +121,6 @@ public class ServerHelper extends CommonHelper {
|
||||
return this.renderModeForPlayer(this.renderModeBased);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void triggerUpdates() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateRenderMode(final PlayerEntity player) {
|
||||
this.renderModeBased = player;
|
||||
|
||||
Reference in New Issue
Block a user