mirror of
https://github.com/GTNewHorizons/FindIt.git
synced 2026-11-18 23:59:05 +00:00
Initial Commit
This commit is contained in:
commit
ae30c50d16
17 files changed
+836
No files matched your search
@@ -0,0 +1,78 @@
|
||||
package com.gtnh.findit;
|
||||
|
||||
import com.gtnh.findit.proxy.FindItCommon;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.SidedProxy;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.common.network.NetworkRegistry;
|
||||
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
|
||||
import net.minecraftforge.common.config.Configuration;
|
||||
import net.minecraftforge.common.config.Property;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
@Mod(
|
||||
modid = FindIt.MOD_ID,
|
||||
name = FindIt.MOD_NAME,
|
||||
version = FindIt.VERSION,
|
||||
dependencies = "required-after:NotEnoughItems;required-after:gregtech"
|
||||
)
|
||||
public class FindIt {
|
||||
|
||||
// Mod info
|
||||
public static final String MOD_ID = "findit";
|
||||
public static final String MOD_NAME = "FindIt";
|
||||
public static final String VERSION = "1.0.0";
|
||||
|
||||
// Config
|
||||
public static int SEARCH_RADIUS = 16;
|
||||
|
||||
public static final SimpleNetworkWrapper NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(MOD_ID);
|
||||
|
||||
@Mod.Instance(MOD_ID)
|
||||
public static FindIt INSTANCE;
|
||||
|
||||
@SidedProxy(serverSide = "com.gtnh.findit.proxy.FindItCommon", clientSide = "com.gtnh.findit.proxy.FindItClient")
|
||||
public static FindItCommon proxy;
|
||||
|
||||
|
||||
@Mod.EventHandler
|
||||
public void preinit(FMLPreInitializationEvent event) {
|
||||
this.setupConfig(event.getSuggestedConfigurationFile());
|
||||
proxy.preinit(event);
|
||||
}
|
||||
|
||||
|
||||
@Mod.EventHandler
|
||||
public void init(FMLInitializationEvent event) {
|
||||
proxy.init(event);
|
||||
}
|
||||
|
||||
@Mod.EventHandler
|
||||
public void postinit(FMLPostInitializationEvent event) {
|
||||
proxy.postinit(event);
|
||||
}
|
||||
|
||||
public void setupConfig(final File file) {
|
||||
final Configuration config = new Configuration(file);
|
||||
try {
|
||||
// Load config
|
||||
config.load();
|
||||
|
||||
// Read props from config
|
||||
Property searchRadiousProp = config.get(Configuration.CATEGORY_GENERAL,
|
||||
"SearchRadius", // Property name
|
||||
"16", // Default value
|
||||
"Radius to search within"); // Comment
|
||||
|
||||
FindIt.SEARCH_RADIUS = searchRadiousProp.getInt();
|
||||
} catch (Exception e) {
|
||||
// Failed reading/writing, just continue
|
||||
} finally {
|
||||
// Save props to config IF config changed
|
||||
if (config.hasChanged()) config.save();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,76 @@
|
||||
package com.gtnh.findit.network;
|
||||
|
||||
import com.gtnh.findit.proxy.client.ParticlePosition;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
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.network.PacketBuffer;
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class KIFoundItMessage implements IMessage {
|
||||
|
||||
private List<ChunkPosition> positions;
|
||||
|
||||
public KIFoundItMessage(List<ChunkPosition> positions) {
|
||||
this.positions = positions;
|
||||
}
|
||||
|
||||
public KIFoundItMessage() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
PacketBuffer packetBuffer = new PacketBuffer(buf);
|
||||
int amount = packetBuffer.readInt();
|
||||
positions = new ArrayList<>();
|
||||
while (amount > 0) {
|
||||
final int x = packetBuffer.readInt();
|
||||
final int y = packetBuffer.readUnsignedByte();
|
||||
final int z = packetBuffer.readInt();
|
||||
positions.add(new ChunkPosition(x, y, z));
|
||||
--amount;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
PacketBuffer packetBuffer = new PacketBuffer(buf);
|
||||
packetBuffer.writeInt(positions.size());
|
||||
for (ChunkPosition pos : positions) {
|
||||
packetBuffer.writeInt(pos.chunkPosX);
|
||||
packetBuffer.writeByte(pos.chunkPosY);
|
||||
packetBuffer.writeInt(pos.chunkPosZ);
|
||||
}
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<KIFoundItMessage, IMessage> {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public IMessage onMessage(KIFoundItMessage message, MessageContext ctx) {
|
||||
Minecraft.getMinecraft().thePlayer.closeScreen();
|
||||
World world = Minecraft.getMinecraft().thePlayer.worldObj;
|
||||
for (ChunkPosition pos : message.positions) {
|
||||
for (int i = 0; i < 2; ++i)
|
||||
Minecraft.getMinecraft().effectRenderer.addEffect(
|
||||
new ParticlePosition(
|
||||
Minecraft.getMinecraft().thePlayer.worldObj,
|
||||
pos.chunkPosX + (0.5 + (world.rand.nextDouble() - 0.5) * world.rand.nextDouble()),
|
||||
pos.chunkPosY + (0.5 + (world.rand.nextDouble() - 0.5) * world.rand.nextDouble()),
|
||||
pos.chunkPosZ + (0.5 + (world.rand.nextDouble() - 0.5) * world.rand.nextDouble())
|
||||
)
|
||||
);
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,125 @@
|
||||
package com.gtnh.findit.network;
|
||||
|
||||
import com.gtnh.findit.FindIt;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import gregtech.api.interfaces.tileentity.IGregTechTileEntity;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.world.ChunkPosition;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.WeakHashMap;
|
||||
|
||||
public class PlzFindItMessage implements IMessage {
|
||||
static WeakHashMap<EntityPlayerMP, Long> lastCalled = new WeakHashMap<>();
|
||||
|
||||
private ItemStack stack;
|
||||
|
||||
public PlzFindItMessage(ItemStack stack) {
|
||||
this.stack = stack;
|
||||
}
|
||||
|
||||
public PlzFindItMessage() {
|
||||
}
|
||||
|
||||
public static List<ChunkPosition> getBlockPosInAABB(AxisAlignedBB axisAlignedBB) {
|
||||
List<ChunkPosition> blocks = new ArrayList<>();
|
||||
|
||||
int maxY = (int) Math.round(axisAlignedBB.maxY),
|
||||
maxX = (int) Math.round(axisAlignedBB.maxX),
|
||||
maxZ = (int) Math.round(axisAlignedBB.maxZ);
|
||||
|
||||
for (int y = (int) Math.round(axisAlignedBB.minY); y < maxY; ++y) {
|
||||
for (int x = (int) Math.round(axisAlignedBB.minX); x < maxX; ++x) {
|
||||
for (int z = (int) Math.round(axisAlignedBB.minZ); z < maxZ; ++z) {
|
||||
blocks.add(new ChunkPosition(x, y, z));
|
||||
}
|
||||
}
|
||||
}
|
||||
return blocks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
PacketBuffer packetBuffer = new PacketBuffer(buf);
|
||||
stack = null;
|
||||
try {
|
||||
stack = packetBuffer.readItemStackFromBuffer();
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
PacketBuffer packetBuffer = new PacketBuffer(buf);
|
||||
try {
|
||||
packetBuffer.writeItemStackToBuffer(stack);
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<PlzFindItMessage, KIFoundItMessage> {
|
||||
|
||||
@Override
|
||||
public KIFoundItMessage onMessage(PlzFindItMessage message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
World world = player.worldObj;
|
||||
|
||||
// Don't let people spam this, otherwise bad performance and they'll probably get disconnected
|
||||
final long time = world.getTotalWorldTime();
|
||||
final Long lastCalled = PlzFindItMessage.lastCalled.get(player);
|
||||
if (lastCalled != null && time - lastCalled < 10L) {
|
||||
return null;
|
||||
}
|
||||
|
||||
final Item toFind = message.stack.getItem();
|
||||
final int metaToFind = message.stack.getItemDamage();
|
||||
|
||||
final double x = player.posX,
|
||||
y = player.posY,
|
||||
z = player.posZ;
|
||||
|
||||
int r = FindIt.SEARCH_RADIUS;
|
||||
AxisAlignedBB box = AxisAlignedBB.getBoundingBox(x - r, y - r, z -r, x + r, y + r, z + r);
|
||||
|
||||
List<ChunkPosition> posList = new ArrayList<>();
|
||||
for (ChunkPosition pos : getBlockPosInAABB(box)) {
|
||||
try {
|
||||
final TileEntity tileEntity = world.getTileEntity(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
|
||||
if(tileEntity == null) continue;
|
||||
|
||||
final Item tileItem = Item.getItemFromBlock(tileEntity.getBlockType());
|
||||
if (tileItem == null) continue;
|
||||
|
||||
final int tileMeta;
|
||||
if (tileEntity instanceof IGregTechTileEntity)
|
||||
tileMeta = ((IGregTechTileEntity)tileEntity).getMetaTileID();
|
||||
else
|
||||
tileMeta = world.getBlockMetadata(pos.chunkPosX, pos.chunkPosY, pos.chunkPosZ);
|
||||
|
||||
if (toFind.equals(tileItem) && metaToFind == tileMeta) {
|
||||
posList.add(pos);
|
||||
}
|
||||
} catch (NullPointerException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
if (!posList.isEmpty())
|
||||
FindIt.NETWORK.sendTo(new KIFoundItMessage(posList), player);
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,72 @@
|
||||
package com.gtnh.findit.proxy;
|
||||
|
||||
import codechicken.nei.LayoutManager;
|
||||
import codechicken.nei.NEIClientConfig;
|
||||
import codechicken.nei.api.API;
|
||||
import codechicken.nei.guihook.GuiContainerManager;
|
||||
import codechicken.nei.guihook.IContainerInputHandler;
|
||||
import com.gtnh.findit.FindIt;
|
||||
import com.gtnh.findit.network.PlzFindItMessage;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraft.client.gui.inventory.GuiContainer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
|
||||
public class FindItClient extends FindItCommon implements IContainerInputHandler{
|
||||
|
||||
@Override
|
||||
public void preinit(FMLPreInitializationEvent event) {
|
||||
super.preinit(event);
|
||||
API.addKeyBind("gui.findit", Keyboard.KEY_Y);
|
||||
GuiContainerManager.addInputHandler((IContainerInputHandler)new FindItClient());
|
||||
}
|
||||
|
||||
public boolean keyTyped(final GuiContainer window, final char c, final int k) {
|
||||
final int keyBinding = NEIClientConfig.getKeyBinding("gui.findit");
|
||||
if (k != keyBinding) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final LayoutManager layout = LayoutManager.instance();
|
||||
if (layout == null || LayoutManager.itemPanel == null || NEIClientConfig.isHidden()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final ItemStack stack = GuiContainerManager.getStackMouseOver(window);
|
||||
if (stack == null || stack.getItem() == null) {
|
||||
return false;
|
||||
}
|
||||
|
||||
FindIt.NETWORK.sendToServer(new PlzFindItMessage(stack));
|
||||
return true;
|
||||
}
|
||||
|
||||
public void onKeyTyped(final GuiContainer guiContainer, final char c, final int i) {
|
||||
}
|
||||
|
||||
public boolean lastKeyTyped(final GuiContainer guiContainer, final char c, final int i) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean mouseClicked(final GuiContainer guiContainer, final int i, final int i1, final int i2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onMouseClicked(final GuiContainer guiContainer, final int i, final int i1, final int i2) {
|
||||
}
|
||||
|
||||
public void onMouseUp(final GuiContainer guiContainer, final int i, final int i1, final int i2) {
|
||||
}
|
||||
|
||||
public boolean mouseScrolled(final GuiContainer guiContainer, final int i, final int i1, final int i2) {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void onMouseScrolled(final GuiContainer guiContainer, final int i, final int i1, final int i2) {
|
||||
}
|
||||
|
||||
public void onMouseDragged(final GuiContainer guiContainer, final int i, final int i1, final int i2, final long l) {
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,29 @@
|
||||
package com.gtnh.findit.proxy;
|
||||
|
||||
import com.gtnh.findit.network.KIFoundItMessage;
|
||||
import com.gtnh.findit.network.PlzFindItMessage;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPostInitializationEvent;
|
||||
import cpw.mods.fml.common.event.FMLPreInitializationEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
|
||||
import static com.gtnh.findit.FindIt.NETWORK;
|
||||
|
||||
public class FindItCommon {
|
||||
|
||||
|
||||
public void preinit(FMLPreInitializationEvent event) {
|
||||
NETWORK.registerMessage(PlzFindItMessage.Handler.class, PlzFindItMessage.class, 0, Side.SERVER);
|
||||
NETWORK.registerMessage(KIFoundItMessage.Handler.class, KIFoundItMessage.class, 1, Side.CLIENT);
|
||||
}
|
||||
|
||||
|
||||
public void init(FMLInitializationEvent event) {
|
||||
|
||||
}
|
||||
|
||||
|
||||
public void postinit(FMLPostInitializationEvent event) {
|
||||
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
package com.gtnh.findit.proxy.client;
|
||||
|
||||
import net.minecraft.client.particle.EntityReddustFX;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.world.World;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
public class ParticlePosition extends EntityReddustFX {
|
||||
|
||||
public ParticlePosition(World world, double posX, double posY, double posZ) {
|
||||
super(world, posX, posY, posZ, 1.0f, 1.0f, 1.0f);
|
||||
this.noClip = true;
|
||||
this.particleMaxAge *= 10;
|
||||
this.motionX *= 0.1;
|
||||
this.motionY *= 0.1;
|
||||
this.motionZ *= 0.1;
|
||||
this.particleScale *= 2.0f;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderParticle(final Tessellator tessellator, float partialTickTime, float rotationX, float rotationZ, float rotationYZ, float rotationXY, float rotationXZ) {
|
||||
super.renderParticle(tessellator, partialTickTime, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ);
|
||||
tessellator.draw();
|
||||
|
||||
GL11.glDisable(2929 /*GL_DEPTH_TEST*/);
|
||||
|
||||
tessellator.startDrawingQuads();
|
||||
super.renderParticle(tessellator, partialTickTime, rotationX, rotationZ, rotationYZ, rotationXY, rotationXZ);
|
||||
tessellator.draw();
|
||||
|
||||
GL11.glEnable(2929 /*GL_DEPTH_TEST*/);
|
||||
tessellator.startDrawingQuads();
|
||||
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user