1.2.6
All checks were successful
SorceryCraft/pipeline/head This commit looks good

Fix Potential Client-Server De-sync Bug
This commit is contained in:
TheBrokenRail 2020-03-24 15:29:41 -04:00
parent fb3ba1411f
commit 8ca4986714
9 changed files with 56 additions and 8 deletions

View File

@ -1,5 +1,8 @@
# Changelog # Changelog
**1.2.6**
* Fix Potential Client-Server De-sync Bug
**1.2.5** **1.2.5**
* Fix Casting Table Bug * Fix Casting Table Bug

View File

@ -10,7 +10,7 @@ org.gradle.jvmargs = -Xmx1G
fabric_loader_version = 0.7.8+build.189 fabric_loader_version = 0.7.8+build.189
# Mod Properties # Mod Properties
mod_version = 1.2.5 mod_version = 1.2.6
maven_group = com.thebrokenrail maven_group = com.thebrokenrail
archives_base_name = sorcerycraft archives_base_name = sorcerycraft

View File

@ -21,9 +21,9 @@ import net.minecraft.util.math.MathHelper;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler> { public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler> {
private static final Identifier TEXTURE = new Identifier("textures/gui/container/villager2.png"); private static final Identifier TEXTURE = new Identifier("textures/gui/container/villager2.png");
private int selectedIndex; private int selectedIndex = 0;
private int indexStartOffset; private int indexStartOffset = 0;
private boolean scrolling; private boolean scrolling = false;
public CastingTableScreen(CastingTableScreenHandler container, PlayerInventory inventory, Text title) { public CastingTableScreen(CastingTableScreenHandler container, PlayerInventory inventory, Text title) {
super(container, inventory, title); super(container, inventory, title);
@ -40,6 +40,11 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
renderXPCost(); renderXPCost();
} }
public void resetIndex() {
selectedIndex = 0;
indexStartOffset = 0;
}
@Override @Override
protected void drawBackground(float delta, int mouseX, int mouseY) { protected void drawBackground(float delta, int mouseX, int mouseY) {
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);

View File

@ -109,6 +109,11 @@ public class CastingTableScreenHandler extends ScreenHandler {
} }
} }
private void resetIndex() {
index = 0;
onContentChanged(inventory);
}
public void setSpells(PlayerEntity player) { public void setSpells(PlayerEntity player) {
if (player.isCreative() ? SorceryCraft.getConfig().limitCastingTable.creative : SorceryCraft.getConfig().limitCastingTable.survival) { if (player.isCreative() ? SorceryCraft.getConfig().limitCastingTable.creative : SorceryCraft.getConfig().limitCastingTable.survival) {
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player; SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
@ -125,8 +130,7 @@ public class CastingTableScreenHandler extends ScreenHandler {
} else { } else {
spells = SpellRegistry.getSpells(); spells = SpellRegistry.getSpells();
} }
index = 0; resetIndex();
onContentChanged(inventory);
} }
public boolean canTakeResult(PlayerEntity playerEntity) { public boolean canTakeResult(PlayerEntity playerEntity) {

View File

@ -16,6 +16,7 @@ import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Environment(EnvType.CLIENT)
@Mixin(ClientPlayNetworkHandler.class) @Mixin(ClientPlayNetworkHandler.class)
public class MixinClientPlayNetworkHandler { public class MixinClientPlayNetworkHandler {
@Shadow @Shadow

View File

@ -0,0 +1,28 @@
package com.thebrokenrail.sorcerycraft.mixin;
import com.thebrokenrail.sorcerycraft.client.gui.CastingTableScreen;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.network.ClientPlayerEntity;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import java.util.Map;
@SuppressWarnings("unused")
@Mixin(ClientPlayerEntity.class)
@Environment(EnvType.CLIENT)
public class MixinClientPlayerEntity extends MixinPlayerEntity {
@Shadow @Final protected MinecraftClient client;
@Override
public void setDiscoveredSpells(Map<Identifier, Integer> spells) {
super.setDiscoveredSpells(spells);
if (client.currentScreen instanceof CastingTableScreen) {
((CastingTableScreen) client.currentScreen).resetIndex();
}
}
}

View File

@ -5,6 +5,8 @@ import com.thebrokenrail.sorcerycraft.packet.UpdateKnownSpellsS2CPacket;
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper; import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity; import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
import com.thebrokenrail.sorcerycraft.spell.util.SpellServerPlayerEntity; import com.thebrokenrail.sorcerycraft.spell.util.SpellServerPlayerEntity;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -16,6 +18,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Map; import java.util.Map;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@Environment(EnvType.SERVER)
@Mixin(ServerPlayerEntity.class) @Mixin(ServerPlayerEntity.class)
public abstract class MixinServerPlayerEntity extends MixinPlayerEntity implements SpellServerPlayerEntity { public abstract class MixinServerPlayerEntity extends MixinPlayerEntity implements SpellServerPlayerEntity {
@Inject(at = @At("HEAD"), method = "copyFrom") @Inject(at = @At("HEAD"), method = "copyFrom")

View File

@ -4,6 +4,8 @@ import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity; import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper; import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.network.PacketContext; import net.fabricmc.fabric.api.network.PacketContext;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf; import net.minecraft.network.PacketByteBuf;
@ -12,6 +14,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public class UpdateKnownSpellsS2CPacket { public class UpdateKnownSpellsS2CPacket {
@Environment(EnvType.CLIENT)
public static void handle(PacketContext context, PacketByteBuf bytes) { public static void handle(PacketContext context, PacketByteBuf bytes) {
CompoundTag tag = bytes.readCompoundTag(); CompoundTag tag = bytes.readCompoundTag();
if (context.getPlayer() != null) { if (context.getPlayer() != null) {

View File

@ -6,9 +6,10 @@
"MixinClientPlayNetworkHandler" "MixinClientPlayNetworkHandler"
], ],
"mixins": [ "mixins": [
"CriterionRegistryHook",
"MixinClientPlayerEntity",
"MixinPlayerEntity", "MixinPlayerEntity",
"MixinServerPlayerEntity", "MixinServerPlayerEntity"
"CriterionRegistryHook"
], ],
"injectors": { "injectors": {
"defaultRequire": 1 "defaultRequire": 1