mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
finished the first turret, full AI chip functionality
This commit is contained in:
parent
adcc7e4bd6
commit
b37852ae07
BIN
src/main/java/assets/hbm/textures/items/nuclear_waste_pearl.png
Normal file
BIN
src/main/java/assets/hbm/textures/items/nuclear_waste_pearl.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 326 B |
BIN
src/main/java/assets/hbm/textures/items/starmetal_gauntlet.png
Normal file
BIN
src/main/java/assets/hbm/textures/items/starmetal_gauntlet.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 314 B |
@ -181,32 +181,15 @@ public class GunEnergyFactory {
|
||||
@Override
|
||||
public void behaveBlockHit(EntityBulletBase bullet, int x, int y, int z) {
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setString("type", "vanillaburst");
|
||||
data.setString("mode", "flame");
|
||||
data.setInteger("count", 15);
|
||||
data.setDouble("motion", 0.1D);
|
||||
|
||||
/*
|
||||
* java.lang.NullPointerException
|
||||
* at cpw.mods.fml.common.network.FMLOutboundHandler$OutboundTarget$7.selectNetworks(FMLOutboundHandler.java:193)
|
||||
* at cpw.mods.fml.common.network.FMLOutboundHandler.write(FMLOutboundHandler.java:273)
|
||||
* at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:644)
|
||||
* at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:698)
|
||||
* at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:637)
|
||||
* at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:115)
|
||||
* at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116)
|
||||
* at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:644)
|
||||
* at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:698)
|
||||
* at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:688)
|
||||
* at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:717)
|
||||
* at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:893)
|
||||
* at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:239)
|
||||
* at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.sendToAllAround(SimpleNetworkWrapper.java:210)
|
||||
* at com.hbm.handler.guncfg.GunEnergyFactory$1.behaveBlockHit(GunEnergyFactory.java:150)
|
||||
*/
|
||||
|
||||
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, bullet.posX, bullet.posY, bullet.posZ), new TargetPoint(bullet.dimension, bullet.posX, bullet.posY, bullet.posZ, 50));
|
||||
if(!bullet.worldObj.isRemote) {
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setString("type", "vanillaburst");
|
||||
data.setString("mode", "flame");
|
||||
data.setInteger("count", 15);
|
||||
data.setDouble("motion", 0.1D);
|
||||
|
||||
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, bullet.posX, bullet.posY, bullet.posZ), new TargetPoint(bullet.dimension, bullet.posX, bullet.posY, bullet.posZ, 50));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
11
src/main/java/com/hbm/interfaces/IControlReceiver.java
Normal file
11
src/main/java/com/hbm/interfaces/IControlReceiver.java
Normal file
@ -0,0 +1,11 @@
|
||||
package com.hbm.interfaces;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
public interface IControlReceiver {
|
||||
|
||||
public boolean hasPermission(EntityPlayer player);
|
||||
|
||||
public void receiveControl(NBTTagCompound data);
|
||||
}
|
||||
@ -2,18 +2,22 @@ package com.hbm.inventory.gui;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import com.hbm.inventory.container.ContainerTurretChekhov;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.packet.AuxButtonPacket;
|
||||
import com.hbm.packet.NBTControlPacket;
|
||||
import com.hbm.packet.PacketDispatcher;
|
||||
import com.hbm.tileentity.turret.TileEntityTurretChekhov;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.audio.PositionedSoundRecord;
|
||||
import net.minecraft.client.gui.GuiTextField;
|
||||
import net.minecraft.client.resources.I18n;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
@ -21,6 +25,7 @@ public class GUITurretChekhov extends GuiInfoContainer {
|
||||
|
||||
private static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/weapon/gui_turret_base.png");
|
||||
private TileEntityTurretChekhov turret;
|
||||
private GuiTextField field;
|
||||
int index;
|
||||
|
||||
public GUITurretChekhov(InventoryPlayer invPlayer, TileEntityTurretChekhov tedf) {
|
||||
@ -31,6 +36,18 @@ public class GUITurretChekhov extends GuiInfoContainer {
|
||||
this.ySize = 222;
|
||||
}
|
||||
|
||||
public void initGui() {
|
||||
|
||||
super.initGui();
|
||||
|
||||
Keyboard.enableRepeatEvents(true);
|
||||
this.field = new GuiTextField(this.fontRendererObj, guiLeft + 10, guiTop + 65, 50, 14);
|
||||
this.field.setTextColor(-1);
|
||||
this.field.setDisabledTextColour(-1);
|
||||
this.field.setEnableBackgroundDrawing(false);
|
||||
this.field.setMaxStringLength(25);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float f) {
|
||||
super.drawScreen(mouseX, mouseY, f);
|
||||
@ -40,6 +57,9 @@ public class GUITurretChekhov extends GuiInfoContainer {
|
||||
|
||||
protected void mouseClicked(int x, int y, int i) {
|
||||
super.mouseClicked(x, y, i);
|
||||
|
||||
boolean flag = x >= this.field.xPosition && x < this.field.xPosition + this.field.width && y >= this.field.yPosition && y < this.field.yPosition + this.field.height;
|
||||
this.field.setFocused(flag);
|
||||
|
||||
if(guiLeft + 115 <= x && guiLeft + 115 + 18 > x && guiTop + 26 < y && guiTop + 26 + 18 >= y) {
|
||||
|
||||
@ -97,6 +117,31 @@ public class GUITurretChekhov extends GuiInfoContainer {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if(guiLeft + 7 <= x && guiLeft + 7 + 18 > x && guiTop + 98 < y && guiTop + 98 + 18 >= y) {
|
||||
|
||||
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
|
||||
if(this.field.getText().isEmpty())
|
||||
return;
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setString("name", this.field.getText());
|
||||
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, turret.xCoord, turret.yCoord, turret.zCoord));
|
||||
|
||||
this.field.setText("");
|
||||
return;
|
||||
}
|
||||
|
||||
if(guiLeft + 43 <= x && guiLeft + 43 + 18 > x && guiTop + 98 < y && guiTop + 98 + 18 >= y) {
|
||||
|
||||
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 1.0F));
|
||||
|
||||
NBTTagCompound data = new NBTTagCompound();
|
||||
data.setInteger("del", this.index);
|
||||
PacketDispatcher.wrapper.sendToServer(new NBTControlPacket(data, turret.xCoord, turret.yCoord, turret.zCoord));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -110,14 +155,28 @@ public class GUITurretChekhov extends GuiInfoContainer {
|
||||
|
||||
String n = EnumChatFormatting.ITALIC + "None";
|
||||
|
||||
while(this.index >= this.getCount())
|
||||
this.index--;
|
||||
|
||||
if(index < 0)
|
||||
index = 0;
|
||||
|
||||
if(names != null) {
|
||||
n = names.get(index);
|
||||
}
|
||||
|
||||
String t = this.field.getText();
|
||||
|
||||
String cursor = System.currentTimeMillis() % 1000 < 500 ? " " : "||";
|
||||
|
||||
if(this.field.isFocused())
|
||||
t = t.substring(0, this.field.getCursorPosition()) + cursor + t.substring(this.field.getCursorPosition(), t.length());
|
||||
|
||||
double scale = 2;
|
||||
|
||||
GL11.glScaled(1D / scale, 1D / scale, 1);
|
||||
this.fontRendererObj.drawString(n, (int)(12 * scale), (int)(51 * scale), 0x00ff00);
|
||||
this.fontRendererObj.drawString(t, (int)(12 * scale), (int)(69 * scale), 0x00ff00);
|
||||
GL11.glScaled(scale, scale, 1);
|
||||
}
|
||||
|
||||
@ -191,4 +250,13 @@ public class GUITurretChekhov extends GuiInfoContainer {
|
||||
|
||||
return names.size();
|
||||
}
|
||||
|
||||
protected void keyTyped(char p_73869_1_, int p_73869_2_) {
|
||||
|
||||
if(this.field.textboxKeyTyped(p_73869_1_, p_73869_2_)) {
|
||||
|
||||
} else {
|
||||
super.keyTyped(p_73869_1_, p_73869_2_);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
100
src/main/java/com/hbm/packet/NBTControlPacket.java
Normal file
100
src/main/java/com/hbm/packet/NBTControlPacket.java
Normal file
@ -0,0 +1,100 @@
|
||||
package com.hbm.packet;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import com.hbm.interfaces.IControlReceiver;
|
||||
|
||||
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 io.netty.buffer.ByteBuf;
|
||||
import io.netty.buffer.Unpooled;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
|
||||
public class NBTControlPacket implements IMessage {
|
||||
|
||||
PacketBuffer buffer;
|
||||
int x;
|
||||
int y;
|
||||
int z;
|
||||
|
||||
public NBTControlPacket() { }
|
||||
|
||||
public NBTControlPacket(NBTTagCompound nbt, int x, int y, int z) {
|
||||
|
||||
this.buffer = new PacketBuffer(Unpooled.buffer());
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
this.z = z;
|
||||
|
||||
try {
|
||||
buffer.writeNBTTagCompoundToBuffer(nbt);
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
|
||||
x = buf.readInt();
|
||||
y = buf.readInt();
|
||||
z = buf.readInt();
|
||||
|
||||
if (buffer == null) {
|
||||
buffer = new PacketBuffer(Unpooled.buffer());
|
||||
}
|
||||
buffer.writeBytes(buf);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
|
||||
buf.writeInt(x);
|
||||
buf.writeInt(y);
|
||||
buf.writeInt(z);
|
||||
|
||||
if (buffer == null) {
|
||||
buffer = new PacketBuffer(Unpooled.buffer());
|
||||
}
|
||||
buf.writeBytes(buffer);
|
||||
}
|
||||
|
||||
public static class Handler implements IMessageHandler<NBTControlPacket, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(NBTControlPacket m, MessageContext ctx) {
|
||||
|
||||
EntityPlayer p = ctx.getServerHandler().playerEntity;
|
||||
|
||||
if(p.worldObj == null)
|
||||
return null;
|
||||
|
||||
TileEntity te = p.worldObj.getTileEntity(m.x, m.y, m.z);
|
||||
|
||||
try {
|
||||
|
||||
NBTTagCompound nbt = m.buffer.readNBTTagCompoundFromBuffer();
|
||||
|
||||
if(nbt != null) {
|
||||
if(te instanceof IControlReceiver) {
|
||||
|
||||
IControlReceiver tile = (IControlReceiver)te;
|
||||
|
||||
if(tile.hasPermission(p))
|
||||
tile.receiveControl(nbt);
|
||||
}
|
||||
}
|
||||
|
||||
} catch (IOException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -97,6 +97,8 @@ public class PacketDispatcher {
|
||||
wrapper.registerMessage(PlayerInformPacket.Handler.class, PlayerInformPacket.class, i++, Side.CLIENT);
|
||||
//Universal keybind packet
|
||||
wrapper.registerMessage(KeybindPacket.Handler.class, KeybindPacket.class, i++, Side.SERVER);
|
||||
//Packet to send NBT data from clients to serverside TEs
|
||||
wrapper.registerMessage(NBTControlPacket.Handler.class, NBTControlPacket.class, i++, Side.SERVER);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
package com.hbm.tileentity.turret;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
@ -10,6 +11,7 @@ import com.hbm.entity.projectile.EntityBulletBase;
|
||||
import com.hbm.handler.BulletConfigSyncingUtil;
|
||||
import com.hbm.handler.BulletConfiguration;
|
||||
import com.hbm.interfaces.IConsumer;
|
||||
import com.hbm.interfaces.IControlReceiver;
|
||||
import com.hbm.items.ModItems;
|
||||
import com.hbm.items.machine.ItemTurretBiometry;
|
||||
import com.hbm.lib.Library;
|
||||
@ -23,6 +25,7 @@ import net.minecraft.entity.monster.IMob;
|
||||
import net.minecraft.entity.passive.EntityAnimal;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
@ -34,7 +37,23 @@ import net.minecraftforge.common.util.FakePlayer;
|
||||
* @author hbm
|
||||
*
|
||||
*/
|
||||
public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase implements IConsumer {
|
||||
public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase implements IConsumer, IControlReceiver {
|
||||
|
||||
@Override
|
||||
public boolean hasPermission(EntityPlayer player) {
|
||||
return this.isUseableByPlayer(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveControl(NBTTagCompound data) {
|
||||
|
||||
if(data.hasKey("del")) {
|
||||
this.removeName(data.getInteger("del"));
|
||||
|
||||
} else if(data.hasKey("name")) {
|
||||
this.addName(data.getString("name"));
|
||||
}
|
||||
}
|
||||
|
||||
//this time we do all rotations in radians
|
||||
//what way are we facing?
|
||||
@ -309,7 +328,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
|
||||
* Removes the chip's entry at a given
|
||||
* @param index
|
||||
*/
|
||||
public void removeName(String index) {
|
||||
public void removeName(int index) {
|
||||
|
||||
if(slots[0] != null && slots[0].getItem() == ModItems.turret_chip) {
|
||||
|
||||
@ -318,7 +337,7 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
|
||||
if(array == null)
|
||||
return;
|
||||
|
||||
List<String> names = Arrays.asList(array);
|
||||
List<String> names = new ArrayList(Arrays.asList(array));
|
||||
ItemTurretBiometry.clearNames(slots[0]);
|
||||
|
||||
names.remove(index);
|
||||
@ -621,6 +640,16 @@ public abstract class TileEntityTurretBaseNT extends TileEntityMachineBase imple
|
||||
*/
|
||||
protected abstract List<Integer> getAmmoList();
|
||||
|
||||
@Override
|
||||
public int[] getAccessibleSlotsFromSide(int side) {
|
||||
return new int[] { 1, 2, 3, 4, 5, 6, 7, 8, 9 };
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValidForSlot(int i, ItemStack itemStack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
public boolean hasPower() {
|
||||
return this.getPower() >= this.getConsumption();
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user