Skip to content

Commit

Permalink
Fix accidental double toggle of ring of loki (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
minecraft7771 authored Dec 29, 2022
1 parent 54f7939 commit 09ccf50
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -141,8 +141,8 @@ public void onPlayerInteract(PlayerInteractEvent event) {
}
}
}
public static void toggleMode(ItemStack stack) {
stack.stackTagCompound.setBoolean(TAG_MODE, !isRingEnabled(stack));
public static void setMode(ItemStack stack, boolean state) {
stack.stackTagCompound.setBoolean(TAG_MODE, state);
}
@SideOnly(Side.CLIENT)
public static void renderHUDNotification(){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
import cpw.mods.fml.common.network.simpleimpl.MessageContext;

public class PacketLokiToggle implements IMessage, IMessageHandler<PacketLokiToggle, IMessage> {

@Override
public void fromBytes(ByteBuf byteBuf) {
// not needed
Expand All @@ -26,8 +25,11 @@ public IMessage onMessage(PacketLokiToggle message, MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
final ItemStack aRing = ItemLokiRing.getLokiRing(player);
if (aRing != null) {
ItemLokiRing.toggleMode(aRing);
PacketHandler.INSTANCE.sendTo(new PacketLokiToggleAck(), player);
boolean ringState = !ItemLokiRing.isRingEnabled(aRing);
ItemLokiRing.setMode(aRing, ringState);
PacketLokiToggleAck ackMessage = new PacketLokiToggleAck();
ackMessage.state = ringState;
PacketHandler.INSTANCE.sendTo(ackMessage, player);
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package vazkii.botania.common.network;

import cpw.mods.fml.common.network.ByteBufUtils;
import io.netty.buffer.ByteBuf;

import net.minecraft.client.Minecraft;
Expand All @@ -13,14 +14,16 @@

public class PacketLokiToggleAck implements IMessage, IMessageHandler<PacketLokiToggleAck, IMessage> {

public boolean state;

@Override
public void fromBytes(ByteBuf byteBuf) {
// not needed
state = byteBuf.readBoolean();
}

@Override
public void toBytes(ByteBuf byteBuf) {
// not needed
byteBuf.writeBoolean(state);
}

@SideOnly(Side.CLIENT)
Expand All @@ -29,7 +32,7 @@ public IMessage onMessage(PacketLokiToggleAck message, MessageContext ctx) {
Minecraft mc = Minecraft.getMinecraft();
final ItemStack aRing = ItemLokiRing.getLokiRing(mc.thePlayer) ;
if (aRing != null) {
ItemLokiRing.toggleMode(aRing);
ItemLokiRing.setMode(aRing, message.state);
ItemLokiRing.renderHUDNotification();
}

Expand Down

0 comments on commit 09ccf50

Please sign in to comment.