Skip to content

Commit

Permalink
Fixed accessory visibility syncing for other players (finally, it was…
Browse files Browse the repository at this point in the history
… actually a really easy fix...)

Fixed player in accessory inventory not looking at mouse correctly

Alright, now I can work on the boss systems without having to think about that damn syncing issue!
There are still other knows issues (dungeon spawning, accessory inventory clicking not registering sometimes, meteorite spawning) but i can fix them later as they have a lot of work to do and aren't as important right now.
  • Loading branch information
jakeb072001 committed Feb 22, 2024
1 parent 942c4b2 commit 9ad4380
Show file tree
Hide file tree
Showing 16 changed files with 70 additions and 154 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
- Eye of Cthulhu and Eater of Worlds //-- Not yet done
- Teams //-- Not yet done
-
### Fixed
- Accessory visibility not syncing correctly for other players
- Player in accessory inventory not looking at mouse position correctly

## [1.7.2-1.20.1] - 2024-02-21
### Changed
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/terramine/TerraMine.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import terramine.common.misc.TerrariaInventory;
import terramine.common.network.ServerPacketHandler;
import terramine.common.utility.InputHandler;
import terramine.common.utility.PlayerInventories;
import terramine.common.world.biome.BiomeAdder;
import terramine.common.world.biome.BiomeAdderCrimsonForced;
import terramine.common.world.biome.BiomeSurfaceRules;
Expand Down Expand Up @@ -90,6 +91,9 @@ public void onInitialize() {
((PlayerStorages) newPlayer).setTerrariaInventory(((PlayerStorages) oldPlayer).getTerrariaInventory());
((PlayerStorages) newPlayer).setPiggyBankInventory(((PlayerStorages) oldPlayer).getPiggyBankInventory());
((PlayerStorages) newPlayer).setSafeInventory(((PlayerStorages) oldPlayer).getSafeInventory());
for (int i = 0; i < 7; i++) {
((PlayerStorages) newPlayer).setSlotVisibility(i, ((PlayerStorages) oldPlayer).getSlotVisibility(i));
}
}
});
PlayerEvent.CHANGE_DIMENSION.register((player, oldLevel, newLevel) -> syncInventory(player));
Expand Down Expand Up @@ -130,6 +134,10 @@ private void syncInventory(ServerPlayer player) {
}
ServerPlayNetworking.send(player, ServerPacketHandler.SETUP_INVENTORY_PACKET_ID, buf2);
ServerPlayNetworking.send(otherPlayer, ServerPacketHandler.SETUP_INVENTORY_PACKET_ID, buf);

