Skip to content

Commit

Permalink
Ritual of Gaia's Transformation fixes. (#49)
Browse files Browse the repository at this point in the history
* Added server->client notification of biome change.

* Fix floating point inaccuracy.

* Replaced inefficient search algorithm.

* Move structure initialization out of a loop. Oops.

* update bs+deps+gardle

* fix wci

* one more

* Always send full 32 bytes with every message.

---------

Co-authored-by: Martin Robertz <[email protected]>
  • Loading branch information
AbdielKavash and Dream-Master authored Jan 21, 2024
1 parent 3218730 commit ff2f889
Show file tree
Hide file tree
Showing 18 changed files with 295 additions and 80 deletions.
43 changes: 42 additions & 1 deletion src/main/java/WayofTime/alchemicalWizardry/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,48 @@

import WayofTime.alchemicalWizardry.api.items.ItemSpellMultiTool;
import WayofTime.alchemicalWizardry.api.spell.SpellParadigmTool;
import WayofTime.alchemicalWizardry.common.items.*;
import WayofTime.alchemicalWizardry.common.items.AWBaseItems;
import WayofTime.alchemicalWizardry.common.items.ActivationCrystal;
import WayofTime.alchemicalWizardry.common.items.AirScribeTool;
import WayofTime.alchemicalWizardry.common.items.ApprenticeBloodOrb;
import WayofTime.alchemicalWizardry.common.items.ArchmageBloodOrb;
import WayofTime.alchemicalWizardry.common.items.ArmourInhibitor;
import WayofTime.alchemicalWizardry.common.items.BlankSpell;
import WayofTime.alchemicalWizardry.common.items.BloodShard;
import WayofTime.alchemicalWizardry.common.items.BoundAxe;
import WayofTime.alchemicalWizardry.common.items.BoundPickaxe;
import WayofTime.alchemicalWizardry.common.items.BoundShovel;
import WayofTime.alchemicalWizardry.common.items.CheatyItem;
import WayofTime.alchemicalWizardry.common.items.CreativeDagger;
import WayofTime.alchemicalWizardry.common.items.DaggerOfSacrifice;
import WayofTime.alchemicalWizardry.common.items.DawnScribeTool;
import WayofTime.alchemicalWizardry.common.items.DemonPlacer;
import WayofTime.alchemicalWizardry.common.items.DemonicTelepositionFocus;
import WayofTime.alchemicalWizardry.common.items.DuskScribeTool;
import WayofTime.alchemicalWizardry.common.items.EarthScribeTool;
import WayofTime.alchemicalWizardry.common.items.EnergyBattery;
import WayofTime.alchemicalWizardry.common.items.EnergyBazooka;
import WayofTime.alchemicalWizardry.common.items.EnergyBlast;
import WayofTime.alchemicalWizardry.common.items.EnergySword;
import WayofTime.alchemicalWizardry.common.items.EnhancedTelepositionFocus;
import WayofTime.alchemicalWizardry.common.items.FireScribeTool;
import WayofTime.alchemicalWizardry.common.items.ItemAlchemyBase;
import WayofTime.alchemicalWizardry.common.items.ItemBloodLetterPack;
import WayofTime.alchemicalWizardry.common.items.ItemComplexSpellCrystal;
import WayofTime.alchemicalWizardry.common.items.ItemComponents;
import WayofTime.alchemicalWizardry.common.items.ItemDiabloKey;
import WayofTime.alchemicalWizardry.common.items.ItemIncense;
import WayofTime.alchemicalWizardry.common.items.ItemRitualDismantler;
import WayofTime.alchemicalWizardry.common.items.ItemRitualDiviner;
import WayofTime.alchemicalWizardry.common.items.LavaCrystal;
import WayofTime.alchemicalWizardry.common.items.LifeBucket;
import WayofTime.alchemicalWizardry.common.items.MagicianBloodOrb;
import WayofTime.alchemicalWizardry.common.items.MasterBloodOrb;
import WayofTime.alchemicalWizardry.common.items.ReinforcedTelepositionFocus;
import WayofTime.alchemicalWizardry.common.items.SacrificialDagger;
import WayofTime.alchemicalWizardry.common.items.TelepositionFocus;
import WayofTime.alchemicalWizardry.common.items.TranscendentBloodOrb;
import WayofTime.alchemicalWizardry.common.items.WaterScribeTool;
import WayofTime.alchemicalWizardry.common.items.armour.BoundArmour;
import WayofTime.alchemicalWizardry.common.items.armour.OmegaArmourEarth;
import WayofTime.alchemicalWizardry.common.items.armour.OmegaArmourFire;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package WayofTime.alchemicalWizardry.client.nei;

