even more radar stuff

This commit is contained in:
Boblet 2023-11-14 15:22:35 +01:00 committed by Bob
parent 089b390708
commit c47e96c3cd
4 changed files with 120 additions and 9 deletions

View File

@ -0,0 +1,63 @@
package com.hbm.inventory.gui;
import java.util.Arrays;
import org.lwjgl.opengl.GL11;
import com.hbm.lib.RefStrings;
import com.hbm.tileentity.machine.TileEntityMachineRadarNT;
import com.hbm.util.I18nUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.util.ResourceLocation;
public class GUIMachineRadarNT extends GuiScreen {
protected static final ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/machine/gui_radar_nt.png");
protected TileEntityMachineRadarNT radar;
protected int xSize = 216;
protected int ySize = 234;
protected int guiLeft;
protected int guiTop;
public GUIMachineRadarNT(TileEntityMachineRadarNT tile) {
this.radar = tile;
}
@Override
public void initGui() {
super.initGui();
this.guiLeft = (this.width - this.xSize) / 2;
this.guiTop = (this.height - this.ySize) / 2;
}
@Override
public void drawScreen(int mouseX, int mouseY, float f) {
this.drawDefaultBackground();
this.drawGuiContainerBackgroundLayer(f, mouseX, mouseY);
GL11.glDisable(GL11.GL_LIGHTING);
this.drawGuiContainerForegroundLayer(mouseX, mouseY);
GL11.glEnable(GL11.GL_LIGHTING);
}
private void drawGuiContainerForegroundLayer(int x, int y) {
if(checkClick(x, y, -10, 88, 8, 8)) this.func_146283_a(Arrays.asList(I18nUtil.resolveKeyArray("radar.detectMissiles")), x, y);
if(checkClick(x, y, -10, 98, 8, 8)) this.func_146283_a(Arrays.asList(I18nUtil.resolveKeyArray("radar.detectShells")), x, y);
if(checkClick(x, y, -10, 108, 8, 8)) this.func_146283_a(Arrays.asList(I18nUtil.resolveKeyArray("radar.detectPlayers")), x, y);
if(checkClick(x, y, -10, 118, 8, 8)) this.func_146283_a(Arrays.asList(I18nUtil.resolveKeyArray("radar.smartMode")), x, y);
if(checkClick(x, y, -10, 128, 8, 8)) this.func_146283_a(Arrays.asList(I18nUtil.resolveKeyArray("radar.redMode")), x, y);
if(checkClick(x, y, -10, 138, 8, 8)) this.func_146283_a(Arrays.asList(I18nUtil.resolveKeyArray("radar.showMap")), x, y);
}
private void drawGuiContainerBackgroundLayer(float f, int mouseX, int mouseY) {
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
drawTexturedModalRect(guiLeft, guiTop, 0, 0, xSize, ySize);
}
protected boolean checkClick(int x, int y, int left, int top, int sizeX, int sizeY) {
return guiLeft + left <= x && guiLeft + left + sizeX > x && guiTop + top < y && guiTop + top + sizeY >= y;
}
}

View File

