Skip to content
Permalink
Browse files

Added player targetting to the turret (crude implementation)

  • Loading branch information...
Ri5ux Ri5ux
Ri5ux authored and Ri5ux committed Jul 12, 2019
1 parent 3b3e374 commit 0cdaa308d894fcb75b1f4ec0da307a53b0f1f956
@@ -11,14 +11,12 @@
import org.avp.packets.client.PacketTurretSync;
import org.avp.packets.client.SpecialPlayerClientSync;
import org.avp.packets.server.OrganismServerSync;
import org.avp.packets.server.PacketAddTuretTarget;
import org.avp.packets.server.PacketAddTurretPlayerTarget;
import org.avp.packets.server.PacketAddTurretTarget;
import org.avp.packets.server.PacketAssemble;
import org.avp.packets.server.PacketAttachParasiteToEntity;
import org.avp.packets.server.PacketBlastdoorCommon;
import org.avp.packets.server.PacketBlastdoorCommon.PacketBlastdoorClient;

import com.asx.mdx.core.mods.IInitEvent;

import org.avp.packets.server.PacketDamageEntity;
import org.avp.packets.server.PacketFireAPC;
import org.avp.packets.server.PacketFirearmSync;
@@ -28,13 +26,16 @@
import org.avp.packets.server.PacketPlasmaDischarge;
import org.avp.packets.server.PacketReadFromDataDevice;
import org.avp.packets.server.PacketReloadFirearm;
import org.avp.packets.server.PacketRemoveTurretPlayerTarget;
import org.avp.packets.server.PacketRemoveTurretTarget;
import org.avp.packets.server.PacketSpawnEntity;
import org.avp.packets.server.PacketSpawnNuke;
import org.avp.packets.server.PacketTurretTargetUpdate;
import org.avp.packets.server.PacketWriteToDataDevice;
import org.avp.packets.server.SpecialPlayerServerSync;

import com.asx.mdx.core.mods.IInitEvent;

import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
@@ -62,12 +63,14 @@ public void init(FMLInitializationEvent event)
this.registerMessage(Side.SERVER, PacketLaunchGrenade.class);
this.registerMessage(Side.SERVER, PacketFireAPC.class);
this.registerMessage(Side.SERVER, PacketDamageEntity.class);
this.registerMessage(Side.SERVER, PacketRemoveTurretTarget.class);
this.registerMessage(Side.SERVER, PacketFirearmSync.class);
this.registerMessage(Side.SERVER, PacketSpawnEntity.class);
this.registerMessage(Side.SERVER, PacketSpawnNuke.class);
this.registerMessage(Side.SERVER, PacketPlasmaDischarge.class);
this.registerMessage(Side.SERVER, PacketAddTuretTarget.class);
this.registerMessage(Side.SERVER, PacketAddTurretTarget.class);
this.registerMessage(Side.SERVER, PacketRemoveTurretTarget.class);
this.registerMessage(Side.SERVER, PacketAddTurretPlayerTarget.class);
this.registerMessage(Side.SERVER, PacketRemoveTurretPlayerTarget.class);
this.registerMessage(Side.SERVER, PacketReadFromDataDevice.class);
this.registerMessage(Side.SERVER, PacketWriteToDataDevice.class);
this.registerMessage(Side.SERVER, OrganismServerSync.class);
@@ -1,7 +1,7 @@
package org.avp.block;

import org.avp.AliensVsPredator;
import org.avp.packets.server.PacketAddTuretTarget;
import org.avp.packets.server.PacketAddTurretTarget;
import org.avp.tile.TileEntityTurret;

import com.asx.mdx.lib.world.entity.Entities;
@@ -89,7 +89,7 @@ public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, En
{
if (tile.getDangerousTargets().get(i) != null)
{
AliensVsPredator.network().sendToAll(new PacketAddTuretTarget(pos.getX(), pos.getY(), pos.getZ(), Entities.getEntityRegistrationId(tile.getDangerousTargets().get(i))));
AliensVsPredator.network().sendToAll(new PacketAddTurretTarget(pos.getX(), pos.getY(), pos.getZ(), Entities.getEntityRegistrationId(tile.getDangerousTargets().get(i))));
}
}
}
@@ -1,11 +1,14 @@
package org.avp.client.gui;

