Fix a few bugs, work on jetpack networking
This commit is contained in:
parent
91eafd02aa
commit
2914a4201d
8 changed files with 208 additions and 9 deletions
|
@ -67,6 +67,7 @@ public class ClientConnectionHandler implements IConnectionHandler
|
|||
}
|
||||
|
||||
ClientTickHandler.tickingSet.clear();
|
||||
Mekanism.jetpackOn.clear();
|
||||
Mekanism.proxy.unloadSoundHandler();
|
||||
}
|
||||
|
||||
|
|
|
@ -1,24 +1,23 @@
|
|||
package mekanism.client;
|
||||
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
import mekanism.api.EnumColor;
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.PacketHandler.Transmission;
|
||||
import mekanism.common.item.ItemConfigurator;
|
||||
import mekanism.common.item.ItemElectricBow;
|
||||
import mekanism.common.item.ItemJetpack;
|
||||
import mekanism.common.item.ItemWalkieTalkie;
|
||||
import mekanism.common.network.PacketConfiguratorState;
|
||||
import mekanism.common.network.PacketElectricBowState;
|
||||
import mekanism.common.network.PacketWalkieTalkieState;
|
||||
import mekanism.common.tileentity.TileEntityUniversalCable;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
import cpw.mods.fml.common.ITickHandler;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
|
@ -103,9 +102,36 @@ public class ClientPlayerTickHandler implements ITickHandler
|
|||
lastTickUpdate = false;
|
||||
}
|
||||
}
|
||||
|
||||
if(cacheJetpackOn(entityPlayer) != isJetpackOn(entityPlayer))
|
||||
{
|
||||
System.out.println("update");
|
||||
Mekanism.jetpackOn.put(entityPlayer, isJetpackOn(entityPlayer));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean cacheJetpackOn(EntityPlayer player)
|
||||
{
|
||||
return Mekanism.jetpackOn.get(player) != null ? Mekanism.jetpackOn.get(player) : false;
|
||||
}
|
||||
|
||||
private boolean isJetpackOn(EntityPlayer player)
|
||||
{
|
||||
if(player.inventory.armorInventory[2] != null)
|
||||
{
|
||||
if(player.inventory.armorInventory[2].getItem() instanceof ItemJetpack)
|
||||
{
|
||||
if(Keyboard.isKeyDown(Keyboard.KEY_SPACE))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<TickType> ticks()
|
||||
{
|
||||
|
|
36
common/mekanism/common/CommonPlayerTracker.java
Normal file
36
common/mekanism/common/CommonPlayerTracker.java
Normal file
|
@ -0,0 +1,36 @@
|
|||
package mekanism.common;
|
||||
import mekanism.common.PacketHandler.Transmission;
|
||||
import mekanism.common.network.PacketJetpackData;
|
||||
import mekanism.common.network.PacketJetpackData.PacketType;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import cpw.mods.fml.common.IPlayerTracker;
|
||||
|
||||
public class CommonPlayerTracker implements IPlayerTracker
|
||||
{
|
||||
@Override
|
||||
public void onPlayerLogin(EntityPlayer player)
|
||||
{
|
||||
if(!player.worldObj.isRemote)
|
||||
{
|
||||
PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketJetpackData().setParams(PacketType.INITIAL), player.worldObj.provider.dimensionId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerLogout(EntityPlayer player)
|
||||
{
|
||||
Mekanism.jetpackOn.remove(player);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerChangedDimension(EntityPlayer player)
|
||||
{
|
||||
if(!player.worldObj.isRemote)
|
||||
{
|
||||
PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketJetpackData().setParams(PacketType.INITIAL), player.worldObj.provider.dimensionId);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPlayerRespawn(EntityPlayer player) {}
|
||||
}
|
|
@ -69,6 +69,7 @@ import mekanism.common.network.PacketDigitalMinerGui;
|
|||
import mekanism.common.network.PacketEditFilter;
|
||||
import mekanism.common.network.PacketElectricBowState;
|
||||
import mekanism.common.network.PacketElectricChest;
|
||||
import mekanism.common.network.PacketJetpackData;
|
||||
import mekanism.common.network.PacketLogisticalSorterGui;
|
||||
import mekanism.common.network.PacketNewFilter;
|
||||
import mekanism.common.network.PacketPortableTeleport;
|
||||
|
@ -91,6 +92,7 @@ import mekanism.common.util.MekanismUtils;
|
|||
import mekanism.common.util.MekanismUtils.ResourceType;
|
||||
import mekanism.common.voice.VoiceServerManager;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.crafting.CraftingManager;
|
||||
|
@ -176,6 +178,8 @@ public class Mekanism
|
|||
/** A list of the usernames of players who have donated to Mekanism. */
|
||||
public static List<String> donators = new ArrayList<String>();
|
||||
|
||||
public static Map<EntityPlayer, Boolean> jetpackOn = new HashMap<EntityPlayer, Boolean>();
|
||||
|
||||
public static Set<Object3D> ic2Registered = new HashSet<Object3D>();
|
||||
|
||||
//Block IDs
|
||||
|
@ -688,6 +692,8 @@ public class Mekanism
|
|||
|
||||
//MC stuff
|
||||
OreDictionary.registerOre("oreCoal", new ItemStack(Block.oreCoal));
|
||||
OreDictionary.registerOre("ingotIron", new ItemStack(Item.ingotIron));
|
||||
OreDictionary.registerOre("ingotGold", new ItemStack(Item.ingotGold));
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -1092,6 +1098,7 @@ public class Mekanism
|
|||
teleporters.clear();
|
||||
dynamicInventories.clear();
|
||||
ic2Registered.clear();
|
||||
jetpackOn.clear();
|
||||
TransporterManager.flowingStacks.clear();
|
||||
}
|
||||
|
||||
|
@ -1133,6 +1140,9 @@ public class Mekanism
|
|||
//Register the mod's ore handler
|
||||
GameRegistry.registerWorldGenerator(new OreHandler());
|
||||
|
||||
//Register player tracker
|
||||
GameRegistry.registerPlayerTracker(new CommonPlayerTracker());
|
||||
|
||||
//Register the mod's GUI handler
|
||||
NetworkRegistry.instance().registerGuiHandler(this, new CoreGuiHandler());
|
||||
|
||||
|
@ -1186,6 +1196,7 @@ public class Mekanism
|
|||
PacketHandler.registerPacket(PacketConfigurationUpdate.class);
|
||||
PacketHandler.registerPacket(PacketSimpleGui.class);
|
||||
PacketHandler.registerPacket(PacketDigitalMinerGui.class);
|
||||
PacketHandler.registerPacket(PacketJetpackData.class);
|
||||
|
||||
//Donators
|
||||
donators.add("mrgreaper");
|
||||
|
|
|
@ -1,6 +1,7 @@
|
|||
package mekanism.common.item;
|
||||
|
||||
import mekanism.api.gas.Gas;
|
||||
import mekanism.api.gas.GasRegistry;
|
||||
import mekanism.api.gas.GasStack;
|
||||
import mekanism.api.gas.IGasItem;
|
||||
import mekanism.client.render.ModelCustomArmor;
|
||||
|
@ -72,6 +73,11 @@ public class ItemJetpack extends ItemArmor implements IGasItem
|
|||
return 0;
|
||||
}
|
||||
|
||||
if(stack.getGas() != GasRegistry.getGas("hydrogen"))
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
int toUse = Math.min(getMaxGas(itemstack)-getStored(itemstack), Math.min(getRate(itemstack), stack.amount));
|
||||
setGas(new GasStack(stack.getGas(), getStored(itemstack)+toUse), itemstack);
|
||||
|
||||
|
@ -102,7 +108,7 @@ public class ItemJetpack extends ItemArmor implements IGasItem
|
|||
@Override
|
||||
public boolean canReceiveGas(ItemStack itemstack, Gas type)
|
||||
{
|
||||
return getGas(itemstack) == null || getGas(itemstack).getGas() == type;
|
||||
return type == GasRegistry.getGas("hydrogen");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
117
common/mekanism/common/network/PacketJetpackData.java
Normal file
117
common/mekanism/common/network/PacketJetpackData.java
Normal file
|
@ -0,0 +1,117 @@
|
|||
package mekanism.common.network;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import mekanism.common.Mekanism;
|
||||
import mekanism.common.PacketHandler;
|
||||
import mekanism.common.PacketHandler.Transmission;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
public class PacketJetpackData implements IMekanismPacket
|
||||
{
|
||||
public PacketType packetType;
|
||||
|
||||
public EntityPlayer updatePlayer;
|
||||
public boolean value;
|
||||
|
||||
@Override
|
||||
public String getName()
|
||||
{
|
||||
return "RedstoneControl";
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMekanismPacket setParams(Object... data)
|
||||
{
|
||||
packetType = (PacketType)data[0];
|
||||
|
||||
if(packetType == PacketType.UPDATE)
|
||||
{
|
||||
updatePlayer = (EntityPlayer)data[1];
|
||||
value = (Boolean)data[2];
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void read(ByteArrayDataInput dataStream, EntityPlayer player, World world) throws Exception
|
||||
{
|
||||
packetType = PacketType.values()[dataStream.readInt()];
|
||||
|
||||
if(packetType == PacketType.INITIAL)
|
||||
{
|
||||
Mekanism.jetpackOn.clear();
|
||||
|
||||
int amount = dataStream.readInt();
|
||||
|
||||
for(int i = 0; i < amount; i++)
|
||||
{
|
||||
EntityPlayer p = world.getPlayerEntityByName(dataStream.readUTF());
|
||||
|
||||
if(p != null)
|
||||
{
|
||||
Mekanism.jetpackOn.put(p, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(packetType == PacketType.UPDATE)
|
||||
{
|
||||
String username = dataStream.readUTF();
|
||||
boolean value = dataStream.readBoolean();
|
||||
|
||||
EntityPlayer p = FMLCommonHandler.instance().getMinecraftServerInstance().getConfigurationManager().getPlayerForUsername(username);
|
||||
|
||||
if(p != null)
|
||||
{
|
||||
Mekanism.jetpackOn.put(p, value);
|
||||
|
||||
PacketHandler.sendPacket(Transmission.CLIENTS_DIM, new PacketJetpackData().setParams(PacketType.UPDATE, p, value), world.provider.dimensionId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void write(DataOutputStream dataStream) throws Exception
|
||||
{
|
||||
dataStream.writeInt(packetType.ordinal());
|
||||
|
||||
if(packetType == PacketType.UPDATE)
|
||||
{
|
||||
dataStream.writeUTF(updatePlayer.username);
|
||||
dataStream.writeBoolean(value);
|
||||
}
|
||||
else if(packetType == PacketType.INITIAL)
|
||||
{
|
||||
List<EntityPlayer> toSend = new ArrayList<EntityPlayer>();
|
||||
|
||||
for(Map.Entry<EntityPlayer, Boolean> entry : Mekanism.jetpackOn.entrySet())
|
||||
{
|
||||
if(entry.getValue())
|
||||
{
|
||||
toSend.add(entry.getKey());
|
||||
}
|
||||
}
|
||||
|
||||
dataStream.writeInt(toSend.size());
|
||||
|
||||
for(EntityPlayer player : toSend)
|
||||
{
|
||||
dataStream.writeUTF(player.username);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static enum PacketType
|
||||
{
|
||||
INITIAL, UPDATE
|
||||
}
|
||||
}
|
|
@ -1,7 +1,6 @@
|
|||
package mekanism.common.network;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.util.Random;
|
||||
|
||||
import mekanism.api.Object3D;
|
||||
import mekanism.common.IRedstoneControl;
|
||||
|
@ -35,8 +34,6 @@ public class PacketRedstoneControl implements IMekanismPacket
|
|||
@Override
|
||||
public void read(ByteArrayDataInput dataStream, EntityPlayer player, World world) throws Exception
|
||||
{
|
||||
Random random = new Random();
|
||||
|
||||
Object3D obj = new Object3D(dataStream.readInt(), dataStream.readInt(), dataStream.readInt());
|
||||
RedstoneControl control = RedstoneControl.values()[dataStream.readInt()];
|
||||
|
||||
|
|
|
@ -465,6 +465,11 @@ public class TileEntityBin extends TileEntityBasicBlock implements ISidedInvento
|
|||
@Override
|
||||
public ItemStack getStoredItemType()
|
||||
{
|
||||
if(itemType == null)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return MekanismUtils.size(itemType, itemCount);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue