Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Final update to release 1.1.0 #3

Merged
merged 4 commits into from
Sep 30, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions changelog.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<h3>Latest release v1.1.0</h3>
<ul>
<li><b>Added: Frustrator command to manage multiple item channelIDs to group main/trigger areas</b></li>
<li><b>Fixed: Multiplayer with multiple online players was broken</b></li>
</ul>
<br>
Expand Down
111 changes: 70 additions & 41 deletions src/main/java/net/jomcraft/frustrator/ClientEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityClientPlayerMP;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatStyle;
Expand All @@ -17,8 +18,8 @@
import org.lwjgl.opengl.GL11;

import javax.annotation.Nullable;
import java.sql.Array;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

public class ClientEventHandler {
Expand All @@ -41,11 +42,16 @@ public class ClientEventHandler {

@Nullable
public static FrustumBounds selectedFrustum = null;

public static int currentChannelID = -1;

public static boolean showAllMainAreas = false;
public static boolean showAllTriggerAreas = false;

public static final ChatStyle style = new ChatStyle();

public static HashMap<Integer, String> channelMap = null;

public static boolean frustumCheck(final int x, final int y, final int z, final FrustumBounds frustum) {
if ((x >= frustum.minX && x <= (frustum.maxX)) && (y >= frustum.minY && y <= (frustum.maxY)) && (z >= frustum.minZ && z <= (frustum.maxZ))) {
return true;
Expand Down Expand Up @@ -78,11 +84,11 @@ public void entityJoinWorld(EntityJoinWorldEvent event) {
@SubscribeEvent
public void livingUpdate(LivingEvent.LivingUpdateEvent event) {
if (event.entity.worldObj.isRemote) {
if (showAllMainAreas)
return;

final FrustumBounds frustum = ((IMixinEntity) event.entity).getFrustum();

if (frustum != null) {
if (showAllMainAreas && frustum.channelID == currentChannelID) return;
boolean success = false;
for (int ii = 0; ii < ClientEventHandler.localFrustums.size(); ii++) {
final FrustumBounds localFrustum = ClientEventHandler.localFrustums.get(ii);
Expand All @@ -101,8 +107,7 @@ public void livingUpdate(LivingEvent.LivingUpdateEvent event) {

@SubscribeEvent
public void clientTick(TickEvent.ClientTickEvent event) {
if (Minecraft.getMinecraft().theWorld == null)
return;
if (Minecraft.getMinecraft().theWorld == null) return;

if (event.phase == TickEvent.Phase.START) {
final List tileEntityList = Minecraft.getMinecraft().theWorld.loadedTileEntityList;
Expand Down Expand Up @@ -133,28 +138,39 @@ public void clientTick(TickEvent.ClientTickEvent event) {
@SubscribeEvent
public void playerTick(TickEvent.PlayerTickEvent event) {
if (event.phase == TickEvent.Phase.START && event.player.worldObj.isRemote) {
if (event.player != Minecraft.getMinecraft().thePlayer)
return;
if (event.player != Minecraft.getMinecraft().thePlayer) return;
int prevChannelID = currentChannelID;

if (Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem() != null && Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getItem() instanceof ItemFrustrator) {
boolean frustratorEquipped = Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem() != null && Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getItem() instanceof ItemFrustrator;

if (frustratorEquipped) {
final ItemStack stack = Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem();
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("channelID")) {
currentChannelID = stack.getTagCompound().getInteger("channelID");
} else {
currentChannelID = 0;
}

if (Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getItemDamage() == 0) {
if (selectedFrustum == null) {
if (showAllMainAreas == false) {
for (int i = 0; i < frustumBounds.length; i++) {
FrustumBounds frustum = frustumBounds[i];
Minecraft.getMinecraft().renderGlobal.markBlocksForUpdate(frustum.minX - 1, frustum.minY - 1, frustum.minZ - 1, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1);
if (frustum.channelID == currentChannelID)
Minecraft.getMinecraft().renderGlobal.markBlocksForUpdate(frustum.minX - 1, frustum.minY - 1, frustum.minZ - 1, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1);
}
}
showAllMainAreas = true;
}
showAllTriggerAreas = false;

} else if (Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem().getItemDamage() == 1) {
if (selectedFrustum == null) {
if (showAllMainAreas == true) {
for (int i = 0; i < frustumBounds.length; i++) {
FrustumBounds frustum = frustumBounds[i];
Minecraft.getMinecraft().renderGlobal.markBlocksForUpdate(frustum.minX - 1, frustum.minY - 1, frustum.minZ - 1, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1);
if (frustum.channelID == currentChannelID)
Minecraft.getMinecraft().renderGlobal.markBlocksForUpdate(frustum.minX - 1, frustum.minY - 1, frustum.minZ - 1, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1);
}
}
showAllMainAreas = false;
Expand All @@ -163,22 +179,29 @@ public void playerTick(TickEvent.PlayerTickEvent event) {
}

} else {
currentChannelID = -1;
if (selectedFrustum == null) {
if (showAllMainAreas == true) {
for (int i = 0; i < frustumBounds.length; i++) {
FrustumBounds frustum = frustumBounds[i];
Minecraft.getMinecraft().renderGlobal.markBlocksForUpdate(frustum.minX - 1, frustum.minY - 1, frustum.minZ - 1, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1);
if (frustum.channelID == currentChannelID)
Minecraft.getMinecraft().renderGlobal.markBlocksForUpdate(frustum.minX - 1, frustum.minY - 1, frustum.minZ - 1, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1);
}
}
showAllMainAreas = false;
}
showAllTriggerAreas = false;
}

if (event.player.ticksExisted % 2 == 0) {
if (showAllMainAreas)
return;
if (currentChannelID != prevChannelID) {
for (int i = 0; i < frustumBounds.length; i++) {
FrustumBounds frustum = frustumBounds[i];
if (frustum.channelID == currentChannelID || frustum.channelID == prevChannelID)
Minecraft.getMinecraft().renderGlobal.markBlocksForUpdate(frustum.minX - 1, frustum.minY - 1, frustum.minZ - 1, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1);
}
}

if (event.player.ticksExisted % 2 == 0) {
final int x = MathHelper.floor_double(event.player.posX);
final int y = MathHelper.floor_double(event.player.posY);
final int z = MathHelper.floor_double(event.player.posZ);
Expand All @@ -189,6 +212,9 @@ public void playerTick(TickEvent.PlayerTickEvent event) {

for (int i = 0; i < frustumBounds.length; i++) {
final FrustumBounds frustum = frustumBounds[i];
if (showAllMainAreas && frustum.channelID == currentChannelID) {
continue;
}
if (frustumCheck(x, y, z, frustum)) {
if (!localFrustums.contains(frustum)) {
Minecraft.getMinecraft().renderGlobal.markBlocksForUpdate(frustum.minX - 1, frustum.minY - 1, frustum.minZ - 1, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1);
Expand All @@ -204,6 +230,9 @@ public void playerTick(TickEvent.PlayerTickEvent event) {
if (frustumCheck(x, y, z, trigger)) {
for (int ii = 0; ii < trigger.parents.length; ii++) {
final FrustumBounds parent = trigger.parents[ii];
if (showAllMainAreas && parent.channelID == currentChannelID) {
continue;
}
if (!localFrustums.contains(parent)) {
Minecraft.getMinecraft().renderGlobal.markBlocksForUpdate(parent.minX - 1, parent.minY - 1, parent.minZ - 1, parent.maxX + 1, parent.maxY + 1, parent.maxZ + 1);
}
Expand Down Expand Up @@ -239,7 +268,6 @@ public void playerTick(TickEvent.PlayerTickEvent event) {
@SubscribeEvent
public void renderWorldLast(RenderWorldLastEvent e) {
final EntityClientPlayerMP player = Minecraft.getMinecraft().thePlayer;

GL11.glPushMatrix();
GL11.glEnable(GL11.GL_BLEND);
OpenGlHelper.glBlendFunc(770, 771, 1, 0);
Expand All @@ -258,22 +286,24 @@ public void renderWorldLast(RenderWorldLastEvent e) {
if (showAllMainAreas) {
for (int i = 0; i < frustumBounds.length; i++) {
final FrustumBounds frustum = frustumBounds[i];
if (frustum == focusedFrustum || frustum == selectedFrustum)
GL11.glLineWidth(6.0F);
ab = AxisAlignedBB.getBoundingBox(frustum.minX, frustum.minY, frustum.minZ, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1).getOffsetBoundingBox(-d0, -d1, -d2);
Minecraft.getMinecraft().renderGlobal.drawOutlinedBoundingBox(ab, -1);
GL11.glLineWidth(3.0F);
if (frustum.channelID == currentChannelID || player.isSneaking()) {
if (frustum == focusedFrustum || frustum == selectedFrustum) GL11.glLineWidth(6.0F);
ab = AxisAlignedBB.getBoundingBox(frustum.minX, frustum.minY, frustum.minZ, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1).getOffsetBoundingBox(-d0, -d1, -d2);
Minecraft.getMinecraft().renderGlobal.drawOutlinedBoundingBox(ab, -1);
GL11.glLineWidth(3.0F);
}
}
}
if (showAllTriggerAreas || selectedTrigger != null) {
GL11.glColor4f(1.0F, 1.0F, 0.0F, 0.8F);
for (int i = 0; i < triggerBounds.length; i++) {
final FrustumBounds frustum = triggerBounds[i];
if (frustum == focusedTrigger || frustum == selectedTrigger)
GL11.glLineWidth(6.0F);
ab = AxisAlignedBB.getBoundingBox(frustum.minX, frustum.minY, frustum.minZ, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1).getOffsetBoundingBox(-d0, -d1, -d2);
Minecraft.getMinecraft().renderGlobal.drawOutlinedBoundingBox(ab, -1);
GL11.glLineWidth(3.0F);
if (frustum.channelID == currentChannelID || player.isSneaking()) {
if (frustum == focusedTrigger || frustum == selectedTrigger) GL11.glLineWidth(6.0F);
ab = AxisAlignedBB.getBoundingBox(frustum.minX, frustum.minY, frustum.minZ, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1).getOffsetBoundingBox(-d0, -d1, -d2);
Minecraft.getMinecraft().renderGlobal.drawOutlinedBoundingBox(ab, -1);
GL11.glLineWidth(3.0F);
}
}
GL11.glColor4f(1.0F, 0.0F, 0.0F, 0.8F);
}
Expand All @@ -288,25 +318,24 @@ public void renderWorldLast(RenderWorldLastEvent e) {
for (int i = 0; i < triggerBounds.length; i++) {

final FrustumBounds frustum = triggerBounds[i];

boolean isTrigger = false;

for (int ii = 0; ii < frustum.parents.length; ii++) {
final FrustumBounds parent = frustum.parents[ii];
if (parent.equalsArea(selectedFrustum)) {
isTrigger = true;
break;
if (frustum.channelID == currentChannelID || player.isSneaking()) {
boolean isTrigger = false;

for (int ii = 0; ii < frustum.parents.length; ii++) {
final FrustumBounds parent = frustum.parents[ii];
if (parent.equalsArea(selectedFrustum)) {
isTrigger = true;
break;
}
}
}

if (!isTrigger)
continue;
if (!isTrigger) continue;

if (frustum == focusedTrigger || frustum == selectedTrigger)
GL11.glLineWidth(6.0F);
ab = AxisAlignedBB.getBoundingBox(frustum.minX, frustum.minY, frustum.minZ, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1).getOffsetBoundingBox(-d0, -d1, -d2);
Minecraft.getMinecraft().renderGlobal.drawOutlinedBoundingBox(ab, -1);
GL11.glLineWidth(3.0F);
if (frustum == focusedTrigger || frustum == selectedTrigger) GL11.glLineWidth(6.0F);
ab = AxisAlignedBB.getBoundingBox(frustum.minX, frustum.minY, frustum.minZ, frustum.maxX + 1, frustum.maxY + 1, frustum.maxZ + 1).getOffsetBoundingBox(-d0, -d1, -d2);
Minecraft.getMinecraft().renderGlobal.drawOutlinedBoundingBox(ab, -1);
GL11.glLineWidth(3.0F);
}
}
GL11.glColor4f(1.0F, 0.0F, 0.0F, 0.8F);
}
Expand Down
28 changes: 24 additions & 4 deletions src/main/java/net/jomcraft/frustrator/CommonEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.PlayerEvent;
import cpw.mods.fml.common.network.FMLNetworkEvent;
import net.jomcraft.frustrator.network.S2CClearSelection;
import net.jomcraft.frustrator.network.S2CSyncAllAreas;
import net.jomcraft.frustrator.network.S2CSyncChannels;
import net.jomcraft.frustrator.storage.FileManager;
import net.minecraft.entity.player.EntityPlayerMP;

Expand All @@ -17,21 +17,41 @@ public class CommonEventHandler {
public void playerChangedDimension(PlayerEvent.PlayerChangedDimensionEvent event) {
Frustrator.network.sendTo(new S2CClearSelection(), (EntityPlayerMP) event.player);
final HashMap<Integer, ArrayList<FrustumBounds>> dimMap = FileManager.getFrustumJSON().getFrustumMap();
final HashMap<Integer, HashMap<Integer, String>> channelMap = FileManager.getFrustumJSON().getChannelMap();
if (dimMap.containsKey(event.player.worldObj.provider.dimensionId)) {
ArrayList<FrustumBounds> bounds = dimMap.get(event.player.worldObj.provider.dimensionId);
Frustrator.network.sendToAll(new S2CSyncAllAreas(bounds.toArray(new FrustumBounds[bounds.size()]), false, null, null));
Frustrator.network.sendTo(new S2CSyncAllAreas(bounds.toArray(new FrustumBounds[bounds.size()]), false, null, null), (EntityPlayerMP) event.player);
} else {
Frustrator.network.sendToAll(new S2CSyncAllAreas(new FrustumBounds[0], false, null, null));
Frustrator.network.sendTo(new S2CSyncAllAreas(new FrustumBounds[0], false, null, null), (EntityPlayerMP) event.player);
}

HashMap<Integer, String> channels;
if (channelMap.containsKey(event.player.worldObj.provider.dimensionId)) {
channels = channelMap.get(event.player.worldObj.provider.dimensionId);
} else {
channels = new HashMap<Integer, String>();
}

Frustrator.network.sendTo(new S2CSyncChannels(channels), (EntityPlayerMP) event.player);
}

@SubscribeEvent
public void playerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
final HashMap<Integer, ArrayList<FrustumBounds>> dimMap = FileManager.getFrustumJSON().getFrustumMap();
final HashMap<Integer, HashMap<Integer, String>> channelMap = FileManager.getFrustumJSON().getChannelMap();
Frustrator.network.sendTo(new S2CClearSelection(), (EntityPlayerMP) event.player);
if (dimMap.containsKey(event.player.worldObj.provider.dimensionId)) {
ArrayList<FrustumBounds> bounds = dimMap.get(event.player.worldObj.provider.dimensionId);
Frustrator.network.sendToAll(new S2CSyncAllAreas(bounds.toArray(new FrustumBounds[bounds.size()]), false, null, null));
Frustrator.network.sendTo(new S2CSyncAllAreas(bounds.toArray(new FrustumBounds[bounds.size()]), false, null, null), (EntityPlayerMP) event.player);
}

HashMap<Integer, String> channels;
if (channelMap.containsKey(event.player.worldObj.provider.dimensionId)) {
channels = channelMap.get(event.player.worldObj.provider.dimensionId);
} else {
channels = new HashMap<Integer, String>();
}

Frustrator.network.sendTo(new S2CSyncChannels(channels), (EntityPlayerMP) event.player);
}
}
9 changes: 7 additions & 2 deletions src/main/java/net/jomcraft/frustrator/Frustrator.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
import net.jomcraft.frustrator.command.CommandFrustrator;
import net.jomcraft.frustrator.network.*;
import net.jomcraft.frustrator.proxy.ServerProxy;
import net.jomcraft.frustrator.storage.FileManager;
import net.minecraft.command.ICommand;
import net.minecraftforge.common.MinecraftForge;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -41,6 +43,7 @@ public Frustrator() {

@EventHandler
public void serverStarting(FMLServerStartingEvent event) {
event.registerServerCommand((ICommand) new CommandFrustrator());
FileManager.initialize();
}

Expand Down Expand Up @@ -69,8 +72,10 @@ public static void construction(FMLPreInitializationEvent event) {
network.registerMessage(C2SDeleteAreaPacket.Handler.class, C2SDeleteAreaPacket.class, 1, Side.SERVER);
network.registerMessage(C2SResizeAreaPacket.Handler.class, C2SResizeAreaPacket.class, 2, Side.SERVER);
network.registerMessage(C2SAddTriggerPacket.Handler.class, C2SAddTriggerPacket.class, 3, Side.SERVER);
network.registerMessage(S2CSyncAllAreas.Handler.class, S2CSyncAllAreas.class, 4, Side.CLIENT);
network.registerMessage(S2CClearSelection.Handler.class, S2CClearSelection.class, 5, Side.CLIENT);
network.registerMessage(C2SChangeChannelPacket.Handler.class, C2SChangeChannelPacket.class, 4, Side.SERVER);
network.registerMessage(S2CSyncAllAreas.Handler.class, S2CSyncAllAreas.class, 5, Side.CLIENT);
network.registerMessage(S2CClearSelection.Handler.class, S2CClearSelection.class, 6, Side.CLIENT);
network.registerMessage(S2CSyncChannels.Handler.class, S2CSyncChannels.class, 7, Side.CLIENT);
}

@EventHandler
Expand Down
Loading