Adjustable Flamethrower modes - combat, heat, and inferno

This commit is contained in:
aidancbrady 2015-11-28 08:58:26 -07:00
parent f88a97697f
commit a71b6bda01
8 changed files with 234 additions and 167 deletions

View file

@ -1,30 +1,22 @@
package mekanism.client;
import static mekanism.client.sound.SoundHandler.Channel.FLAMETHROWER;
import static mekanism.client.sound.SoundHandler.Channel.GASMASK;
import static mekanism.client.sound.SoundHandler.Channel.JETPACK;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mekanism.api.IClientTicker;
import mekanism.api.MekanismConfig.client;
import mekanism.api.gas.GasStack;
import mekanism.client.sound.SoundHandler;
import mekanism.common.KeySync;
import mekanism.common.Mekanism;
import mekanism.common.ObfuscatedNames;
import mekanism.common.item.ItemFlamethrower;
import mekanism.common.item.ItemFreeRunners;
import mekanism.common.item.ItemGasMask;
import mekanism.common.item.ItemJetpack;
import mekanism.common.item.*;
import mekanism.common.item.ItemJetpack.JetpackMode;
import mekanism.common.item.ItemScubaTank;
import mekanism.common.network.PacketFlamethrowerActive.FlamethrowerActiveMessage;
import mekanism.common.network.PacketFlamethrowerData;
import mekanism.common.network.PacketFlamethrowerData.FlamethrowerDataMessage;
import mekanism.common.network.PacketJetpackData.JetpackDataMessage;
import mekanism.common.network.PacketJetpackData.JetpackPacket;
import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage;
@ -36,14 +28,9 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.StringUtils;
import com.mojang.authlib.minecraft.MinecraftProfileTexture;
import java.util.*;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.TickEvent.ClientTickEvent;
import cpw.mods.fml.common.gameevent.TickEvent.Phase;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import static mekanism.client.sound.SoundHandler.Channel.*;
/**
* Client-side tick handler for Mekanism. Used mainly for the update check upon startup.
@ -220,7 +207,7 @@ public class ClientTickHandler
Mekanism.flamethrowerActive.remove(mc.thePlayer.getCommandSenderName());
}
Mekanism.packetHandler.sendToServer(new FlamethrowerActiveMessage(mc.thePlayer.getCommandSenderName(), isFlamethrowerOn(mc.thePlayer)));
Mekanism.packetHandler.sendToServer(new FlamethrowerDataMessage(PacketFlamethrowerData.FlamethrowerPacket.UPDATE, mc.thePlayer.getCommandSenderName(), isFlamethrowerOn(mc.thePlayer)));
}
if(Mekanism.jetpackOn.contains(mc.thePlayer.getCommandSenderName()) != isJetpackOn(mc.thePlayer))

View file

@ -1,20 +1,23 @@
package mekanism.client;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mekanism.api.EnumColor;
import mekanism.api.util.StackUtils;
import mekanism.client.sound.SoundHandler;
import mekanism.common.Mekanism;
import mekanism.common.block.BlockMachine.MachineType;
import mekanism.common.item.ItemBlockMachine;
import mekanism.common.item.ItemConfigurator;
import mekanism.common.item.*;
import mekanism.common.item.ItemConfigurator.ConfiguratorMode;
import mekanism.common.item.ItemElectricBow;
import mekanism.common.item.ItemJetpack;
import mekanism.common.item.ItemJetpack.JetpackMode;
import mekanism.common.item.ItemScubaTank;
import mekanism.common.item.ItemWalkieTalkie;
import mekanism.common.network.PacketConfiguratorState.ConfiguratorStateMessage;
import mekanism.common.network.PacketElectricBowState.ElectricBowStateMessage;
import mekanism.common.network.PacketFlamethrowerData;
import mekanism.common.network.PacketJetpackData.JetpackDataMessage;
import mekanism.common.network.PacketJetpackData.JetpackPacket;
import mekanism.common.network.PacketPortableTankState.PortableTankStateMessage;
@ -28,17 +31,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.ChatComponentText;
import org.lwjgl.input.Keyboard;
import cpw.mods.fml.client.FMLClientHandler;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.common.gameevent.InputEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class MekanismKeyHandler extends MekKeyHandler
{
@ -91,7 +85,7 @@ public class MekanismKeyHandler extends MekKeyHandler
bow.setFireState(toolStack, !bow.getFireState(toolStack));
Mekanism.packetHandler.sendToServer(new ElectricBowStateMessage(bow.getFireState(toolStack)));
player.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + LangUtils.localize("tooltip.fireMode") + ": " + (bow.getFireState(toolStack) ? EnumColor.DARK_GREEN : EnumColor.DARK_RED) + LangUtils.transYesNo(bow.getFireState(toolStack))));
player.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + LangUtils.localize("tooltip.fireMode") + ": " + (bow.getFireState(toolStack) ? EnumColor.DARK_GREEN : EnumColor.DARK_RED) + LangUtils.transOnOff(bow.getFireState(toolStack))));
}
else if(player.isSneaking() && item instanceof ItemBlockMachine)
{
@ -101,7 +95,7 @@ public class MekanismKeyHandler extends MekKeyHandler
{
machine.setBucketMode(toolStack, !machine.getBucketMode(toolStack));
Mekanism.packetHandler.sendToServer(new PortableTankStateMessage(machine.getBucketMode(toolStack)));
player.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + LangUtils.localize("tooltip.portableTank.bucketMode") + ": " + (machine.getBucketMode(toolStack) ? (EnumColor.DARK_GREEN + "ON") : (EnumColor.DARK_RED + "OFF"))));
player.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + LangUtils.localize("tooltip.portableTank.bucketMode") + ": " + (machine.getBucketMode(toolStack) ? EnumColor.DARK_GREEN : EnumColor.DARK_RED) + LangUtils.transOnOff(machine.getBucketMode(toolStack))));
}
}
else if(player.isSneaking() && item instanceof ItemWalkieTalkie)
@ -116,6 +110,14 @@ public class MekanismKeyHandler extends MekKeyHandler
SoundHandler.playSound("mekanism:etc.Ding");
}
}
else if(player.isSneaking() && item instanceof ItemFlamethrower)
{
ItemFlamethrower flamethrower = (ItemFlamethrower)item;
flamethrower.incrementMode(toolStack);
Mekanism.packetHandler.sendToServer(new PacketFlamethrowerData.FlamethrowerDataMessage(PacketFlamethrowerData.FlamethrowerPacket.MODE, null, false));
player.addChatMessage(new ChatComponentText(EnumColor.DARK_BLUE + "[Mekanism] " + EnumColor.GREY + LangUtils.localize("tooltip.flamethrower.modeBump") + ": " + flamethrower.getMode(toolStack).getName()));
}
}
else if(kb == armorModeSwitchKey)
{

View file

@ -1,67 +1,41 @@
package mekanism.common;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
import io.netty.buffer.ByteBuf;
import java.util.ArrayList;
import java.util.List;
import mekanism.api.MekanismConfig.general;
import mekanism.api.Range4D;
import mekanism.common.network.PacketBoxBlacklist;
import mekanism.common.network.*;
import mekanism.common.network.PacketBoxBlacklist.BoxBlacklistMessage;
import mekanism.common.network.PacketConfigSync;
import mekanism.common.network.PacketConfigSync.ConfigSyncMessage;
import mekanism.common.network.PacketConfigurationUpdate;
import mekanism.common.network.PacketConfigurationUpdate.ConfigurationUpdateMessage;
import mekanism.common.network.PacketConfiguratorState;
import mekanism.common.network.PacketConfiguratorState.ConfiguratorStateMessage;
import mekanism.common.network.PacketContainerEditMode;
import mekanism.common.network.PacketContainerEditMode.ContainerEditModeMessage;
import mekanism.common.network.PacketDataRequest;
import mekanism.common.network.PacketDataRequest.DataRequestMessage;
import mekanism.common.network.PacketDigitalMinerGui;
import mekanism.common.network.PacketDigitalMinerGui.DigitalMinerGuiMessage;
import mekanism.common.network.PacketDropperUse;
import mekanism.common.network.PacketDropperUse.DropperUseMessage;
import mekanism.common.network.PacketEditFilter;
import mekanism.common.network.PacketEditFilter.EditFilterMessage;
import mekanism.common.network.PacketElectricBowState;
import mekanism.common.network.PacketElectricBowState.ElectricBowStateMessage;
import mekanism.common.network.PacketElectricChest;
import mekanism.common.network.PacketElectricChest.ElectricChestMessage;
import mekanism.common.network.PacketFlamethrowerActive;
import mekanism.common.network.PacketFlamethrowerActive.FlamethrowerActiveMessage;
import mekanism.common.network.PacketJetpackData;
import mekanism.common.network.PacketFlamethrowerData.FlamethrowerDataMessage;
import mekanism.common.network.PacketJetpackData.JetpackDataMessage;
import mekanism.common.network.PacketKey;
import mekanism.common.network.PacketKey.KeyMessage;
import mekanism.common.network.PacketLogisticalSorterGui;
import mekanism.common.network.PacketLogisticalSorterGui.LogisticalSorterGuiMessage;
import mekanism.common.network.PacketNewFilter;
import mekanism.common.network.PacketNewFilter.NewFilterMessage;
import mekanism.common.network.PacketOredictionificatorGui;
import mekanism.common.network.PacketOredictionificatorGui.OredictionificatorGuiMessage;
import mekanism.common.network.PacketPortableTankState;
import mekanism.common.network.PacketPortableTankState.PortableTankStateMessage;
import mekanism.common.network.PacketPortableTeleporter;
import mekanism.common.network.PacketPortableTeleporter.PortableTeleporterMessage;
import mekanism.common.network.PacketPortalFX;
import mekanism.common.network.PacketPortalFX.PortalFXMessage;
import mekanism.common.network.PacketRedstoneControl;
import mekanism.common.network.PacketRedstoneControl.RedstoneControlMessage;
import mekanism.common.network.PacketRemoveUpgrade;
import mekanism.common.network.PacketRemoveUpgrade.RemoveUpgradeMessage;
import mekanism.common.network.PacketRobit;
import mekanism.common.network.PacketRobit.RobitMessage;
import mekanism.common.network.PacketScubaTankData;
import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage;
import mekanism.common.network.PacketSimpleGui;
import mekanism.common.network.PacketSimpleGui.SimpleGuiMessage;
import mekanism.common.network.PacketTileEntity;
import mekanism.common.network.PacketTileEntity.TileEntityMessage;
import mekanism.common.network.PacketTransmitterUpdate;
import mekanism.common.network.PacketTransmitterUpdate.TransmitterUpdateMessage;
import mekanism.common.network.PacketWalkieTalkieState;
import mekanism.common.network.PacketWalkieTalkieState.WalkieTalkieStateMessage;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
@ -73,11 +47,9 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Vec3;
import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper;
import cpw.mods.fml.relauncher.Side;
import java.util.ArrayList;
import java.util.List;
/**
* Mekanism packet handler. As always, use packets sparingly!
@ -126,8 +98,8 @@ public class PacketHandler
netHandler.registerMessage(PacketBoxBlacklist.class, BoxBlacklistMessage.class, 24, Side.CLIENT);
netHandler.registerMessage(PacketPortableTankState.class, PortableTankStateMessage.class, 25, Side.SERVER);
netHandler.registerMessage(PacketContainerEditMode.class, ContainerEditModeMessage.class, 26, Side.SERVER);
netHandler.registerMessage(PacketFlamethrowerActive.class, FlamethrowerActiveMessage.class, 27, Side.CLIENT);
netHandler.registerMessage(PacketFlamethrowerActive.class, FlamethrowerActiveMessage.class, 27, Side.SERVER);
netHandler.registerMessage(PacketFlamethrowerData.class, FlamethrowerDataMessage.class, 27, Side.CLIENT);
netHandler.registerMessage(PacketFlamethrowerData.class, FlamethrowerDataMessage.class, 27, Side.SERVER);
netHandler.registerMessage(PacketDropperUse.class, DropperUseMessage.class, 28, Side.SERVER);
}

View file

@ -1,13 +1,12 @@
package mekanism.common.entity;
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
import io.netty.buffer.ByteBuf;
import java.util.List;
import mekanism.api.Coord4D;
import mekanism.api.MekanismConfig.general;
import mekanism.api.Pos3D;
import mekanism.api.util.StackUtils;
import mekanism.common.item.ItemFlamethrower;
import mekanism.common.util.MekanismUtils;
import net.minecraft.block.Block;
import net.minecraft.entity.Entity;
@ -17,14 +16,11 @@ import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.FurnaceRecipes;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraft.util.MathHelper;
import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3;
import net.minecraft.util.*;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.registry.IEntityAdditionalSpawnData;
import java.util.List;
public class EntityFlame extends Entity implements IEntityAdditionalSpawnData
{
@ -32,6 +28,7 @@ public class EntityFlame extends Entity implements IEntityAdditionalSpawnData
public static final int DAMAGE = 10;
public Entity owner = null;
public ItemFlamethrower.FlamethrowerMode mode = ItemFlamethrower.FlamethrowerMode.COMBAT;
public EntityFlame(World world)
{
@ -63,6 +60,7 @@ public class EntityFlame extends Entity implements IEntityAdditionalSpawnData
motionZ = motion.zPos;
owner = player;
mode = ((ItemFlamethrower)player.getCurrentEquippedItem().getItem()).getMode(player.getCurrentEquippedItem());
}
public void setHeading(Pos3D motion)
@ -163,9 +161,9 @@ public class EntityFlame extends Entity implements IEntityAdditionalSpawnData
{
if(mop.entityHit != null && !mop.entityHit.isImmuneToFire())
{
if(mop.entityHit instanceof EntityItem)
if(mop.entityHit instanceof EntityItem && mode != ItemFlamethrower.FlamethrowerMode.COMBAT)
{
if(mop.entityHit.ticksExisted > 80)
if(mop.entityHit.ticksExisted > 100)
{
if(!smeltItem((EntityItem)mop.entityHit))
{
@ -186,9 +184,9 @@ public class EntityFlame extends Entity implements IEntityAdditionalSpawnData
if(general.aestheticWorldDamage && !fluid && (sideCoord.isAirBlock(worldObj) || sideCoord.isReplaceable(worldObj)))
{
if(!smeltBlock(new Coord4D(mop.blockX, mop.blockY, mop.blockZ)))
if(mode != ItemFlamethrower.FlamethrowerMode.COMBAT && !smeltBlock(new Coord4D(mop.blockX, mop.blockY, mop.blockZ)))
{
if(!worldObj.isRemote)
if(mode == ItemFlamethrower.FlamethrowerMode.INFERNO && !worldObj.isRemote)
{
worldObj.setBlock(sideCoord.xCoord, sideCoord.yCoord, sideCoord.zCoord, Blocks.fire);
}
@ -296,14 +294,26 @@ public class EntityFlame extends Entity implements IEntityAdditionalSpawnData
protected void entityInit() {}
@Override
protected void readEntityFromNBT(NBTTagCompound nbtTags) {}
protected void readEntityFromNBT(NBTTagCompound nbtTags)
{
mode = ItemFlamethrower.FlamethrowerMode.values()[nbtTags.getInteger("mode")];
}
@Override
protected void writeEntityToNBT(NBTTagCompound nbtTags) {}
protected void writeEntityToNBT(NBTTagCompound nbtTags)
{
nbtTags.setInteger("mode", mode.ordinal());
}
@Override
public void writeSpawnData(ByteBuf dataStream) {}
public void writeSpawnData(ByteBuf dataStream)
{
dataStream.writeInt(mode.ordinal());
}
@Override
public void readSpawnData(ByteBuf dataStream) {}
public void readSpawnData(ByteBuf dataStream)
{
mode = ItemFlamethrower.FlamethrowerMode.values()[dataStream.readInt()];
}
}

View file

@ -1,7 +1,8 @@
package mekanism.common.item;
import java.util.List;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import mekanism.api.EnumColor;
import mekanism.api.MekanismConfig.general;
import mekanism.api.gas.Gas;
import mekanism.api.gas.GasRegistry;
@ -14,8 +15,8 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
public class ItemFlamethrower extends ItemMekanism implements IGasItem
{
@ -41,6 +42,8 @@ public class ItemFlamethrower extends ItemMekanism implements IGasItem
else {
list.add(LangUtils.localize("tooltip.stored") + " " + gasStack.getGas().getLocalizedName() + ": " + gasStack.amount);
}
list.add(EnumColor.GREY + LangUtils.localize("tooltip.mode") + ": " + EnumColor.GREY + getMode(itemstack).getName());
}
@Override
@ -49,7 +52,7 @@ public class ItemFlamethrower extends ItemMekanism implements IGasItem
public void useGas(ItemStack stack)
{
setGas(stack, new GasStack(getGas(stack).getGas(), getGas(stack).amount-1));
setGas(stack, new GasStack(getGas(stack).getGas(), getGas(stack).amount - 1));
}
@Override
@ -175,4 +178,55 @@ public class ItemFlamethrower extends ItemMekanism implements IGasItem
setGas(filled, new GasStack(GasRegistry.getGas("hydrogen"), ((IGasItem)filled.getItem()).getMaxGas(filled)));
list.add(filled);
}
public void incrementMode(ItemStack stack)
{
setMode(stack, getMode(stack).increment());
}
public FlamethrowerMode getMode(ItemStack stack)
{
if(stack.stackTagCompound == null)
{
return FlamethrowerMode.COMBAT;
}
return FlamethrowerMode.values()[stack.stackTagCompound.getInteger("mode")];
}
public void setMode(ItemStack stack, FlamethrowerMode mode)
{
if(stack.stackTagCompound == null)
{
stack.setTagCompound(new NBTTagCompound());
}
stack.stackTagCompound.setInteger("mode", mode.ordinal());
}
public static enum FlamethrowerMode
{
COMBAT("tooltip.flamethrower.combat", EnumColor.YELLOW),
HEAT("tooltip.flamethrower.heat", EnumColor.ORANGE),
INFERNO("tooltip.flamethrower.inferno", EnumColor.DARK_RED);
private String unlocalized;
private EnumColor color;
private FlamethrowerMode(String s, EnumColor c)
{
unlocalized = s;
color = c;
}
public FlamethrowerMode increment()
{
return ordinal() < values().length-1 ? values()[ordinal()+1] : values()[0];
}
public String getName()
{
return color + LangUtils.localize(unlocalized);
}
}
}

View file

@ -1,62 +0,0 @@
package mekanism.common.network;
import io.netty.buffer.ByteBuf;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.network.PacketFlamethrowerActive.FlamethrowerActiveMessage;
import net.minecraft.entity.player.EntityPlayer;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
public class PacketFlamethrowerActive implements IMessageHandler<FlamethrowerActiveMessage, IMessage>
{
@Override
public IMessage onMessage(FlamethrowerActiveMessage message, MessageContext context)
{
EntityPlayer player = PacketHandler.getPlayer(context);
if(message.value)
{
Mekanism.flamethrowerActive.add(message.username);
}
else {
Mekanism.flamethrowerActive.remove(message.username);
}
if(!player.worldObj.isRemote)
{
Mekanism.packetHandler.sendToDimension(new FlamethrowerActiveMessage(message.username, message.value), player.worldObj.provider.dimensionId);
}
return null;
}
public static class FlamethrowerActiveMessage implements IMessage
{
public String username;
public boolean value;
public FlamethrowerActiveMessage() {}
public FlamethrowerActiveMessage(String name, boolean state)
{
username = name;
value = state;
}
@Override
public void toBytes(ByteBuf dataStream)
{
PacketHandler.writeString(dataStream, username);
dataStream.writeBoolean(value);
}
@Override
public void fromBytes(ByteBuf dataStream)
{
username = PacketHandler.readString(dataStream);
value = dataStream.readBoolean();
}
}
}

View file

@ -0,0 +1,99 @@
package mekanism.common.network;
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 mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.item.ItemFlamethrower;
import mekanism.common.network.PacketFlamethrowerData.FlamethrowerDataMessage;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
public class PacketFlamethrowerData implements IMessageHandler<FlamethrowerDataMessage, IMessage>
{
@Override
public IMessage onMessage(FlamethrowerDataMessage message, MessageContext context)
{
EntityPlayer player = PacketHandler.getPlayer(context);
if(message.packetType == FlamethrowerPacket.UPDATE)
{
if(message.value)
{
Mekanism.flamethrowerActive.add(message.username);
}
else {
Mekanism.flamethrowerActive.remove(message.username);
}
if(!player.worldObj.isRemote)
{
Mekanism.packetHandler.sendToDimension(new FlamethrowerDataMessage(FlamethrowerPacket.UPDATE, message.username, message.value), player.worldObj.provider.dimensionId);
}
}
else if(message.packetType == FlamethrowerPacket.MODE)
{
ItemStack stack = player.getCurrentEquippedItem();
if(stack != null && stack.getItem() instanceof ItemFlamethrower)
{
((ItemFlamethrower)stack.getItem()).incrementMode(stack);
}
}
return null;
}
public static class FlamethrowerDataMessage implements IMessage
{
public FlamethrowerPacket packetType;
public String username;
public boolean value;
public FlamethrowerDataMessage() {}
public FlamethrowerDataMessage(FlamethrowerPacket type, String name, boolean state)
{
packetType = type;
if(type == FlamethrowerPacket.UPDATE)
{
username = name;
value = state;
}
}
@Override
public void toBytes(ByteBuf dataStream)
{
dataStream.writeInt(packetType.ordinal());
if(packetType == FlamethrowerPacket.UPDATE)
{
PacketHandler.writeString(dataStream, username);
dataStream.writeBoolean(value);
}
}
@Override
public void fromBytes(ByteBuf dataStream)
{
packetType = FlamethrowerPacket.values()[dataStream.readInt()];
if(packetType == FlamethrowerPacket.UPDATE)
{
username = PacketHandler.readString(dataStream);
value = dataStream.readBoolean();
}
}
}
public static enum FlamethrowerPacket
{
UPDATE,
MODE;
}
}

View file

@ -685,6 +685,11 @@ tooltip.jetpack.regular=Regular
tooltip.jetpack.hover=Hover
tooltip.jetpack.disabled=Disabled
tooltip.flamethrower.combat=Combat
tooltip.flamethrower.heat=Heat
tooltip.flamethrower.inferno=Inferno
tooltip.flamethrower.modeBump=Flamethrower mode bumped to
tooltip.seismicReader.needsEnergy=Not enough energy to interpret vibration
tooltip.seismicReader.noVibrations=Unable to discover any vibrations