for (int i = 0; i < 7; i++) {
((PlayerStorages) otherPlayer).setSlotVisibility(i, ((PlayerStorages) otherPlayer).getSlotVisibility(i));
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected HumanoidModel<LivingEntity> getModel() {

@Override
public final void render(ItemStack itemStack, int dyeSlot, int realSlot, EntityModel<? extends LivingEntity> contextModel, PoseStack poseStack, MultiBufferSource multiBufferSource, int light, Player player, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
if (!ModComponents.ACCESSORY_VISIBILITY.get(player).getSlotVisibility(realSlot)) {
if (!((PlayerStorages) player).getSlotVisibility(realSlot)) {
return;
}
HumanoidModel<LivingEntity> model = getModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ protected BeltModel getModel() {

@Override
public final void render(ItemStack stack, int dyeSlot, int realSlot, EntityModel<? extends LivingEntity> contextModel, PoseStack poseStack, MultiBufferSource multiBufferSource, int light, Player player, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
if (!ModComponents.ACCESSORY_VISIBILITY.get(player).getSlotVisibility(realSlot)) {
if (!((PlayerStorages) player).getSlotVisibility(realSlot)) {
return;
}
BeltModel model = getModel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ protected static boolean hasSlimArms(Entity entity) {

@Override
public final void render(ItemStack stack, int dyeSlot, int realSlot, EntityModel<? extends LivingEntity> contextModel, PoseStack poseStack, MultiBufferSource multiBufferSource, int light, Player player, float limbSwing, float limbSwingAmount, float partialTicks, float ageInTicks, float netHeadYaw, float headPitch) {
if (!ModComponents.ACCESSORY_VISIBILITY.get(player).getSlotVisibility(realSlot)) {
if (!((PlayerStorages) player).getSlotVisibility(realSlot)) {
return;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import terramine.common.init.ModComponents;
import terramine.extensions.PlayerStorages;

@Environment(EnvType.CLIENT)
public class ToggleImageButton extends Button {
Expand Down Expand Up @@ -48,7 +49,7 @@ public void renderWidget(GuiGraphics guiGraphics, int i, int j, float f) {

if (!this.isActive()) {
g += this.xDiffTex * 2;
} else if (!ModComponents.ACCESSORY_VISIBILITY.get(Minecraft.getInstance().player).getSlotVisibility(slot)) {
} else if (!((PlayerStorages) Minecraft.getInstance().player).getSlotVisibility(slot)) {
g += this.xDiffTex;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
import terramine.client.render.gui.menu.TerrariaInventoryContainerMenu;
import terramine.common.init.ModComponents;
import terramine.common.network.ServerPacketHandler;
import terramine.extensions.PlayerStorages;

import java.util.List;

Expand Down Expand Up @@ -89,7 +90,7 @@ protected void init() {
this.addRenderableWidget(new ToggleImageButton(this.leftPos + 130, this.height / 2 - 105 + (18 * i), 8, 8, 0, 0, 8, 8, i, EYE_TEX, 16, 16, (buttonWidget) -> {
FriendlyByteBuf buf = new FriendlyByteBuf(Unpooled.buffer());
buf.writeInt(finalI);
buf.writeBoolean(!ModComponents.ACCESSORY_VISIBILITY.get(this.minecraft.player).getSlotVisibility(finalI));
buf.writeBoolean(!((PlayerStorages) this.minecraft.player).getSlotVisibility(finalI));
ClientPlayNetworking.send(ServerPacketHandler.UPDATE_ACCESSORY_VISIBILITY_PACKET_ID, buf);
}));
}
Expand Down Expand Up @@ -121,7 +122,7 @@ protected void renderBg(@NotNull GuiGraphics guiGraphics, float f, int i, int j)
}

public void renderEntityInInventoryFollowsMouse(GuiGraphics guiGraphics, int i, int j, int k, float f, float g, LivingEntity livingEntity) {
float h = (float)Math.atan(f / 40.0F);
float h = (float)Math.atan((f + 35) / 40.0F);
float l = (float)Math.atan(g / 40.0F);
Quaternionf quaternionf = (new Quaternionf()).rotateZ(3.1415927F);
Quaternionf quaternionf2 = (new Quaternionf()).rotateX(l * 20.0F * 0.017453292F);
Expand Down

This file was deleted.

3 changes: 0 additions & 3 deletions src/main/java/terramine/common/init/ModComponents.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ public class ModComponents implements EntityComponentInitializer, LevelComponent
ComponentRegistryV3.INSTANCE.getOrCreate(TerraMine.id("lava_immunity"), LavaImmunityComponent.class);
public static final ComponentKey<SyncedBooleanComponent> SPACE_GUN_FREE =
ComponentRegistryV3.INSTANCE.getOrCreate(TerraMine.id("space_gun_free"), SyncedBooleanComponent.class);
public static final ComponentKey<AccessoryVisibilityComponent> ACCESSORY_VISIBILITY =
ComponentRegistryV3.INSTANCE.getOrCreate(TerraMine.id("accessory_visibility"), AccessoryVisibilityComponent.class);
public static final ComponentKey<SyncedIntegerComponent> ACCESSORY_SLOTS_ADDER =
ComponentRegistryV3.INSTANCE.getOrCreate(TerraMine.id("accessory_slots_adder"), SyncedIntegerComponent.class);
public static final ComponentKey<SyncedBooleanComponent> ACCESSORY_HARDCORE_CHECK =
Expand All @@ -62,7 +60,6 @@ public void registerEntityComponentFactories(EntityComponentFactoryRegistry regi
registry.registerForPlayers(MOVEMENT_ORDER, MovementOrderComponent::new, RespawnCopyStrategy.LOSSLESS_ONLY);
registry.registerForPlayers(LAVA_IMMUNITY, LavaImmunityComponent::new, RespawnCopyStrategy.LOSSLESS_ONLY);
registry.registerForPlayers(SPACE_GUN_FREE, player -> new SyncedBooleanComponent("space_gun_free"), RespawnCopyStrategy.LOSSLESS_ONLY);
registry.registerForPlayers(ACCESSORY_VISIBILITY, AccessoryVisibilityComponent::new, RespawnCopyStrategy.CHARACTER);
registry.registerForPlayers(ACCESSORY_SLOTS_ADDER, player -> new SyncedIntegerComponent("extraSlots"), RespawnCopyStrategy.CHARACTER);
registry.registerForPlayers(ACCESSORY_HARDCORE_CHECK, player -> new SyncedBooleanComponent("addedHardcoreSlot"), RespawnCopyStrategy.CHARACTER);
registry.registerForPlayers(ACCESSORY_DEMON_HEART_CHECK, player -> new SyncedBooleanComponent("addedDemonHeartSlot"), RespawnCopyStrategy.CHARACTER);
Expand Down
25 changes: 3 additions & 22 deletions src/main/java/terramine/common/network/ServerPacketHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,9 @@
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.client.multiplayer.ClientLevel;
import net.minecraft.core.NonNullList;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.particles.SimpleParticleType;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvent;
Expand Down Expand Up @@ -49,7 +47,6 @@ public class ServerPacketHandler {
// Client
public static final ResourceLocation SETUP_INVENTORY_PACKET_ID = TerraMine.id("setup_inventory");
public static final ResourceLocation UPDATE_INVENTORY_PACKET_ID = TerraMine.id("update_inventory");
public static final ResourceLocation SETUP_ACCESSORY_VISIBILITY_PACKET_ID = TerraMine.id("setup_accessory_visibility");

// Both
public static final ResourceLocation UPDATE_ACCESSORY_VISIBILITY_PACKET_ID = TerraMine.id("update_accessory_visibility");
Expand Down Expand Up @@ -148,10 +145,7 @@ public static void register() {
ServerPlayNetworking.registerGlobalReceiver(UPDATE_ACCESSORY_VISIBILITY_PACKET_ID, (server, player, handler, buf, responseSender) -> {
int slot = buf.readInt();
boolean isVisible = buf.readBoolean();
server.execute(() -> {
ModComponents.ACCESSORY_VISIBILITY.get(player).setSlotVisibility(slot, isVisible);
ModComponents.ACCESSORY_VISIBILITY.sync(player);
});
server.execute(() -> ((PlayerStorages) player).setSlotVisibility(slot, isVisible));
});
}

Expand Down Expand Up @@ -182,22 +176,9 @@ public static void registerClient() {
boolean isVisible = buffer.readBoolean();
UUID uuid = buffer.readUUID();
client.execute(() -> {
ModComponents.ACCESSORY_VISIBILITY.get(client.level.getPlayerByUUID(uuid)).setSlotVisibility(slot, isVisible);
ModComponents.ACCESSORY_VISIBILITY.sync(client.level.getPlayerByUUID(uuid));
});
});

ClientPlayNetworking.registerGlobalReceiver(SETUP_ACCESSORY_VISIBILITY_PACKET_ID, (client, handler, buffer, responseSender) -> {
List<Boolean> visibility = Lists.newArrayList();
for (int i = 0; i < 7; i++) {
visibility.add(buffer.readBoolean());
}
UUID uuid = buffer.readUUID();
client.execute(() -> {
for (int i = 0; i < visibility.size(); i++) {
ModComponents.ACCESSORY_VISIBILITY.get(client.level.getPlayerByUUID(uuid)).setSlotVisibility(i, visibility.get(i));
if (client.level.getPlayerByUUID(uuid) != null) {
((PlayerStorages) client.level.getPlayerByUUID(uuid)).setSlotVisibility(slot, isVisible);
}
ModComponents.ACCESSORY_VISIBILITY.sync(client.level.getPlayerByUUID(uuid));
});
});

Expand Down
4 changes: 4 additions & 0 deletions src/main/java/terramine/extensions/PlayerStorages.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,13 @@ public interface PlayerStorages {

SimpleContainer getSafeInventory();

boolean getSlotVisibility(int slot);

void setTerrariaInventory(TerrariaInventory terrariaInventory);

void setPiggyBankInventory(SimpleContainer piggyBankInventory);

void setSafeInventory(SimpleContainer safeInventory);

void setSlotVisibility(int slot, boolean visible);
}
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ private static void renderArm(PoseStack matrixStack, MultiBufferSource buffer, i
}

for (int i = 0; i < allEquippedGloves.size(); i++) {
if (!ModComponents.ACCESSORY_VISIBILITY.get(player).getSlotVisibility(i)) {
if (!((PlayerStorages) player).getSlotVisibility(i)) {
continue;
}
ItemStack stack = allEquippedGloves.get(i);
Expand Down
38 changes: 0 additions & 38 deletions src/main/java/terramine/mixin/player/PlayerListMixin.java

This file was deleted.

Loading

0 comments on commit 9ad4380

Please sign in to comment.