import java.awt.*;
import java.awt.Point;
import java.awt.Rectangle;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.Arrays;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package WayofTime.alchemicalWizardry.common;

import java.util.Arrays;
import java.util.BitSet;
import java.util.EnumMap;
import java.util.LinkedList;
import java.util.List;
Expand All @@ -10,6 +12,7 @@
import net.minecraft.network.Packet;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraft.world.chunk.Chunk;
import net.minecraftforge.common.util.ForgeDirection;

import WayofTime.alchemicalWizardry.AlchemicalWizardry;
Expand Down Expand Up @@ -77,6 +80,8 @@ private void addClientHandler() {
.addAfter(tileAltarCodec, "CurrentReagentBarMessageHandler", new CurrentReagentBarMessageHandler());
clientChannel.pipeline()
.addAfter(tileAltarCodec, "CurrentAddedHPMessageHandler", new CurrentAddedHPMessageHandler());
clientChannel.pipeline()
.addAfter(tileAltarCodec, "GaiaBiomeChangeHandler", new GaiaBiomeChangeMessageHandler());
}

@SideOnly(Side.SERVER)
Expand Down Expand Up @@ -283,6 +288,23 @@ protected void channelRead0(ChannelHandlerContext ctx, KeyboardMessage msg) thro
}
}

private static class GaiaBiomeChangeMessageHandler extends SimpleChannelInboundHandler<GaiaBiomeChangeMessage> {

@Override
protected void channelRead0(ChannelHandlerContext ctx, GaiaBiomeChangeMessage msg) throws Exception {
Chunk chunk = AlchemicalWizardry.proxy.getClientWorld().getChunkFromChunkCoords(msg.chunkX, msg.chunkZ);
if (chunk != null) {
byte[] biomeArray = chunk.getBiomeArray();
for (int i = 0; i < 16 * 16; ++i) {
if (msg.mask.get(i)) {
biomeArray[i] = msg.biome;
}
}
chunk.setBiomeArray(biomeArray);
}
}
}

public static class BMMessage {

int index;
Expand Down Expand Up @@ -417,6 +439,16 @@ public static class KeyboardMessage extends BMMessage {
byte keyPressed;
}

public static class GaiaBiomeChangeMessage extends BMMessage {

int chunkX;
int chunkZ;
byte biome;
BitSet mask;
// One bit per coordinate in a chunk, 16*16 bits = 32 bytes
public static final int maskByteCount = 32;
}

private class ClientToServerCodec extends FMLIndexedMessageToMessageCodec<BMMessage> {

public ClientToServerCodec() {}
Expand Down Expand Up @@ -458,6 +490,7 @@ public TEAltarCodec() {
addDiscriminator(12, CurrentReagentBarMessage.class);
addDiscriminator(13, CurrentAddedHPMessage.class);
addDiscriminator(14, KeyboardMessage.class);
addDiscriminator(15, GaiaBiomeChangeMessage.class);
}

@Override
Expand Down Expand Up @@ -669,6 +702,17 @@ public void encodeInto(ChannelHandlerContext ctx, BMMessage msg, ByteBuf target)

target.writeByte(((KeyboardMessage) msg).keyPressed);
break;

case 15:
target.writeInt(((GaiaBiomeChangeMessage) msg).chunkX);
target.writeInt(((GaiaBiomeChangeMessage) msg).chunkZ);
target.writeByte(((GaiaBiomeChangeMessage) msg).biome);
byte[] arr = Arrays.copyOf(
((GaiaBiomeChangeMessage) msg).mask.toByteArray(),
GaiaBiomeChangeMessage.maskByteCount);
target.writeBytes(arr);
break;

}
}

Expand Down Expand Up @@ -894,6 +938,16 @@ public void decodeInto(ChannelHandlerContext ctx, ByteBuf dat, BMMessage msg) {
System.out.println("Packet recieved: being decoded");
((KeyboardMessage) msg).keyPressed = dat.readByte();
break;

case 15:
((GaiaBiomeChangeMessage) msg).chunkX = dat.readInt();
((GaiaBiomeChangeMessage) msg).chunkZ = dat.readInt();
((GaiaBiomeChangeMessage) msg).biome = dat.readByte();

byte[] buffer = new byte[GaiaBiomeChangeMessage.maskByteCount];
dat.readBytes(buffer);
((GaiaBiomeChangeMessage) msg).mask = BitSet.valueOf(buffer);
break;
}
}
}
Expand Down Expand Up @@ -1067,6 +1121,17 @@ public static Packet getKeyboardPressPacket(byte bt) {
return INSTANCE.channels.get(Side.CLIENT).generatePacketFrom(msg);
}

