Skip to content

Commit

Permalink
Final changes before update 1.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
PT400C committed Sep 30, 2023
1 parent b4baa6e commit 8cc6306
Show file tree
Hide file tree
Showing 21 changed files with 187 additions and 185 deletions.
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
88 changes: 30 additions & 58 deletions src/main/java/net/jomcraft/frustrator/ClientEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
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;
Expand Down Expand Up @@ -53,8 +52,6 @@ public class ClientEventHandler {

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

//public static boolean isSneaking = false;

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 @@ -91,8 +88,7 @@ public void livingUpdate(LivingEvent.LivingUpdateEvent event) {
final FrustumBounds frustum = ((IMixinEntity) event.entity).getFrustum();

if (frustum != null) {
if (showAllMainAreas && frustum.channelID == currentChannelID)
return;
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 @@ -111,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 @@ -143,17 +138,14 @@ 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;

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

if (frustratorEquipped) {
// System.out.println("WTF!!");
final ItemStack stack = Minecraft.getMinecraft().thePlayer.getCurrentEquippedItem();
if(stack.hasTagCompound() && stack.getTagCompound().hasKey("channelID")){
// System.out.println(currentChannelID);
if (stack.hasTagCompound() && stack.getTagCompound().hasKey("channelID")) {
currentChannelID = stack.getTagCompound().getInteger("channelID");
} else {
currentChannelID = 0;
Expand All @@ -164,7 +156,7 @@ public void playerTick(TickEvent.PlayerTickEvent event) {
if (showAllMainAreas == false) {
for (int i = 0; i < frustumBounds.length; i++) {
FrustumBounds frustum = frustumBounds[i];
if(frustum.channelID == currentChannelID)
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);
}
}
Expand All @@ -177,7 +169,7 @@ public void playerTick(TickEvent.PlayerTickEvent event) {
if (showAllMainAreas == true) {
for (int i = 0; i < frustumBounds.length; i++) {
FrustumBounds frustum = frustumBounds[i];
if(frustum.channelID == currentChannelID)
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);
}
}
Expand All @@ -192,7 +184,7 @@ public void playerTick(TickEvent.PlayerTickEvent event) {
if (showAllMainAreas == true) {
for (int i = 0; i < frustumBounds.length; i++) {
FrustumBounds frustum = frustumBounds[i];
if(frustum.channelID == currentChannelID)
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);
}
}
Expand All @@ -201,30 +193,15 @@ public void playerTick(TickEvent.PlayerTickEvent event) {
showAllTriggerAreas = false;
}

if(currentChannelID != prevChannelID){
if (currentChannelID != prevChannelID) {
for (int i = 0; i < frustumBounds.length; i++) {
FrustumBounds frustum = frustumBounds[i];
if(frustum.channelID == currentChannelID || frustum.channelID == prevChannelID)
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(isSneaking != event.player.isSneaking()){
if (frustratorEquipped) {
for (int i = 0; i < frustumBounds.length; i++) {
FrustumBounds frustum = frustumBounds[i];
//if(event.player.isSneaking() ? 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);
}
}
}*/

//isSneaking = event.player.isSneaking();

if (event.player.ticksExisted % 2 == 0) {
// if (showAllMainAreas)
// return;

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 @@ -235,7 +212,7 @@ public void playerTick(TickEvent.PlayerTickEvent event) {

for (int i = 0; i < frustumBounds.length; i++) {
final FrustumBounds frustum = frustumBounds[i];
if(showAllMainAreas && frustum.channelID == currentChannelID){
if (showAllMainAreas && frustum.channelID == currentChannelID) {
continue;
}
if (frustumCheck(x, y, z, frustum)) {
Expand All @@ -253,7 +230,7 @@ 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){
if (showAllMainAreas && parent.channelID == currentChannelID) {
continue;
}
if (!localFrustums.contains(parent)) {
Expand Down Expand Up @@ -291,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 @@ -310,9 +286,8 @@ public void renderWorldLast(RenderWorldLastEvent e) {
if (showAllMainAreas) {
for (int i = 0; i < frustumBounds.length; i++) {
final FrustumBounds frustum = frustumBounds[i];
if(frustum.channelID == currentChannelID || player.isSneaking()) {
if (frustum == focusedFrustum || frustum == selectedFrustum)
GL11.glLineWidth(6.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);
Expand All @@ -323,9 +298,8 @@ public void renderWorldLast(RenderWorldLastEvent e) {
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.channelID == currentChannelID || player.isSneaking()) {
if (frustum == focusedTrigger || frustum == selectedTrigger)
GL11.glLineWidth(6.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);
Expand All @@ -344,26 +318,24 @@ public void renderWorldLast(RenderWorldLastEvent e) {
for (int i = 0; i < triggerBounds.length; i++) {

final FrustumBounds frustum = triggerBounds[i];
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 (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
5 changes: 3 additions & 2 deletions src/main/java/net/jomcraft/frustrator/CommonEventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

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;
Expand Down Expand Up @@ -32,7 +31,8 @@ public void playerChangedDimension(PlayerEvent.PlayerChangedDimensionEvent event
} else {
channels = new HashMap<Integer, String>();
}
Frustrator.network.sendTo(new S2CSyncChannels(channels), (EntityPlayerMP) event.player);

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

@SubscribeEvent
Expand All @@ -51,6 +51,7 @@ public void playerLoggedIn(PlayerEvent.PlayerLoggedInEvent event) {
} else {
channels = new HashMap<Integer, String>();
}

Frustrator.network.sendTo(new S2CSyncChannels(channels), (EntityPlayerMP) event.player);
}
}
5 changes: 1 addition & 4 deletions src/main/java/net/jomcraft/frustrator/FrustumBounds.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
package net.jomcraft.frustrator;

import com.google.gson.annotations.SerializedName;

import javax.annotation.Nullable;
import java.util.Arrays;

Expand Down Expand Up @@ -38,8 +36,7 @@ public FrustumBounds(final int minX, final int minY, final int minZ, final int m
}

public boolean equalsArea(FrustumBounds frustum) {
if (frustum == null)
return false;
if (frustum == null) return false;
if (frustum.minX == this.minX && frustum.minY == this.minY && frustum.minZ == this.minZ && frustum.maxX == this.maxX && frustum.maxY == this.maxY && frustum.maxZ == this.maxZ)
return true;

Expand Down
Loading

0 comments on commit 8cc6306

Please sign in to comment.