1.2.6
SorceryCraft/pipeline/head This commit looks good Details

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
**1.2.6**
* Fix Potential Client-Server De-sync Bug
**1.2.5**
* Fix Casting Table Bug

View File

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

View File

@ -21,9 +21,9 @@ import net.minecraft.util.math.MathHelper;
@Environment(EnvType.CLIENT)
public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler> {
private static final Identifier TEXTURE = new Identifier("textures/gui/container/villager2.png");
private int selectedIndex;
private int indexStartOffset;
private boolean scrolling;
private int selectedIndex = 0;
private int indexStartOffset = 0;
private boolean scrolling = false;
public CastingTableScreen(CastingTableScreenHandler container, PlayerInventory inventory, Text title) {
super(container, inventory, title);
@ -40,6 +40,11 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
renderXPCost();
}
public void resetIndex() {
selectedIndex = 0;
indexStartOffset = 0;
}
@Override
protected void drawBackground(float delta, int mouseX, int mouseY) {
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) {
if (player.isCreative() ? SorceryCraft.getConfig().limitCastingTable.creative : SorceryCraft.getConfig().limitCastingTable.survival) {
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
@ -125,8 +130,7 @@ public class CastingTableScreenHandler extends ScreenHandler {
} else {
spells = SpellRegistry.getSpells();
}
index = 0;
onContentChanged(inventory);
resetIndex();
}
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;
@SuppressWarnings("unused")
@Environment(EnvType.CLIENT)
@Mixin(ClientPlayNetworkHandler.class)
public class MixinClientPlayNetworkHandler {
@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.SpellPlayerEntity;
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.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
@ -16,6 +18,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import java.util.Map;
@SuppressWarnings("unused")
@Environment(EnvType.SERVER)
@Mixin(ServerPlayerEntity.class)
public abstract class MixinServerPlayerEntity extends MixinPlayerEntity implements SpellServerPlayerEntity {
@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.SpellHelper;
import io.netty.buffer.Unpooled;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.network.PacketContext;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf;
@ -12,6 +14,7 @@ import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier;
public class UpdateKnownSpellsS2CPacket {
@Environment(EnvType.CLIENT)
public static void handle(PacketContext context, PacketByteBuf bytes) {
CompoundTag tag = bytes.readCompoundTag();
if (context.getPlayer() != null) {

View File

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