import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.ArrayList;

import org.avp.AliensVsPredator;
import org.avp.packets.server.PacketAddTuretTarget;
import org.avp.packets.server.PacketAddTurretPlayerTarget;
import org.avp.packets.server.PacketAddTurretTarget;
import org.avp.packets.server.PacketReadFromDataDevice;
import org.avp.packets.server.PacketRemoveTurretPlayerTarget;
import org.avp.packets.server.PacketRemoveTurretTarget;
import org.avp.packets.server.PacketWriteToDataDevice;
import org.avp.tile.TileEntityTurret;
@@ -14,6 +17,7 @@

import com.asx.mdx.lib.client.gui.GuiCustomButton;
import com.asx.mdx.lib.client.gui.GuiCustomSlider;
import com.asx.mdx.lib.client.gui.GuiCustomTextbox;
import com.asx.mdx.lib.client.gui.IAction;
import com.asx.mdx.lib.client.gui.IGuiElement;
import com.asx.mdx.lib.client.util.Color;
@@ -37,17 +41,18 @@
@SideOnly(Side.CLIENT)
public class GuiTurret extends GuiContainer
{
private TileEntityTurret tile;
private GuiCustomButton buttonScrollUp;
private GuiCustomButton buttonScrollDown;
private GuiCustomButton buttonAddAsTarget;
private GuiCustomButton buttonSave;
private GuiCustomButton buttonLoad;
private GuiCustomSlider sliderColorR, sliderColorG, sliderColorB, sliderColorA;
private int scroll = 0;
private float modelRotation = -90.0F;
private TileEntityTurret tile;
private GuiCustomButton buttonScrollUp;
private GuiCustomButton buttonScrollDown;
private GuiCustomButton buttonAddAsTarget;
private GuiCustomButton buttonSave;
private GuiCustomButton buttonLoad;
private GuiCustomSlider sliderColorR, sliderColorG, sliderColorB, sliderColorA;
private GuiCustomTextbox playerNameInput;
private int scroll = 0;
private float modelRotation = -90.0F;
private ArrayList<Class<? extends Entity>> entityList;
private ArrayList<EntityLiving> entityLivingList;
private ArrayList<EntityLiving> entityLivingList;

public GuiTurret(EntityPlayer player, TileEntityTurret turret, World world, int x, int y, int z)
{
@@ -93,6 +98,8 @@ public void initGui()
this.buttonSave = new GuiCustomButton(3, 0, 0, 35, 20, "");
this.buttonLoad = new GuiCustomButton(4, 0, 0, 35, 20, "");

this.playerNameInput = new GuiCustomTextbox(0, 0, 200, 20);

this.sliderColorA = new GuiCustomSlider(0, 0, 0, "Laser Color A", 0F, 255F);
this.sliderColorR = new GuiCustomSlider(0, 0, 0, "Laser Color R", 0F, 255F);
this.sliderColorG = new GuiCustomSlider(0, 0, 0, "Laser Color G", 0F, 255F);
@@ -113,7 +120,7 @@ public void onGuiClosed()

for (Class<? extends Entity> c : this.tile.getDangerousTargets())
{
AliensVsPredator.network().sendToServer(new PacketAddTuretTarget(this.tile.getPos().getX(), this.tile.getPos().getY(), this.tile.getPos().getZ(), Entities.getEntityRegistrationId(c)));
AliensVsPredator.network().sendToServer(new PacketAddTurretTarget(this.tile.getPos().getX(), this.tile.getPos().getY(), this.tile.getPos().getZ(), Entities.getEntityRegistrationId(c)));
}
}

@@ -172,6 +179,14 @@ public void drawScreen(int mouseX, int mouseY, float p_73863_3_)
{
super.drawScreen(mouseX, mouseY, p_73863_3_);

this.playerNameInput.setX(guiLeft);
this.playerNameInput.setY(guiTop - 20);
this.playerNameInput.setWidth(225);
this.playerNameInput.setBackgroundColor(0xFF222222);
this.playerNameInput.setTextColor(0xFFDDDDDD);
this.playerNameInput.setBorderColor(0xFF555555);
this.playerNameInput.drawTextBox();

this.sliderColorA.y = guiTop + 170 + 0;
this.sliderColorA.x = guiLeft + 3;
this.sliderColorA.width = 219;
@@ -203,8 +218,7 @@ public void drawScreen(int mouseX, int mouseY, float p_73863_3_)
this.buttonScrollUp.displayString = "\u21e7";
this.buttonScrollUp.baseColor = this.getScroll() == 0 ? 0x22000000 : 0xAA000000;
this.buttonScrollUp.drawButton();
this.buttonScrollUp.setAction(new IAction()
{
this.buttonScrollUp.setAction(new IAction() {
@Override
public void perform(IGuiElement element)
{
@@ -217,8 +231,7 @@ public void perform(IGuiElement element)
this.buttonScrollDown.displayString = "\u21e9";
this.buttonScrollDown.baseColor = this.getScroll() >= this.entityLivingList.size() - 1 ? 0x22000000 : 0xAA000000;
this.buttonScrollDown.drawButton();
this.buttonScrollDown.setAction(new IAction()
{
this.buttonScrollDown.setAction(new IAction() {
@Override
public void perform(IGuiElement element)
{
@@ -230,22 +243,39 @@ public void perform(IGuiElement element)
this.buttonAddAsTarget.y = this.guiTop + 65;
this.buttonAddAsTarget.width = 20;
this.buttonAddAsTarget.drawButton();
this.buttonAddAsTarget.setAction(new IAction()
{
this.buttonAddAsTarget.setAction(new IAction() {
@Override
public void perform(IGuiElement element)
{
if (tile != null)
{
if (!tile.canTargetType(getCurrentSelectedEntity().getClass()))
if (playerNameInput != null && playerNameInput.getText().isEmpty() || playerNameInput == null)
{
tile.addTargetType(getCurrentSelectedEntity().getClass());
AliensVsPredator.network().sendToServer(new PacketAddTuretTarget(tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), Entities.getEntityRegistrationId(getCurrentSelectedEntity())));
if (!tile.canTargetType(getCurrentSelectedEntity().getClass()))
{
tile.addTargetType(getCurrentSelectedEntity().getClass());
AliensVsPredator.network().sendToServer(new PacketAddTurretTarget(tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), Entities.getEntityRegistrationId(getCurrentSelectedEntity())));
}
else
{
tile.removeTargetType(getCurrentSelectedEntity().getClass());
AliensVsPredator.network().sendToServer(new PacketRemoveTurretTarget(tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), Entities.getEntityRegistrationId(getCurrentSelectedEntity())));
}
}
else
{
tile.removeTargetType(getCurrentSelectedEntity().getClass());
AliensVsPredator.network().sendToServer(new PacketRemoveTurretTarget(tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), Entities.getEntityRegistrationId(getCurrentSelectedEntity())));
if (!tile.getTargetPlayers().contains(playerNameInput.getText()))
{
Game.minecraft().player.sendChatMessage("'" + playerNameInput.getText() + "' added to turret player target list.");
tile.addTargetPlayer(playerNameInput.getText());
AliensVsPredator.network().sendToServer(new PacketAddTurretPlayerTarget(tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), playerNameInput.getText()));
}
else
{
Game.minecraft().player.sendChatMessage("'" + playerNameInput.getText() + "' removed from turret player target list.");
tile.removeTargetPlayer(playerNameInput.getText());
AliensVsPredator.network().sendToServer(new PacketRemoveTurretPlayerTarget(tile.getPos().getX(), tile.getPos().getY(), tile.getPos().getZ(), playerNameInput.getText()));
}
}
}
}
@@ -256,8 +286,7 @@ public void perform(IGuiElement element)
this.buttonSave.displayString = "S";
this.buttonSave.width = 14;
this.buttonSave.drawButton();
this.buttonSave.setAction(new IAction()
{
this.buttonSave.setAction(new IAction() {
@Override
public void perform(IGuiElement element)
{
@@ -271,8 +300,7 @@ public void perform(IGuiElement element)
this.buttonLoad.displayString = "L";
this.buttonLoad.width = 14;
this.buttonLoad.drawButton();
this.buttonLoad.setAction(new IAction()
{
this.buttonLoad.setAction(new IAction() {
@Override
public void perform(IGuiElement element)
{
@@ -301,8 +329,8 @@ public void updateScreen()

for (Entity entity : this.entityLivingList)
{
//TODO: Temporarily disabled to fix a crash
// entity.onUpdate();
// TODO: Temporarily disabled to fix a crash
// entity.onUpdate();
}

int dWheel = Mouse.getDWheel();
@@ -354,4 +382,16 @@ public int getScroll()
{
return this.scroll;
}

@Override
protected void keyTyped(char typedChar, int keyCode) throws IOException
{
if (this.playerNameInput.isEnabled() && this.playerNameInput.isFocused() && keyCode != Keyboard.KEY_ESCAPE)
{
this.playerNameInput.textboxKeyTyped(typedChar, keyCode);
return;
}

super.keyTyped(typedChar, keyCode);
}
}
@@ -0,0 +1,68 @@
package org.avp.packets.server;

import org.avp.tile.TileEntityTurret;

import io.netty.buffer.ByteBuf;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.fml.common.network.ByteBufUtils;
import net.minecraftforge.fml.common.network.simpleimpl.IMessage;
import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler;
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;

public class PacketAddTurretPlayerTarget implements IMessage, IMessageHandler<PacketAddTurretPlayerTarget, PacketAddTurretPlayerTarget>
{
public int x, y, z;
public String name;

public PacketAddTurretPlayerTarget()
{
;
}

public PacketAddTurretPlayerTarget(int x, int y, int z, String globalID)
{
this.x = x;
this.y = y;
this.z = z;
this.name = globalID;
}

@Override
public void fromBytes(ByteBuf buf)
{
this.x = buf.readInt();
this.y = buf.readInt();
this.z = buf.readInt();
this.name = ByteBufUtils.readUTF8String(buf);
}

@Override
public void toBytes(ByteBuf buf)
{
buf.writeInt(x);
buf.writeInt(y);
buf.writeInt(z);
ByteBufUtils.writeUTF8String(buf, this.name);
}

@Override
public PacketAddTurretPlayerTarget onMessage(PacketAddTurretPlayerTarget packet, MessageContext ctx)
{
System.out.println("Sent packet " + this.getClass().getName());
ctx.getServerHandler().player.getServerWorld().addScheduledTask(new Runnable()
{
@Override
public void run()
{
TileEntityTurret tile = (TileEntityTurret) ctx.getServerHandler().player.world.getTileEntity(new BlockPos(packet.x, packet.y, packet.z));

if (tile != null)
{
tile.addTargetPlayer(packet.name);
}
}
});

return null;
}
}
@@ -13,17 +13,17 @@
import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
import net.minecraftforge.fml.common.registry.ForgeRegistries;

public class PacketAddTuretTarget implements IMessage, IMessageHandler<PacketAddTuretTarget, PacketAddTuretTarget>
public class PacketAddTurretTarget implements IMessage, IMessageHandler<PacketAddTurretTarget, PacketAddTurretTarget>
{
public int x, y, z;
public String entityIdentifier;

public PacketAddTuretTarget()
public PacketAddTurretTarget()
{
;
}

public PacketAddTuretTarget(int x, int y, int z, String globalID)
public PacketAddTurretTarget(int x, int y, int z, String globalID)
{
this.x = x;
this.y = y;
@@ -50,7 +50,7 @@ public void toBytes(ByteBuf buf)
}

@Override
public PacketAddTuretTarget onMessage(PacketAddTuretTarget packet, MessageContext ctx)
public PacketAddTurretTarget onMessage(PacketAddTurretTarget packet, MessageContext ctx)
{
System.out.println("Sent packet " + this.getClass().getName());
ctx.getServerHandler().player.getServerWorld().addScheduledTask(new Runnable()

0 comments on commit 0cdaa30

Please sign in to comment.
You can’t perform that action at this time.