Skip to content

Commit

Permalink
Merge branch 'development' into 1.8.9
Browse files Browse the repository at this point in the history
  • Loading branch information
unpairedbracket committed May 1, 2016
2 parents 185ea3c + 4720e8f commit 85c6766
Show file tree
Hide file tree
Showing 20 changed files with 296 additions and 53 deletions.
8 changes: 8 additions & 0 deletions src/main/java/mekanism/client/MekanismClient.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package mekanism.client;

import java.util.HashMap;
import java.util.Map;

import mekanism.api.MekanismAPI;
import mekanism.api.MekanismAPI.BoxBlacklistEvent;
import mekanism.api.MekanismConfig.general;
Expand All @@ -9,12 +12,15 @@
import mekanism.common.base.IModule;
import mekanism.common.content.boiler.SynchronizedBoilerData;
import mekanism.common.network.PacketKey.KeyMessage;
import mekanism.common.security.SecurityData;
import net.minecraft.client.Minecraft;
import net.minecraft.client.settings.KeyBinding;
import net.minecraftforge.common.MinecraftForge;

public class MekanismClient extends Mekanism
{
public static Map<String, SecurityData> clientSecurityMap = new HashMap<String, SecurityData>();

public static VoiceClient voiceClient;

public static long ticksPassed = 0;
Expand All @@ -32,6 +38,8 @@ public static void updateKey(KeyBinding key, int type)

public static void reset()
{
clientSecurityMap.clear();

if(general.voiceServerEnabled)
{
if(MekanismClient.voiceClient != null)
Expand Down
14 changes: 8 additions & 6 deletions src/main/java/mekanism/client/gui/element/GuiSecurityTab.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.api.util.ListUtils;
import mekanism.client.MekanismClient;
import mekanism.client.gui.IGuiWrapper;
import mekanism.client.sound.SoundHandler;
import mekanism.common.Mekanism;
import mekanism.common.network.PacketSecurityMode.SecurityModeMessage;
import mekanism.common.security.ISecurityItem;
import mekanism.common.security.ISecurityTile;
import mekanism.common.security.ISecurityTile.SecurityMode;
import mekanism.common.security.SecurityData;
import mekanism.common.security.SecurityFrequency;
import mekanism.common.util.LangUtils;
import mekanism.common.util.MekanismUtils;
Expand Down Expand Up @@ -56,17 +58,17 @@ public void renderBackground(int xAxis, int yAxis, int guiWidth, int guiHeight)
guiObj.drawTexturedRect(guiWidth + 176, guiHeight + 32, 0, 0, 26, 26);

SecurityMode mode = getSecurity();
SecurityFrequency freq = getFrequency();
SecurityData data = MekanismClient.clientSecurityMap.get(getOwner());

if(freq != null && freq.override)
if(data != null && data.override)
{
mode = freq.securityMode;
mode = data.mode;
}

int renderX = 26 + (18*mode.ordinal());

if(getOwner() != null && getOwner().equals(mc.thePlayer.getName()) &&
(getFrequency() == null || !getFrequency().override))
(data == null || !data.override))
{
if(xAxis >= 179 && xAxis <= 197 && yAxis >= 36 && yAxis <= 54)
{
Expand All @@ -90,12 +92,12 @@ public void renderForeground(int xAxis, int yAxis)

if(xAxis >= 179 && xAxis <= 197 && yAxis >= 36 && yAxis <= 54)
{
String securityDisplay = isItem ? SecurityUtils.getSecurityDisplay(getItem()) : SecurityUtils.getSecurityDisplay(tileEntity);
String securityDisplay = isItem ? SecurityUtils.getSecurityDisplay(getItem(), Side.CLIENT) : SecurityUtils.getSecurityDisplay(tileEntity, Side.CLIENT);
String securityText = EnumColor.GREY + LangUtils.localize("gui.security") + ": " + securityDisplay;
String ownerText = SecurityUtils.getOwnerDisplay(mc.thePlayer.getName(), getOwner());
String overrideText = EnumColor.RED + "(" + LangUtils.localize("gui.overridden") + ")";

if(isItem ? SecurityUtils.isOverridden(getItem()) : SecurityUtils.isOverridden(tileEntity))
if(isItem ? SecurityUtils.isOverridden(getItem(), Side.CLIENT) : SecurityUtils.isOverridden(tileEntity, Side.CLIENT))
{
displayTooltips(ListUtils.asList(securityText, ownerText, overrideText), xAxis, yAxis);
}
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/mekanism/common/CommonPlayerTracker.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import mekanism.common.network.PacketJetpackData.JetpackPacket;
import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage;
import mekanism.common.network.PacketScubaTankData.ScubaTankPacket;
import mekanism.common.network.PacketSecurityUpdate.SecurityPacket;
import mekanism.common.network.PacketSecurityUpdate.SecurityUpdateMessage;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
Expand All @@ -29,6 +31,7 @@ public void onPlayerLoginEvent(PlayerLoggedInEvent event)
Mekanism.packetHandler.sendTo(new BoxBlacklistMessage(), (EntityPlayerMP)event.player);
Mekanism.packetHandler.sendTo(new JetpackDataMessage(JetpackPacket.FULL, null, false), (EntityPlayerMP)event.player);
Mekanism.packetHandler.sendTo(new ScubaTankDataMessage(ScubaTankPacket.FULL, null, false), (EntityPlayerMP)event.player);
Mekanism.packetHandler.sendTo(new SecurityUpdateMessage(SecurityPacket.FULL, null, null), (EntityPlayerMP)event.player);

Mekanism.logger.info("Sent config to '" + event.player.getDisplayName() + ".'");
}
Expand Down
17 changes: 17 additions & 0 deletions src/main/java/mekanism/common/PacketHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,8 @@
import mekanism.common.network.PacketScubaTankData.ScubaTankDataMessage;
import mekanism.common.network.PacketSecurityMode;
import mekanism.common.network.PacketSecurityMode.SecurityModeMessage;
import mekanism.common.network.PacketSecurityUpdate;
import mekanism.common.network.PacketSecurityUpdate.SecurityUpdateMessage;
import mekanism.common.network.PacketSimpleGui;
import mekanism.common.network.PacketSimpleGui.SimpleGuiMessage;
import mekanism.common.network.PacketTileEntity;
Expand Down Expand Up @@ -138,6 +140,7 @@ public void initialize()
netHandler.registerMessage(PacketFlamethrowerData.class, FlamethrowerDataMessage.class, 27, Side.SERVER);
netHandler.registerMessage(PacketDropperUse.class, DropperUseMessage.class, 28, Side.SERVER);
netHandler.registerMessage(PacketEntityMove.class, EntityMoveMessage.class, 29, Side.CLIENT);
netHandler.registerMessage(PacketSecurityUpdate.class, SecurityUpdateMessage.class, 30, Side.CLIENT);
}

/**
Expand Down Expand Up @@ -271,6 +274,20 @@ public void sendTo(IMessage message, EntityPlayerMP player)
{
netHandler.sendTo(message, player);
}

/**
* Send this message to everyone connected to the server.
* @param message - message to send
*/
public void sendToAll(IMessage message)
{
MinecraftServer server = MinecraftServer.getServer();

for(EntityPlayerMP player : server.getConfigurationManager().playerEntityList)
{
sendTo(message, player);
}
}

/**
* Send this message to everyone within a certain range of a point.
Expand Down
1 change: 0 additions & 1 deletion src/main/java/mekanism/common/block/BlockEnergyCube.java
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,6 @@ public void getSubBlocks(Item item, CreativeTabs creativetabs, List<ItemStack> l
for(EnergyCubeTier tier : EnergyCubeTier.values())
{
ItemStack discharged = new ItemStack(this);
discharged.setItemDamage(100);
((ItemBlockEnergyCube)discharged.getItem()).setEnergyCubeTier(discharged, tier);
list.add(discharged);
ItemStack charged = new ItemStack(this);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import mcp.mobius.waila.api.IWailaRegistrar;
import mekanism.api.Coord4D;
import mekanism.api.EnumColor;
import mekanism.common.tile.TileEntityAdvancedBoundingBlock;
import mekanism.common.tile.TileEntityBin;
import mekanism.common.tile.TileEntityBoundingBlock;
import mekanism.common.tile.TileEntityEnergyCube;
Expand Down Expand Up @@ -38,6 +39,7 @@ public static void register(IWailaRegistrar registrar)
registrar.registerHeadProvider(provider, TileEntityInductionProvider.class);
registrar.registerHeadProvider(provider, TileEntityFactory.class);
registrar.registerHeadProvider(provider, TileEntityBoundingBlock.class);
registrar.registerHeadProvider(provider, TileEntityAdvancedBoundingBlock.class);
registrar.registerHeadProvider(provider, TileEntityFluidTank.class);
registrar.registerHeadProvider(provider, TileEntityGasTank.class);
registrar.registerHeadProvider(provider, TileEntityBin.class);
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/mekanism/common/item/ItemBlockEnergyCube.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,6 @@ public ItemBlockEnergyCube(Block block)
super(block);
metaBlock = block;
setMaxStackSize(1);
setMaxDamage(100);
setNoRepair();
setCreativeTab(Mekanism.tabMekanism);
}
Expand All @@ -77,9 +76,9 @@ public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List<
if(hasSecurity(itemstack))
{
list.add(SecurityUtils.getOwnerDisplay(entityplayer.getName(), getOwner(itemstack)));
list.add(EnumColor.GREY + LangUtils.localize("gui.security") + ": " + SecurityUtils.getSecurityDisplay(itemstack));
list.add(EnumColor.GREY + LangUtils.localize("gui.security") + ": " + SecurityUtils.getSecurityDisplay(itemstack, Side.CLIENT));

if(SecurityUtils.isOverridden(itemstack))
if(SecurityUtils.isOverridden(itemstack, Side.CLIENT))
{
list.add(EnumColor.RED + "(" + LangUtils.localize("gui.overridden") + ")");
}
Expand All @@ -93,7 +92,6 @@ public ItemStack getUnchargedItem(EnergyCubeTier tier)
{
ItemStack stack = new ItemStack(this);
setEnergyCubeTier(stack, tier);
stack.setItemDamage(100);

return stack;
}
Expand Down
5 changes: 3 additions & 2 deletions src/main/java/mekanism/common/item/ItemBlockGasTank.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
import net.minecraft.util.EnumFacing;
import net.minecraft.world.World;
import net.minecraftforge.common.util.Constants.NBT;
import net.minecraftforge.fml.relauncher.Side;

public class ItemBlockGasTank extends ItemBlock implements IGasItem, ISustainedInventory, ITierItem, ISecurityItem
{
Expand Down Expand Up @@ -131,9 +132,9 @@ public void addInformation(ItemStack itemstack, EntityPlayer entityplayer, List<
if(hasSecurity(itemstack))
{
list.add(SecurityUtils.getOwnerDisplay(entityplayer.getName(), getOwner(itemstack)));
list.add(EnumColor.GREY + LangUtils.localize("gui.security") + ": " + SecurityUtils.getSecurityDisplay(itemstack));
list.add(EnumColor.GREY + LangUtils.localize("gui.security") + ": " + SecurityUtils.getSecurityDisplay(itemstack, Side.CLIENT));

if(SecurityUtils.isOverridden(itemstack))
if(SecurityUtils.isOverridden(itemstack, Side.CLIENT))
{
list.add(EnumColor.RED + "(" + LangUtils.localize("gui.overridden") + ")");
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/mekanism/common/item/ItemBlockMachine.java
Original file line number Diff line number Diff line change
Expand Up @@ -194,9 +194,9 @@ else if(!MekKeyHandler.getIsKeyPressed(MekanismKeyHandler.modeSwitchKey))
if(hasSecurity(itemstack))
{
list.add(SecurityUtils.getOwnerDisplay(entityplayer.getName(), getOwner(itemstack)));
list.add(EnumColor.GREY + LangUtils.localize("gui.security") + ": " + SecurityUtils.getSecurityDisplay(itemstack));
list.add(EnumColor.GREY + LangUtils.localize("gui.security") + ": " + SecurityUtils.getSecurityDisplay(itemstack, Side.CLIENT));

if(SecurityUtils.isOverridden(itemstack))
if(SecurityUtils.isOverridden(itemstack, Side.CLIENT))
{
list.add(EnumColor.RED + "(" + LangUtils.localize("gui.overridden") + ")");
}
Expand Down
116 changes: 116 additions & 0 deletions src/main/java/mekanism/common/network/PacketSecurityUpdate.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
package mekanism.common.network;

import io.netty.buffer.ByteBuf;

import java.util.ArrayList;
import java.util.List;

import mekanism.client.MekanismClient;
import mekanism.common.Mekanism;
import mekanism.common.PacketHandler;
import mekanism.common.frequency.Frequency;
import mekanism.common.network.PacketSecurityUpdate.SecurityUpdateMessage;
import mekanism.common.security.SecurityData;
import mekanism.common.security.SecurityFrequency;
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 PacketSecurityUpdate implements IMessageHandler<SecurityUpdateMessage, IMessage>
{
@Override
public IMessage onMessage(SecurityUpdateMessage message, MessageContext context)
{
if(message.packetType == SecurityPacket.UPDATE)
{
MekanismClient.clientSecurityMap.put(message.playerUsername, message.securityData);
}

return null;
}

public static class SecurityUpdateMessage implements IMessage
{
public SecurityPacket packetType;

public String playerUsername;
public SecurityData securityData;

public SecurityUpdateMessage() {}

public SecurityUpdateMessage(SecurityPacket type, String username, SecurityData data)
{
packetType = type;

if(packetType == SecurityPacket.UPDATE)
{
playerUsername = username;
securityData = data;
}
}

@Override
public void toBytes(ByteBuf dataStream)
{
dataStream.writeInt(packetType.ordinal());

if(packetType == SecurityPacket.UPDATE)
{
PacketHandler.writeString(dataStream, playerUsername);
securityData.write(dataStream);
}
else if(packetType == SecurityPacket.FULL)
{
List<SecurityFrequency> frequencies = new ArrayList<SecurityFrequency>();

for(Frequency frequency : Mekanism.securityFrequencies.getFrequencies())
{
if(frequency instanceof SecurityFrequency)
{
frequencies.add((SecurityFrequency)frequency);
}
}

dataStream.writeInt(frequencies.size());

for(SecurityFrequency frequency : frequencies)
{
PacketHandler.writeString(dataStream, frequency.owner);
new SecurityData(frequency).write(dataStream);
}
}
}

@Override
public void fromBytes(ByteBuf dataStream)
{
packetType = SecurityPacket.values()[dataStream.readInt()];

if(packetType == SecurityPacket.UPDATE)
{
playerUsername = PacketHandler.readString(dataStream);
securityData = SecurityData.read(dataStream);
}
else if(packetType == SecurityPacket.FULL)
{
MekanismClient.clientSecurityMap.clear();

int amount = dataStream.readInt();

for(int i = 0; i < amount; i++)
{
String owner = PacketHandler.readString(dataStream);
SecurityData data = SecurityData.read(dataStream);

MekanismClient.clientSecurityMap.put(owner, data);
}
}
}
}

public static enum SecurityPacket
{
UPDATE,
FULL;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public abstract class MachineInput<INPUT extends MachineInput<INPUT>>

public static boolean inputContains(ItemStack container, ItemStack contained)
{
if(container.stackSize >= contained.stackSize)
if(container != null && container.stackSize >= contained.stackSize)
{
if(MekanismUtils.getOreDictName(container).contains("treeSapling"))
{
Expand Down
34 changes: 34 additions & 0 deletions src/main/java/mekanism/common/security/SecurityData.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package mekanism.common.security;

import io.netty.buffer.ByteBuf;
import mekanism.common.security.ISecurityTile.SecurityMode;

public class SecurityData
{
public SecurityMode mode = SecurityMode.PUBLIC;
public boolean override;

public SecurityData() {}

public SecurityData(SecurityFrequency frequency)
{
mode = frequency.securityMode;
override = frequency.override;
}

public void write(ByteBuf dataStream)
{
dataStream.writeInt(mode.ordinal());
dataStream.writeBoolean(override);
}

public static SecurityData read(ByteBuf dataStream)
{
SecurityData data = new SecurityData();

data.mode = SecurityMode.values()[dataStream.readInt()];
data.override = dataStream.readBoolean();

return data;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,12 @@ public boolean canSetFacing(int side)
return side != 0 && side != 1;
}

@Override
public int[] getSlotsForFace(EnumFacing side)
{
return new int[] {0};
}

@Override
public void setActive(boolean active)
{
Expand Down
Loading

0 comments on commit 85c6766

Please sign in to comment.