@ -185,7 +185,7 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
/** Only accepts inputs in a fixed order, saves a ton of performance because there's no permutations to check for */
public CustomMachineRecipe getMatchingRecipe() {
List<CustomMachineRecipe> recipes = CustomMachineRecipes.recipes.get(this.machineType);
List<CustomMachineRecipe> recipes = CustomMachineRecipes.recipes.get(this.config.recipeKey);
if(recipes == null || recipes.isEmpty()) return null;
outer:
@ -391,11 +391,11 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
for(int i = 0; i < outputTanks.length; i++) outputTanks[i].readFromNBT(nbt, "o" + i);
this.matcher.readFromNBT(nbt);
}
int index = nbt.getInteger("cachedIndex");
if(index != -1) {
this.cachedRecipe = CustomMachineRecipes.recipes.get(this.machineType).get(index);
int index = nbt.getInteger("cachedIndex");
if(index != -1) {
this.cachedRecipe = CustomMachineRecipes.recipes.get(this.config.recipeKey).get(index);
}
}
}
@ -417,7 +417,7 @@ public class TileEntityCustomMachine extends TileEntityMachineBase implements IF
this.matcher.writeToNBT(nbt);
if(this.cachedRecipe != null) {
int index = CustomMachineRecipes.recipes.get(this.machineType).indexOf(this.cachedRecipe);
int index = CustomMachineRecipes.recipes.get(this.config.recipeKey).indexOf(this.cachedRecipe);
nbt.setInteger("cachedIndex", index);
} else {
nbt.setInteger("cachedIndex", -1);

View File

@ -8,31 +8,41 @@ import java.util.function.Function;
import com.google.gson.JsonObject;
import com.google.gson.stream.JsonWriter;
import com.hbm.extprop.HbmLivingProps;
import com.hbm.inventory.gui.GUIMachineRadarNT;
import com.hbm.lib.Library;
import com.hbm.tileentity.IConfigurableMachine;
import com.hbm.tileentity.IGUIProvider;
import com.hbm.tileentity.TileEntityMachineBase;
import com.hbm.util.Tuple.Pair;
import api.hbm.entity.IRadarDetectable;
import api.hbm.entity.IRadarDetectableNT;
import api.hbm.entity.RadarEntry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import io.netty.buffer.ByteBuf;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
/**
* Now with SmЯt lag-free entity detection! (patent pending)
* @author hbm
*/
public class TileEntityMachineRadarNT extends TileEntityMachineBase implements IConfigurableMachine {
public class TileEntityMachineRadarNT extends TileEntityMachineBase implements IGUIProvider, IConfigurableMachine {
public boolean scanMissiles = true;
public boolean scanShells = true;
public boolean scanPlayers = true;
public boolean smartMode = true;
public boolean redMode = true;
public boolean showMap = false;
public boolean jammed = false;
@ -133,9 +143,11 @@ public class TileEntityMachineRadarNT extends TileEntityMachineBase implements I
public void serialize(ByteBuf buf) {
buf.writeLong(this.power);
buf.writeBoolean(this.scanMissiles);
buf.writeBoolean(this.scanShells);
buf.writeBoolean(this.scanPlayers);
buf.writeBoolean(this.smartMode);
buf.writeBoolean(this.redMode);
buf.writeBoolean(this.showMap);
buf.writeBoolean(this.jammed);
buf.writeInt(entries.size());
for(RadarEntry entry : entries) entry.toBytes(buf);
@ -145,9 +157,11 @@ public class TileEntityMachineRadarNT extends TileEntityMachineBase implements I
public void deserialize(ByteBuf buf) {
this.power = buf.readLong();
this.scanMissiles = buf.readBoolean();
this.scanShells = buf.readBoolean();
this.scanPlayers = buf.readBoolean();
this.smartMode = buf.readBoolean();
this.redMode = buf.readBoolean();
this.showMap = buf.readBoolean();
this.jammed = buf.readBoolean();
int count = buf.readInt();
for(int i = 0; i < count; i++) {
@ -157,6 +171,40 @@ public class TileEntityMachineRadarNT extends TileEntityMachineBase implements I
}
}
AxisAlignedBB bb = null;
@Override
public AxisAlignedBB getRenderBoundingBox() {
if(bb == null) {
bb = AxisAlignedBB.getBoundingBox(
xCoord - 1,
yCoord,
zCoord - 1,
xCoord + 2,
yCoord + 3,
zCoord + 2
);
}
return bb;
}
@Override
@SideOnly(Side.CLIENT)
public double getMaxRenderDistanceSquared()
{
return 65536.0D;
}
@Override public Container provideContainer(int ID, EntityPlayer player, World world, int x, int y, int z) { return null; }
@Override
@SideOnly(Side.CLIENT)
public GuiScreen provideGUI(int ID, EntityPlayer player, World world, int x, int y, int z) {
return new GUIMachineRadarNT(this);
}
/** List of lambdas that are supplied a Pair with the entity and radar in question to generate a RadarEntry
The converters coming first have the highest priority */
public static List<Function<Pair<Entity, Object>, RadarEntry>> converters = new ArrayList();

Binary file not shown.

Before

Width:  |  Height:  |  Size: 21 KiB

After

Width:  |  Height:  |  Size: 21 KiB