public static Packet getGaiaBiomeChangePacket(int x, int z, byte biome, BitSet mask) {
GaiaBiomeChangeMessage msg = new GaiaBiomeChangeMessage();
msg.index = 15;
msg.chunkX = x;
msg.chunkZ = z;
msg.biome = biome;
msg.mask = mask;

return INSTANCE.channels.get(Side.SERVER).generatePacketFrom(msg);
}

public void sendTo(Packet message, EntityPlayerMP player) {
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
.set(FMLOutboundHandler.OutboundTarget.PLAYER);
Expand All @@ -1087,6 +1152,13 @@ public void sendToAllAround(Packet message, NetworkRegistry.TargetPoint point) {
this.channels.get(Side.SERVER).writeAndFlush(message);
}

public void sendToDimension(Packet message, Integer dimensionId) {
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGET)
.set(FMLOutboundHandler.OutboundTarget.DIMENSION);
this.channels.get(Side.SERVER).attr(FMLOutboundHandler.FML_MESSAGETARGETARGS).set(dimensionId);
this.channels.get(Side.SERVER).writeAndFlush(message);
}

public void sendToServer(Packet message) {
this.channels.get(Side.CLIENT).attr(FMLOutboundHandler.FML_MESSAGETARGET)
.set(FMLOutboundHandler.OutboundTarget.TOSERVER);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package WayofTime.alchemicalWizardry.common.commands;

import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import net.minecraft.command.CommandBase;
import net.minecraft.command.ICommandSender;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.*;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.passive.EntityHorse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,16 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.*;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILeapAtTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.passive.EntityHorse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
package WayofTime.alchemicalWizardry.common.entity.mob;

import net.minecraft.entity.*;
import net.minecraft.entity.ai.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IRangedAttackMob;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIArrowAttack;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.passive.EntityHorse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.*;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.passive.EntityHorse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.*;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.passive.EntityHorse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
package WayofTime.alchemicalWizardry.common.entity.mob;

import net.minecraft.entity.*;
import net.minecraft.entity.ai.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IRangedAttackMob;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIArrowAttack;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.passive.EntityHorse;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
package WayofTime.alchemicalWizardry.common.entity.mob;

import net.minecraft.entity.*;
import net.minecraft.entity.ai.*;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.IRangedAttackMob;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.ai.EntityAIArrowAttack;
import net.minecraft.entity.ai.EntityAIAttackOnCollide;
import net.minecraft.entity.ai.EntityAIFollowOwner;
import net.minecraft.entity.ai.EntityAIHurtByTarget;
import net.minecraft.entity.ai.EntityAILookIdle;
import net.minecraft.entity.ai.EntityAIOwnerHurtByTarget;
import net.minecraft.entity.ai.EntityAIOwnerHurtTarget;
import net.minecraft.entity.ai.EntityAISwimming;
import net.minecraft.entity.ai.EntityAIWander;
import net.minecraft.entity.ai.EntityAIWatchClosest;
import net.minecraft.entity.monster.EntityCreeper;
import net.minecraft.entity.monster.EntityGhast;
import net.minecraft.entity.passive.EntityHorse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,11 @@

import WayofTime.alchemicalWizardry.AlchemicalWizardry;
import WayofTime.alchemicalWizardry.api.Int3;
import WayofTime.alchemicalWizardry.api.alchemy.energy.*;
import WayofTime.alchemicalWizardry.api.alchemy.energy.IReagentHandler;
import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainerInfo;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentStack;
import WayofTime.alchemicalWizardry.api.items.interfaces.IReagentManipulator;
import WayofTime.alchemicalWizardry.common.tileEntity.TEReagentConduit;
import cpw.mods.fml.relauncher.Side;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
import net.minecraftforge.common.util.ForgeDirection;

import WayofTime.alchemicalWizardry.AlchemicalWizardry;
import WayofTime.alchemicalWizardry.api.alchemy.energy.*;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ISegmentedReagentHandler;
import WayofTime.alchemicalWizardry.api.alchemy.energy.Reagent;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentContainerInfo;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentRegistry;
import WayofTime.alchemicalWizardry.api.alchemy.energy.ReagentStack;
import WayofTime.alchemicalWizardry.api.items.interfaces.IReagentManipulator;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,11 @@
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.*;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.IFluidContainerItem;
import net.minecraftforge.fluids.IFluidHandler;

import WayofTime.alchemicalWizardry.AlchemicalWizardry;
import WayofTime.alchemicalWizardry.api.Int3;
Expand Down
Loading

0 comments on commit ff2f889

Please sign in to comment.