diff --git a/build.gradle b/build.gradle index f5fcec648..837159f61 100644 --- a/build.gradle +++ b/build.gradle @@ -37,7 +37,9 @@ repositories { maven { name = "HYWLA" url = "https://maven.tehnut.info/" - + content { + includeGroup "mcp.mobius.waila" + } } maven { name = 'Earthcomputer Mods' @@ -107,8 +109,12 @@ dependencies { include "alexiil.mc.lib:libblockattributes-items:${libblockattributes_version}" include "alexiil.mc.lib:libblockattributes-fluids:${libblockattributes_version}" - modCompileOnly "me.shedaniel:RoughlyEnoughItems:4.6.6" - modCompileOnly "mcp.mobius.waila:Hwyla:1.16.1-1.9.22-75" + modCompileOnly("me.shedaniel:RoughlyEnoughItems:5.0.2-unstable") { + exclude group: "net.fabricmc.fabric-api" + } + modCompileOnly("mcp.mobius.waila:Hwyla:1.16.1-1.9.22-75") { + exclude group: "net.fabricmc.fabric-api" + } // modRuntimeOnly "me.shedaniel:RoughlyEnoughItems:4.6.6" // modRuntimeOnly "mcp.mobius.waila:Hwyla:1.16.1-1.9.22-75" diff --git a/gradle.properties b/gradle.properties index a2d864964..099af2f66 100644 --- a/gradle.properties +++ b/gradle.properties @@ -14,7 +14,7 @@ yarn_mappings=1.16.2-pre1+build.5 loader_version=0.9.0+build.204 #Fabric api -fabric_version=0.16.1+build.387-1.16 +fabric_version=0.16.3+build.390-1.16 loom_version=0.4-SNAPSHOT diff --git a/src/main/java/appeng/client/AppEngClient.java b/src/main/java/appeng/client/AppEngClient.java index 0e8aed2d3..837a5ef2e 100644 --- a/src/main/java/appeng/client/AppEngClient.java +++ b/src/main/java/appeng/client/AppEngClient.java @@ -217,6 +217,12 @@ public final class AppEngClient extends AppEngBase { throw new IllegalStateException("No server is currently running."); } + @Override + public boolean isOnServerThread() { + IntegratedServer server = client.getServer(); + return server != null && server.isOnThread(); + } + @Override public Stream getPlayers() { return Stream.empty(); @@ -243,15 +249,15 @@ public final class AppEngClient extends AppEngBase { } @Override - public CableRenderMode getRenderMode() { + public CableRenderMode getCableRenderMode() { if (Platform.isServer()) { - return super.getRenderMode(); + return super.getCableRenderMode(); } final MinecraftClient mc = MinecraftClient.getInstance(); final PlayerEntity player = mc.player; - return this.renderModeForPlayer(player); + return this.getCableRenderModeForPlayer(player); } public void triggerUpdates() { @@ -271,7 +277,7 @@ public final class AppEngClient extends AppEngBase { } @Override - public void updateRenderMode(PlayerEntity player) { + public void setPartInteractionPlayer(PlayerEntity player) { } diff --git a/src/main/java/appeng/core/AppEng.java b/src/main/java/appeng/core/AppEng.java index 1f09cd663..8042b14f1 100644 --- a/src/main/java/appeng/core/AppEng.java +++ b/src/main/java/appeng/core/AppEng.java @@ -67,9 +67,14 @@ public interface AppEng { void postInit(); - CableRenderMode getRenderMode(); + CableRenderMode getCableRenderMode(); - void updateRenderMode(PlayerEntity player); + /** + * Sets the player that is currently interacting with a cable or part attached to a cable. This will return that + * player's cable render mode from calls to {@link #getCableRenderMode()}, until another player or null is set. + * @param player Null to revert to the default cable render mode. + */ + void setPartInteractionPlayer(PlayerEntity player); boolean isActionKey(@Nonnull final ActionKey key, int keyCode, int scanCode); @@ -81,6 +86,11 @@ public interface AppEng { */ MinecraftServer getServer(); + /** + * Checks whether the current thread is the main server thread. + */ + boolean isOnServerThread(); + // // private final Registration registration; // diff --git a/src/main/java/appeng/core/AppEngBase.java b/src/main/java/appeng/core/AppEngBase.java index 7386c2776..4cfb422b5 100644 --- a/src/main/java/appeng/core/AppEngBase.java +++ b/src/main/java/appeng/core/AppEngBase.java @@ -152,12 +152,23 @@ import appeng.worldgen.ChargedQuartzOreConfig; import appeng.worldgen.ChargedQuartzOreFeature; import appeng.worldgen.meteorite.MeteoriteStructure; +import javax.annotation.Nullable; + public abstract class AppEngBase implements AppEng { protected AdvancementTriggers advancementTriggers; - // WTF is this doing? Should this be a ThreadLocal??? - private PlayerEntity renderModeBased; + /** + * While we process a player-specific part placement/cable interaction packet, + * we need to use that player's transparent-facade mode to understand whether + * the player can see through facades or not. + *

+ * We need to use this method since the collision shape methods do not know + * about the player that the shape is being requested for, so they will call + * {@link #getCableRenderMode()} below, which then will use this field to figure + * out which player it's for. + */ + private final ThreadLocal partInteractionPlayer = new ThreadLocal<>(); public AppEngBase() { if (AppEng.instance() != null) { @@ -423,18 +434,13 @@ public abstract class AppEngBase implements AppEng { } @Override - public CableRenderMode getRenderMode() { - if (this.renderModeBased == null) { - return CableRenderMode.STANDARD; - } - - return this.renderModeForPlayer(this.renderModeBased); + public CableRenderMode getCableRenderMode() { + return this.getCableRenderModeForPlayer(partInteractionPlayer.get()); } - // FIXME this is some hot shit _FOR WHAT_? @Override - public void updateRenderMode(final PlayerEntity player) { - this.renderModeBased = player; + public void setPartInteractionPlayer(final PlayerEntity player) { + this.partInteractionPlayer.set(player); } protected final void callDeferredBootstrapComponents(Class componentClass, @@ -443,7 +449,7 @@ public abstract class AppEngBase implements AppEng { definitions.getRegistry().getBootstrapComponents(componentClass).forEachRemaining(invoker); } - protected CableRenderMode renderModeForPlayer(final PlayerEntity player) { + protected final CableRenderMode getCableRenderModeForPlayer(@Nullable final PlayerEntity player) { if (player != null) { for (int x = 0; x < PlayerInventory.getHotbarSize(); x++) { final ItemStack is = player.inventory.getStack(x); diff --git a/src/main/java/appeng/core/api/ApiPart.java b/src/main/java/appeng/core/api/ApiPart.java index 7d0cb95e5..95674f52e 100644 --- a/src/main/java/appeng/core/api/ApiPart.java +++ b/src/main/java/appeng/core/api/ApiPart.java @@ -41,6 +41,6 @@ public class ApiPart implements IPartHelper { @Override public CableRenderMode getCableRenderMode() { - return AppEng.instance().getRenderMode(); + return AppEng.instance().getCableRenderMode(); } } diff --git a/src/main/java/appeng/core/sync/packets/PartPlacementPacket.java b/src/main/java/appeng/core/sync/packets/PartPlacementPacket.java index f502e62fb..ab747b492 100644 --- a/src/main/java/appeng/core/sync/packets/PartPlacementPacket.java +++ b/src/main/java/appeng/core/sync/packets/PartPlacementPacket.java @@ -68,11 +68,14 @@ public class PartPlacementPacket extends BasePacket { @Override public void serverPacketData(final INetworkInfo manager, final PlayerEntity player) { final ServerPlayerEntity sender = (ServerPlayerEntity) player; - AppEng.instance().updateRenderMode(sender); - PartPlacement.setEyeHeight(this.eyeHeight); - PartPlacement.place(sender.getStackInHand(this.hand), new BlockPos(this.x, this.y, this.z), - Direction.values()[this.face], sender, this.hand, sender.world, - PartPlacement.PlaceType.INTERACT_FIRST_PASS, 0); - AppEng.instance().updateRenderMode(null); + AppEng.instance().setPartInteractionPlayer(sender); + try { + PartPlacement.setEyeHeight(this.eyeHeight); + PartPlacement.place(sender.getStackInHand(this.hand), new BlockPos(this.x, this.y, this.z), + Direction.values()[this.face], sender, this.hand, sender.world, + PartPlacement.PlaceType.INTERACT_FIRST_PASS, 0); + } finally { + AppEng.instance().setPartInteractionPlayer(null); + } } } diff --git a/src/main/java/appeng/parts/PartPlacement.java b/src/main/java/appeng/parts/PartPlacement.java index 491228def..807ede314 100644 --- a/src/main/java/appeng/parts/PartPlacement.java +++ b/src/main/java/appeng/parts/PartPlacement.java @@ -316,11 +316,12 @@ public class PartPlacement { } private static SelectedPart selectPart(final PlayerEntity player, final IPartHost host, final Vec3d pos) { - AppEng.instance().updateRenderMode(player); - final SelectedPart sp = host.selectPart(pos); - AppEng.instance().updateRenderMode(null); - - return sp; + AppEng.instance().setPartInteractionPlayer(player); + try { + return host.selectPart(pos); + } finally { + AppEng.instance().setPartInteractionPlayer(null); + } } public static IFacadePart isFacade(final ItemStack held, final AEPartLocation side) { diff --git a/src/main/java/appeng/server/AppEngServer.java b/src/main/java/appeng/server/AppEngServer.java index 73e9ceff0..cabb51cd0 100644 --- a/src/main/java/appeng/server/AppEngServer.java +++ b/src/main/java/appeng/server/AppEngServer.java @@ -7,13 +7,11 @@ import javax.annotation.Nonnull; import net.fabricmc.fabric.api.event.lifecycle.v1.ServerLifecycleEvents; import net.fabricmc.fabric.api.server.PlayerStream; -import net.minecraft.client.util.InputUtil; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.MinecraftServer; import net.minecraft.util.hit.HitResult; import net.minecraft.world.World; -import appeng.api.parts.CableRenderMode; import appeng.client.ActionKey; import appeng.client.EffectType; import appeng.core.AppEngBase; @@ -78,16 +76,6 @@ public final class AppEngServer extends AppEngBase { } - @Override - public CableRenderMode getRenderMode() { - return null; - } - - @Override - public void updateRenderMode(PlayerEntity player) { - - } - @Override public boolean isActionKey(@Nonnull ActionKey key, int keyCode, int scanCode) { return false; @@ -98,4 +86,9 @@ public final class AppEngServer extends AppEngBase { return server; } + @Override + public boolean isOnServerThread() { + return server != null && server.isOnThread(); + } + } diff --git a/src/main/java/appeng/util/Platform.java b/src/main/java/appeng/util/Platform.java index 3d35dae0b..0e3252efc 100644 --- a/src/main/java/appeng/util/Platform.java +++ b/src/main/java/appeng/util/Platform.java @@ -18,48 +18,14 @@ package appeng.util; -import java.text.DecimalFormat; -import java.util.*; - -import javax.annotation.Nullable; - -import com.google.common.base.Preconditions; -import com.google.common.collect.Iterables; - -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; -import net.fabricmc.loader.api.FabricLoader; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.entity.BlockEntity; -import net.minecraft.client.MinecraftClient; -import net.minecraft.client.item.TooltipContext; -import net.minecraft.entity.Entity; -import net.minecraft.entity.ItemEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.inventory.CraftingInventory; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.recipe.Recipe; -import net.minecraft.server.integrated.IntegratedServer; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.text.LiteralText; -import net.minecraft.text.Text; -import net.minecraft.text.TranslatableText; -import net.minecraft.util.Formatting; -import net.minecraft.util.Identifier; -import net.minecraft.util.Util; -import net.minecraft.util.hit.EntityHitResult; -import net.minecraft.util.hit.HitResult; -import net.minecraft.util.math.*; -import net.minecraft.util.registry.Registry; -import net.minecraft.world.RayTraceContext; -import net.minecraft.world.World; - import alexiil.mc.lib.attributes.fluid.volume.FluidVolume; - -import appeng.api.config.*; +import appeng.api.config.AccessRestriction; +import appeng.api.config.Actionable; +import appeng.api.config.PowerMultiplier; +import appeng.api.config.PowerUnits; +import appeng.api.config.SearchBoxMode; +import appeng.api.config.SecurityPermissions; +import appeng.api.config.SortOrder; import appeng.api.definitions.IItemDefinition; import appeng.api.definitions.IMaterials; import appeng.api.features.AEFeature; @@ -86,6 +52,7 @@ import appeng.api.util.DimensionalCoord; import appeng.core.AEConfig; import appeng.core.AELog; import appeng.core.Api; +import appeng.core.AppEng; import appeng.core.stats.AeStats; import appeng.fluids.util.AEFluidStack; import appeng.hooks.TickHandler; @@ -97,6 +64,50 @@ import appeng.util.helpers.ItemComparisonHelper; import appeng.util.helpers.P2PHelper; import appeng.util.item.AEItemStack; import appeng.util.prioritylist.IPartitionList; +import com.google.common.base.Preconditions; +import com.google.common.collect.Iterables; +import net.fabricmc.api.EnvType; +import net.fabricmc.api.Environment; +import net.fabricmc.loader.api.FabricLoader; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.entity.BlockEntity; +import net.minecraft.client.MinecraftClient; +import net.minecraft.client.item.TooltipContext; +import net.minecraft.entity.Entity; +import net.minecraft.entity.ItemEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.inventory.CraftingInventory; +import net.minecraft.item.Item; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.recipe.Recipe; +import net.minecraft.server.MinecraftServer; +import net.minecraft.server.world.ServerWorld; +import net.minecraft.text.LiteralText; +import net.minecraft.text.Text; +import net.minecraft.text.TranslatableText; +import net.minecraft.util.Formatting; +import net.minecraft.util.Identifier; +import net.minecraft.util.Util; +import net.minecraft.util.hit.EntityHitResult; +import net.minecraft.util.hit.HitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Box; +import net.minecraft.util.math.Direction; +import net.minecraft.util.math.MathHelper; +import net.minecraft.util.math.Vec3d; +import net.minecraft.util.registry.Registry; +import net.minecraft.world.RayTraceContext; +import net.minecraft.world.World; + +import javax.annotation.Nullable; +import java.text.DecimalFormat; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Random; /** * @author AlgorithmX2 @@ -203,10 +214,7 @@ public class Platform { * returns true if the code is on the client. */ public static boolean isClient() { - // FIXME: Move this to the proxy so it will work on a dedicated server - MinecraftClient client = MinecraftClient.getInstance(); - IntegratedServer server = client.getServer(); - return server == null || Thread.currentThread() != server.getThread(); + return !AppEng.instance().isOnServerThread(); } /* @@ -647,8 +655,7 @@ public class Platform { public static LookDirection getPlayerRay(final PlayerEntity playerIn, double reachDistance) { final double x = playerIn.prevX + (playerIn.getX() - playerIn.prevX); - final double y = playerIn.prevY + (playerIn.getY() - playerIn.prevY) - + playerIn.getEyeHeight(playerIn.getPose()); + final double y = playerIn.prevY + (playerIn.getY() - playerIn.prevY) + playerIn.getStandingEyeHeight(); final double z = playerIn.prevZ + (playerIn.getZ() - playerIn.prevZ); final float playerPitch = playerIn.prevPitch + (playerIn.pitch - playerIn.prevPitch); diff --git a/src/main/java/appeng/worldgen/meteorite/MeteoriteStructurePiece.java b/src/main/java/appeng/worldgen/meteorite/MeteoriteStructurePiece.java index b529a4254..eed0a0786 100644 --- a/src/main/java/appeng/worldgen/meteorite/MeteoriteStructurePiece.java +++ b/src/main/java/appeng/worldgen/meteorite/MeteoriteStructurePiece.java @@ -35,7 +35,7 @@ import appeng.worldgen.meteorite.fallout.FalloutMode; public class MeteoriteStructurePiece extends StructurePiece { - public static final StructurePieceType TYPE = StructurePieceType.register(MeteoriteStructurePiece::new, "AE2MTRT"); + public static final StructurePieceType TYPE = StructurePieceType.register(MeteoriteStructurePiece::new, "ae2mtrt"); private final PlacedMeteoriteSettings settings;