Removing stuff
This commit is contained in:
parent
24d024e0e1
commit
1cfe9414df
43 changed files with 15 additions and 2133 deletions
|
@ -1,6 +1,5 @@
|
|||
package com.builtbroken.minecraft;
|
||||
|
||||
import java.awt.Color;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -8,17 +7,11 @@ import net.minecraft.block.Block;
|
|||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
import com.builtbroken.common.Pair;
|
||||
import com.builtbroken.minecraft.IExtraInfo.IExtraBlockInfo;
|
||||
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.client.registry.ClientRegistry;
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
|
||||
public class ClientRegistryProxy extends RegistryProxy
|
||||
|
@ -37,13 +30,4 @@ public class ClientRegistryProxy extends RegistryProxy
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderBeam(World world, Vector3 position, Vector3 target, Color color, int age)
|
||||
{
|
||||
if (world.isRemote || FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
|
||||
{
|
||||
FMLClientHandler.instance().getClient().effectRenderer.addEffect(new FXBeam(world, position, target, color, DarkCore.TEXTURE_DIRECTORY + "", age));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -8,7 +8,6 @@ import net.minecraft.server.MinecraftServer;
|
|||
import net.minecraftforge.common.Configuration;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
|
||||
import com.builtbroken.minecraft.fluid.FluidHelper;
|
||||
import com.builtbroken.minecraft.helpers.PlayerKeyHandler;
|
||||
import com.builtbroken.minecraft.prefab.BlockMulti;
|
||||
import com.builtbroken.minecraft.save.SaveManager;
|
||||
|
@ -28,12 +27,7 @@ public class DarkCore
|
|||
public static final String DOMAIN = "darkcore";
|
||||
public static final String PREFIX = DOMAIN + ":";
|
||||
|
||||
public static final String TEXTURE_DIRECTORY = "textures/";
|
||||
public static final String BLOCK_DIRECTORY = TEXTURE_DIRECTORY + "blocks/";
|
||||
public static final String ITEM_DIRECTORY = TEXTURE_DIRECTORY + "items/";
|
||||
public static final String MODEL_DIRECTORY = TEXTURE_DIRECTORY + "models/";
|
||||
public static final String GUI_DIRECTORY = TEXTURE_DIRECTORY + "gui/";
|
||||
public static final String CHANNEL = "DARKCORE";
|
||||
|
||||
|
||||
public static String DIRECTORY_NO_SLASH = "assets/" + DOMAIN + "/";
|
||||
public static String DIRECTORY = "/" + DIRECTORY_NO_SLASH;
|
||||
|
@ -73,13 +67,7 @@ public class DarkCore
|
|||
{
|
||||
if (!pre)
|
||||
{
|
||||
CoreRegistry.masterBlockConfig.load();
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
MinecraftForge.EVENT_BUS.register(new FluidHelper());
|
||||
MinecraftForge.EVENT_BUS.register(SaveManager.instance());
|
||||
TickRegistry.registerTickHandler(NetworkUpdateHandler.instance(), Side.SERVER);
|
||||
TickRegistry.registerScheduledTickHandler(new PlayerKeyHandler(), Side.CLIENT);
|
||||
MinecraftForge.EVENT_BUS.register(new LaserEntityDamageSource(null));
|
||||
CoreRegistry.masterBlockConfig.load();
|
||||
pre = true;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -44,7 +44,7 @@ public class FXBeam extends EntityFX
|
|||
/** beam diameter */
|
||||
private float beamD = 0.08f;
|
||||
|
||||
private String texture = DarkCore.TEXTURE_DIRECTORY + "";
|
||||
private String texture = "";
|
||||
|
||||
public FXBeam(World world, Vector3 start, Vector3 end, Color color, String texture, int age, boolean pulse)
|
||||
{
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.builtbroken.minecraft.fluid;
|
||||
package com.builtbroken.minecraft;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
|
@ -37,19 +37,4 @@ public class LaserEntityDamageSource extends EntityDamageSource
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public void LivingAttackEvent(LivingAttackEvent event)
|
||||
{
|
||||
if (event.entity instanceof EntityPlayer)
|
||||
{
|
||||
if (((EntityPlayer) event.entity).inventory.armorItemInSlot(3) == new ItemStack(Item.plateDiamond, 1))
|
||||
{
|
||||
if (event.isCancelable())
|
||||
{
|
||||
event.setCanceled(true);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,15 +1,8 @@
|
|||
package com.builtbroken.minecraft;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
import com.builtbroken.minecraft.network.PacketManagerEffects;
|
||||
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
public class RegistryProxy
|
||||
|
@ -26,9 +19,4 @@ public class RegistryProxy
|
|||
{
|
||||
GameRegistry.registerTileEntityWithAlternatives(clazz, name, "DM" + name);
|
||||
}
|
||||
|
||||
public void renderBeam(World world, Vector3 position, Vector3 target, Color color, int age)
|
||||
{
|
||||
PacketManagerEffects.sendClientLaserEffect(world, position, target, color, age);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,21 +0,0 @@
|
|||
package com.builtbroken.minecraft.fluid;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
/** Some common Fluid that other mods use
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public enum EnumFluid
|
||||
{
|
||||
FUEL(new Fluid("fuel").setUnlocalizedName("fluid.fuel.name")),
|
||||
OIL(new Fluid("oil").setUnlocalizedName("fluid.oil.name").setDensity(1500).setViscosity(4700)),
|
||||
BIOFUEL(new Fluid("biofuel").setUnlocalizedName("fluid.biofuel.name")),
|
||||
WASTE(new Fluid("waste").setUnlocalizedName("fluid.waste.name").setDensity(1300).setViscosity(1800));
|
||||
|
||||
public final Fluid fluid;
|
||||
|
||||
private EnumFluid(Fluid fluid)
|
||||
{
|
||||
this.fluid = fluid;
|
||||
}
|
||||
}
|
|
@ -1,76 +0,0 @@
|
|||
package com.builtbroken.minecraft.fluid;
|
||||
|
||||
import com.builtbroken.common.science.ChemElement;
|
||||
import com.builtbroken.common.science.ChemicalCompound;
|
||||
|
||||
/** Enum of gases used to create all the gas fluids
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public enum EnumGas
|
||||
{
|
||||
CARBONDIOXIDE("Carbon DiOxide", false),
|
||||
OXYGEN(ChemElement.Oxygen, 2f, true),
|
||||
BUTANE(ChemicalCompound.BUTANE, true),
|
||||
METHANE(ChemicalCompound.METHANE, true),
|
||||
NATURAL_GAS("Natural Gas", false),
|
||||
PROPANE("Propane", false);
|
||||
|
||||
/** Name used when creating this as a fluid */
|
||||
public final String fluidName;
|
||||
/** Name used to display to the players */
|
||||
public final String name;
|
||||
/** Object data reference that was used to create this gas, can be a ChemicalCompound, Element,
|
||||
* or Fluid */
|
||||
public final Object data;
|
||||
public boolean enabled = false;
|
||||
/** Only used for elements since when used as a gas they sometimes bind together */
|
||||
private float molePerGasMolecule = 1.0f;
|
||||
/** Local instance of the gas used when the getGas method is called */
|
||||
private Gas gas;
|
||||
|
||||
private EnumGas(String name, boolean enabled)
|
||||
{
|
||||
this.fluidName = name.replace(" ", "").toLowerCase();
|
||||
this.name = name;
|
||||
data = null;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
private EnumGas(ChemicalCompound compound, boolean enabled)
|
||||
{
|
||||
this.fluidName = "gas:" + compound.compoundName.replace(" ", "").toLowerCase();
|
||||
this.name = compound.compoundName;
|
||||
data = compound;
|
||||
this.enabled = enabled;
|
||||
}
|
||||
|
||||
private EnumGas(ChemElement element, float molesPerGasMolecule, boolean enabled)
|
||||
{
|
||||
this.fluidName = "gas:" + element.elementName.replace(" ", "").toLowerCase();
|
||||
this.name = element.elementName;
|
||||
data = element;
|
||||
this.enabled = enabled;
|
||||
this.molePerGasMolecule = molesPerGasMolecule;
|
||||
}
|
||||
|
||||
public Gas getGas()
|
||||
{
|
||||
if (gas == null)
|
||||
{
|
||||
gas = new Gas(fluidName);
|
||||
if (data instanceof ChemElement)
|
||||
{
|
||||
gas.setDensity((int) ((ChemElement) data).density * 1000);
|
||||
}
|
||||
else if (data instanceof ChemicalCompound)
|
||||
{
|
||||
gas.setDensity((int) ((ChemicalCompound) data).density * 1000);
|
||||
}
|
||||
else
|
||||
{
|
||||
gas.setDensity(-1000);
|
||||
}
|
||||
}
|
||||
return gas;
|
||||
}
|
||||
}
|
|
@ -1,58 +0,0 @@
|
|||
package com.builtbroken.minecraft.fluid;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
|
||||
/** Tank that has a filter on the fluid ids it will accept
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class FilteredTank extends FluidTank
|
||||
{
|
||||
private List<Integer> fluidIds = new ArrayList<Integer>();
|
||||
boolean gas = true;
|
||||
boolean liquid = true;
|
||||
|
||||
public FilteredTank(int capacity, int... fluidIds)
|
||||
{
|
||||
this(capacity, true, true, fluidIds);
|
||||
}
|
||||
|
||||
public FilteredTank(int capacity, boolean gas, boolean liquid, int... fluidIds)
|
||||
{
|
||||
super(capacity);
|
||||
this.gas = gas;
|
||||
this.liquid = liquid;
|
||||
for (int id : fluidIds)
|
||||
{
|
||||
this.fluidIds.add(id);
|
||||
}
|
||||
}
|
||||
|
||||
public FilteredTank(FluidStack stack, int capacity)
|
||||
{
|
||||
super(stack, capacity);
|
||||
}
|
||||
|
||||
public FilteredTank(Fluid fluid, int amount, int capacity)
|
||||
{
|
||||
super(fluid, amount, capacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill)
|
||||
{
|
||||
if (resource != null && resource.getFluid() != null && (!gas || gas && resource.getFluid().isGaseous()) && (!liquid || liquid && !resource.getFluid().isGaseous()))
|
||||
{
|
||||
if (fluidIds.contains(resource.fluidID))
|
||||
{
|
||||
return super.fill(resource, doFill);
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package com.builtbroken.minecraft.fluid;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
|
||||
/** These is an extension of the Fluid system forcing it to be a gas on creation
|
||||
*
|
||||
* @author Archadia, DarkGuardsman */
|
||||
public class Gas extends Fluid
|
||||
{
|
||||
|
||||
public Gas(String name)
|
||||
{
|
||||
super(name);
|
||||
this.isGaseous = true;
|
||||
this.density = -1000;
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package com.builtbroken.minecraft.fluid;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
|
||||
/** Version of the fluid tank that is restricted to gases only
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class GasTank extends FluidTank
|
||||
{
|
||||
|
||||
public GasTank(int capacity)
|
||||
{
|
||||
super(capacity);
|
||||
}
|
||||
|
||||
public GasTank(FluidStack stack, int capacity)
|
||||
{
|
||||
super(stack, capacity);
|
||||
}
|
||||
|
||||
public GasTank(Fluid fluid, int amount, int capacity)
|
||||
{
|
||||
super(fluid, amount, capacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill)
|
||||
{
|
||||
if (resource != null && resource.getFluid() != null && resource.getFluid().isGaseous())
|
||||
{
|
||||
return super.fill(resource, doFill);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package com.builtbroken.minecraft.fluid;
|
||||
|
||||
import net.minecraftforge.fluids.Fluid;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.FluidTank;
|
||||
|
||||
/** Version of the fluid tank that only supports liquids
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class LiquidTank extends FluidTank
|
||||
{
|
||||
|
||||
public LiquidTank(int capacity)
|
||||
{
|
||||
super(capacity);
|
||||
}
|
||||
|
||||
public LiquidTank(FluidStack stack, int capacity)
|
||||
{
|
||||
super(stack, capacity);
|
||||
}
|
||||
|
||||
public LiquidTank(Fluid fluid, int amount, int capacity)
|
||||
{
|
||||
super(fluid, amount, capacity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(FluidStack resource, boolean doFill)
|
||||
{
|
||||
if (resource != null && resource.getFluid() != null && !resource.getFluid().isGaseous())
|
||||
{
|
||||
return super.fill(resource, doFill);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
}
|
|
@ -8,8 +8,6 @@ import net.minecraft.client.settings.KeyBinding;
|
|||
import org.lwjgl.input.Keyboard;
|
||||
import org.lwjgl.input.Mouse;
|
||||
|
||||
import com.builtbroken.minecraft.network.PacketManagerKeyEvent;
|
||||
|
||||
import cpw.mods.fml.common.IScheduledTickHandler;
|
||||
import cpw.mods.fml.common.TickType;
|
||||
|
||||
|
@ -18,6 +16,12 @@ import cpw.mods.fml.common.TickType;
|
|||
* @author DarkGuardsman */
|
||||
public class PlayerKeyHandler implements IScheduledTickHandler
|
||||
{
|
||||
private String channel;
|
||||
|
||||
public PlayerKeyHandler(String channel)
|
||||
{
|
||||
this.channel = channel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final void tickStart(EnumSet<TickType> type, Object... tickData)
|
||||
|
@ -40,7 +44,7 @@ public class PlayerKeyHandler implements IScheduledTickHandler
|
|||
boolean state = (keyCode < 0 ? Mouse.isButtonDown(keyCode + 100) : Keyboard.isKeyDown(keyCode));
|
||||
if (state)
|
||||
{
|
||||
PacketManagerKeyEvent.sendPacket(keyCode);
|
||||
//PacketManagerKeyEvent.sendPacket(this.channel, keyCode);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,24 +0,0 @@
|
|||
package com.builtbroken.minecraft.interfaces;
|
||||
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
|
||||
/** Applied to objects that can be aimed by yaw and pitch. This is used by things like sentry guns,
|
||||
* vehicles, or mining tools.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IAimable
|
||||
{
|
||||
/** Vector which runs from the objects eyes(or gun). Should be right outside the objects bounds
|
||||
* but no farther than that. */
|
||||
public Vector3 getLook();
|
||||
|
||||
/** X pitch, Y is yaw, z is roll. Roll is almost never used */
|
||||
public Vector3 getRotation();
|
||||
|
||||
/** This does not set the rotation but rather moves the current rotation by the given values */
|
||||
public void updateRotation(float pitch, float yaw, float roll);
|
||||
|
||||
/** Forces the rotation to the angles */
|
||||
public void setRotation(float pitch, float yaw, float roll);
|
||||
}
|
|
@ -1,18 +0,0 @@
|
|||
package com.builtbroken.minecraft.interfaces;
|
||||
|
||||
/** This class should be applied to all tile entities (mainly machines) that can be disabled (by
|
||||
* things like EMP, short circuit etc.).
|
||||
*
|
||||
* @author Calclavia */
|
||||
public interface IDisableable
|
||||
{
|
||||
/** This is called when the tile entity is to be disabled.
|
||||
*
|
||||
* @param duration - The duration of the disable in ticks. */
|
||||
public void onDisable(int duration);
|
||||
|
||||
/** Called to see if this tile entity is disabled.
|
||||
*
|
||||
* @return True if the tile entity is disabled. */
|
||||
public boolean isDisabled();
|
||||
}
|
|
@ -4,13 +4,7 @@ import net.minecraft.inventory.ISidedInventory;
|
|||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
/** External inventory management container for an object. Allows for most if not all inventory code
|
||||
* to be removed from the tile. That is some methods will still need to remain in order to work with
|
||||
* automation. As well this is not designed to replace the need for IInventory support of a tile but
|
||||
* to make it easier to manage. Suggested use it to create a prefab manager for several tiles. Then
|
||||
* have those tiles use the prefab as an extermal inventory manager to reduce code size per class.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
/** @author DarkGuardsman */
|
||||
public interface IInvBox extends ISidedInventory
|
||||
{
|
||||
/** Gets the inventory array. ForgeDirection.UNKOWN must return all sides */
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.builtbroken.minecraft.save;
|
||||
package com.builtbroken.minecraft.network;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
|
@ -1,17 +0,0 @@
|
|||
package com.builtbroken.minecraft.network;
|
||||
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public interface IPacketManager
|
||||
{
|
||||
public int getID();
|
||||
|
||||
public void setID(int maxID);
|
||||
|
||||
public void handlePacket(INetworkManager network, Packet250CustomPayload packet, Player player, ByteArrayDataInput data);
|
||||
}
|
|
@ -1,11 +0,0 @@
|
|||
package com.builtbroken.minecraft.network;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public interface ISimpleItemPacketReceiver
|
||||
{
|
||||
public boolean simplePacket(EntityPlayer player, ItemStack stack, String id, ByteArrayDataInput data);
|
||||
}
|
|
@ -1,21 +0,0 @@
|
|||
package com.builtbroken.minecraft.network;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
/** Simplified version of IPackerReceiver for tiles that only need a packet ID, data, and player
|
||||
* Reference
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface ISimplePacketReceiver
|
||||
{
|
||||
/** Simplified version of IPacketReceiver's HandlePacketData
|
||||
*
|
||||
* @param id - packet ID as a string
|
||||
* @param data - data from the packet, after location has been read
|
||||
* @param player - player that the packet was sent to or came from
|
||||
* @return true if the packet was used */
|
||||
public boolean simplePacket(String id, ByteArrayDataInput data, Player player);
|
||||
|
||||
}
|
|
@ -1,79 +0,0 @@
|
|||
package com.builtbroken.minecraft.network;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.ChatMessageComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.ForgeSubscribe;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
||||
import net.minecraftforge.event.entity.player.PlayerInteractEvent.Action;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
import com.builtbroken.common.Pair;
|
||||
|
||||
public class PacketDataWatcher
|
||||
{
|
||||
HashMap<Pair<World, Vector3>, List<Integer>> packetSizes = new HashMap<Pair<World, Vector3>, List<Integer>>();
|
||||
|
||||
public static PacketDataWatcher instance = new PacketDataWatcher();
|
||||
|
||||
public boolean enable = false;
|
||||
|
||||
public void onPacketData(TileEntity entity, Packet250CustomPayload data, long t)
|
||||
{
|
||||
if (entity != null && enable)
|
||||
{
|
||||
Pair<World, Vector3> location = new Pair<World, Vector3>(entity.worldObj, new Vector3(entity));
|
||||
List<Integer> l = this.packetSizes.get(location);
|
||||
if (l == null)
|
||||
{
|
||||
l = new ArrayList<Integer>();
|
||||
}
|
||||
l.add(data.getPacketSize());
|
||||
this.packetSizes.put(location, l);
|
||||
}
|
||||
}
|
||||
|
||||
@ForgeSubscribe
|
||||
public void playerRightClickEvent(PlayerInteractEvent event)
|
||||
{
|
||||
if (event.action == Action.RIGHT_CLICK_BLOCK && event.entityPlayer.capabilities.isCreativeMode && event.entityPlayer.getHeldItem() != null && event.entityPlayer.getHeldItem().itemID == Item.blazeRod.itemID)
|
||||
{
|
||||
if (event.entityPlayer.worldObj.isRemote)
|
||||
{
|
||||
if (event.entityPlayer.isSneaking())
|
||||
{
|
||||
this.enable = !this.enable;
|
||||
event.entityPlayer.sendChatToPlayer(ChatMessageComponent.createFromText("PacketWatcher is now " + (this.enable ? "Enabled. Now caching packet sizes." : "Disabled. Data cache has been cleared")));
|
||||
this.packetSizes.clear();
|
||||
}
|
||||
else
|
||||
{
|
||||
TileEntity ent = event.entityPlayer.worldObj.getBlockTileEntity(event.x, event.y, event.z);
|
||||
if (ent != null)
|
||||
{
|
||||
System.out.println("Entity Check");
|
||||
Pair<World, Vector3> location = new Pair(ent.worldObj, new Vector3(ent));
|
||||
int p = 0, a = 0;
|
||||
if (this.packetSizes.get(location) != null)
|
||||
{
|
||||
for (int i : this.packetSizes.get(location))
|
||||
{
|
||||
a += i;
|
||||
}
|
||||
p = this.packetSizes.get(location).size();
|
||||
a /= (p > 0 ? p : 1);
|
||||
}
|
||||
event.entityPlayer.sendChatToPlayer(ChatMessageComponent.createFromText("AveragePacketSize: " + a + "bits for " + p + " packets"));
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,379 +0,0 @@
|
|||
package com.builtbroken.minecraft.network;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataInputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.nbt.CompressedStreamTools;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
import com.builtbroken.minecraft.save.IPacketLoad;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
import com.google.common.io.ByteArrayDataOutput;
|
||||
import com.google.common.io.ByteStreams;
|
||||
|
||||
import cpw.mods.fml.common.network.IPacketHandler;
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
/** Packet manager based off the PacketManager from UE created by Calclavia. However changed so it
|
||||
* can easily be extended without changing the base handler file. Instead of changing the base file
|
||||
* manager can be registered to the handle that pickup on ids and then handle there own data from
|
||||
* those ids. This lets new and complex handling to be created without many overlap or long methods
|
||||
* in the packet handler
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class PacketHandler implements IPacketHandler
|
||||
{
|
||||
protected static PacketHandler instance;
|
||||
|
||||
public static HashMap<Integer, IPacketManager> packetTypes = new HashMap<Integer, IPacketManager>();
|
||||
|
||||
public static PacketManagerTile tile = new PacketManagerTile();
|
||||
|
||||
public static int maxID = 0;
|
||||
static
|
||||
{
|
||||
registerManager(new PacketManagerTile());
|
||||
registerManager(PacketManagerKeyEvent.instance());
|
||||
registerManager(new PacketManagerEntity());
|
||||
registerManager(new PacketManagerItem());
|
||||
}
|
||||
|
||||
public static void registerManager(IPacketManager manager)
|
||||
{
|
||||
if (manager != null)
|
||||
{
|
||||
packetTypes.put(maxID, manager);
|
||||
manager.setID(maxID);
|
||||
maxID++;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
public static IPacketManager getManager(int id)
|
||||
{
|
||||
return packetTypes.get(id);
|
||||
}
|
||||
|
||||
public static PacketHandler instance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new PacketHandler();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
/** Writes a compressed NBTTagCompound to the OutputStream */
|
||||
public void writeNBTTagCompound(NBTTagCompound tag, DataOutputStream dataStream) throws IOException
|
||||
{
|
||||
if (tag == null)
|
||||
{
|
||||
dataStream.writeShort(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] var2 = CompressedStreamTools.compress(tag);
|
||||
dataStream.writeShort((short) var2.length);
|
||||
dataStream.write(var2);
|
||||
}
|
||||
}
|
||||
|
||||
public void writeNBTTagCompound(NBTTagCompound tag, ByteArrayDataOutput dataStream) throws IOException
|
||||
{
|
||||
if (tag == null)
|
||||
{
|
||||
dataStream.writeShort(-1);
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] var2 = CompressedStreamTools.compress(tag);
|
||||
dataStream.writeShort((short) var2.length);
|
||||
dataStream.write(var2);
|
||||
}
|
||||
}
|
||||
|
||||
/** Reads a compressed NBTTagCompount in a ByteStream. */
|
||||
public NBTTagCompound readNBTTagCompound(DataInputStream dataStream) throws IOException
|
||||
{
|
||||
short var1 = dataStream.readShort();
|
||||
|
||||
if (var1 < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] var2 = new byte[var1];
|
||||
dataStream.readFully(var2);
|
||||
return CompressedStreamTools.decompress(var2);
|
||||
}
|
||||
}
|
||||
|
||||
public NBTTagCompound readNBTTagCompound(ByteArrayDataInput dataStream) throws IOException
|
||||
{
|
||||
short var1 = dataStream.readShort();
|
||||
|
||||
if (var1 < 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
byte[] var2 = new byte[var1];
|
||||
dataStream.readFully(var2);
|
||||
return CompressedStreamTools.decompress(var2);
|
||||
}
|
||||
}
|
||||
|
||||
public static Vector3 readVector3(ByteArrayDataInput data) throws IOException
|
||||
{
|
||||
return new Vector3(data.readDouble(), data.readDouble(), data.readDouble());
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public Packet getPacketWithID(String channelName, int id, Object... sendData)
|
||||
{
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream(bytes);
|
||||
|
||||
try
|
||||
{
|
||||
data.writeInt(id);
|
||||
data = encodeDataStream(data, sendData);
|
||||
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
packet.channel = channelName;
|
||||
packet.data = bytes.toByteArray();
|
||||
packet.length = packet.data.length;
|
||||
|
||||
return packet;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.out.println("Failed to create packet.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
public Packet getPacket(String channelName, Object... sendData)
|
||||
{
|
||||
return getPacketWithID(channelName, -1, sendData);
|
||||
}
|
||||
|
||||
/** Generates a packet for a tile entity using a loader instance. This is mainly used to pass
|
||||
* data from an object inside a tile entity and have it go write back to that object on the
|
||||
* other side of the network. Your tile entity will still need to grab the data in the same way
|
||||
* as getTilePacket. Then just pass it back to the object that wrote the data.
|
||||
*
|
||||
* @param channelName - channel to send the packet threw
|
||||
* @param packetID - id to be used with the tile entity receive method
|
||||
* @param sender - tile entity that send the packet, and will get the packet
|
||||
* @param load - object that will be loading the data
|
||||
* @return new Packet250CustomPayLoad */
|
||||
public Packet getPacketFromLoader(String channelName, String packetID, TileEntity sender, IPacketLoad load)
|
||||
{
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream(bytes);
|
||||
|
||||
try
|
||||
{
|
||||
data.writeInt(PacketHandler.tile.getID());
|
||||
|
||||
data.writeInt(sender.xCoord);
|
||||
data.writeInt(sender.yCoord);
|
||||
data.writeInt(sender.zCoord);
|
||||
data.writeUTF(packetID);
|
||||
load.loadPacket(data);
|
||||
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
packet.channel = channelName;
|
||||
packet.data = bytes.toByteArray();
|
||||
packet.length = packet.data.length;
|
||||
|
||||
return packet;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.out.println("Failed to create packet.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Generates a packet for a tile entity using the data given
|
||||
*
|
||||
* @param channelName - channel to send the packet threw
|
||||
* @param packetID - id to be used with the tile entity receive method
|
||||
* @param sender - tile entity that send the packet, and will get the packet
|
||||
* @param sendData - data to be sent
|
||||
* @return new Packet250CustomPayLoad */
|
||||
@SuppressWarnings("resource")
|
||||
public Packet getTilePacket(String channelName, String packetID, TileEntity sender, Object... sendData)
|
||||
{
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream(bytes);
|
||||
|
||||
try
|
||||
{
|
||||
data.writeInt(PacketHandler.tile.getID());
|
||||
|
||||
data.writeInt(sender.xCoord);
|
||||
data.writeInt(sender.yCoord);
|
||||
data.writeInt(sender.zCoord);
|
||||
data.writeUTF(packetID);
|
||||
data = encodeDataStream(data, sendData);
|
||||
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
packet.channel = channelName;
|
||||
packet.data = bytes.toByteArray();
|
||||
packet.length = packet.data.length;
|
||||
|
||||
return packet;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.out.println("Failed to create packet.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/** Sends packets to clients around a specific coordinate. A wrapper using Vector3. See
|
||||
* {@PacketDispatcher} for detailed information. */
|
||||
public void sendPacketToClients(Packet packet, World worldObj, Vector3 position, double range)
|
||||
{
|
||||
try
|
||||
{
|
||||
PacketDispatcher.sendPacketToAllAround(position.x, position.y, position.z, range, worldObj.provider.dimensionId, packet);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Sending packet to client failed.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
/** Sends a packet to all the clients on this server. */
|
||||
public void sendPacketToClients(Packet packet, World worldObj)
|
||||
{
|
||||
try
|
||||
{
|
||||
PacketDispatcher.sendPacketToAllInDimension(packet, worldObj.provider.dimensionId);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Sending packet to client failed.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public void sendPacketToClients(Packet packet)
|
||||
{
|
||||
try
|
||||
{
|
||||
PacketDispatcher.sendPacketToAllPlayers(packet);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Sending packet to client failed.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public DataOutputStream encodeDataStream(DataOutputStream data, Object... sendData)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (Object dataValue : sendData)
|
||||
{
|
||||
if (dataValue instanceof Vector3)
|
||||
{
|
||||
data.writeDouble(((Vector3) dataValue).x);
|
||||
data.writeDouble(((Vector3) dataValue).y);
|
||||
data.writeDouble(((Vector3) dataValue).z);
|
||||
}
|
||||
else if (dataValue instanceof Integer)
|
||||
{
|
||||
data.writeInt((Integer) dataValue);
|
||||
}
|
||||
else if (dataValue instanceof Float)
|
||||
{
|
||||
data.writeFloat((Float) dataValue);
|
||||
}
|
||||
else if (dataValue instanceof Double)
|
||||
{
|
||||
data.writeDouble((Double) dataValue);
|
||||
}
|
||||
else if (dataValue instanceof Byte)
|
||||
{
|
||||
data.writeByte((Byte) dataValue);
|
||||
}
|
||||
else if (dataValue instanceof Boolean)
|
||||
{
|
||||
data.writeBoolean((Boolean) dataValue);
|
||||
}
|
||||
else if (dataValue instanceof String)
|
||||
{
|
||||
data.writeUTF((String) dataValue);
|
||||
}
|
||||
else if (dataValue instanceof Short)
|
||||
{
|
||||
data.writeShort((Short) dataValue);
|
||||
}
|
||||
else if (dataValue instanceof Long)
|
||||
{
|
||||
data.writeLong((Long) dataValue);
|
||||
}
|
||||
else if (dataValue instanceof NBTTagCompound)
|
||||
{
|
||||
writeNBTTagCompound((NBTTagCompound) dataValue, data);
|
||||
}
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.out.println("Packet data encoding failed.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
return data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPacketData(INetworkManager network, Packet250CustomPayload packet, Player player)
|
||||
{
|
||||
try
|
||||
{
|
||||
ByteArrayDataInput data = ByteStreams.newDataInput(packet.data);
|
||||
|
||||
int packetTypeID = data.readInt();
|
||||
|
||||
IPacketManager packetType = getManager(packetTypeID);
|
||||
|
||||
if (packetType != null)
|
||||
{
|
||||
packetType.handlePacket(network, packet, player, data);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,65 +0,0 @@
|
|||
package com.builtbroken.minecraft.network;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
import com.builtbroken.minecraft.CoreRegistry;
|
||||
import com.builtbroken.minecraft.DarkCore;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class PacketManagerEffects implements IPacketManager
|
||||
{
|
||||
static int packetID = 0;
|
||||
|
||||
@Override
|
||||
public int getID()
|
||||
{
|
||||
return packetID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setID(int maxID)
|
||||
{
|
||||
packetID = maxID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacket(INetworkManager network, Packet250CustomPayload packet, Player player, ByteArrayDataInput data)
|
||||
{
|
||||
try
|
||||
{
|
||||
World world = ((EntityPlayer) player).worldObj;
|
||||
String effectName = data.readUTF();
|
||||
if (world != null)
|
||||
{
|
||||
if (effectName.equalsIgnoreCase("laser"))
|
||||
{
|
||||
System.out.println("Received laser packet");
|
||||
CoreRegistry.proxy().renderBeam(world, PacketHandler.readVector3(data), PacketHandler.readVector3(data), new Color(data.readInt(), data.readInt(), data.readInt()), data.readInt());
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("[CoreMachine] Error reading packet for effect rendering");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void sendClientLaserEffect(World world, Vector3 position, Vector3 target, Color color, int age)
|
||||
{
|
||||
Packet packet = PacketHandler.instance().getPacketWithID(DarkCore.CHANNEL, packetID, "laser", position, target, color.getRed(), color.getBlue(), color.getGreen(), age);
|
||||
PacketHandler.instance().sendPacketToClients(packet, world, position, position.distance(target));
|
||||
System.out.println("Sent laser render packet to client");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,78 +0,0 @@
|
|||
package com.builtbroken.minecraft.network;
|
||||
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.world.World;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
|
||||
import com.builtbroken.minecraft.DarkCore;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class PacketManagerEntity implements IPacketManager
|
||||
{
|
||||
static int packetID = 0;
|
||||
|
||||
@Override
|
||||
public int getID()
|
||||
{
|
||||
return packetID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setID(int maxID)
|
||||
{
|
||||
packetID = maxID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacket(INetworkManager network, Packet250CustomPayload packet, Player player, ByteArrayDataInput data)
|
||||
{
|
||||
try
|
||||
{
|
||||
int entityId = data.readInt();
|
||||
|
||||
World world = ((EntityPlayer) player).worldObj;
|
||||
if (world != null)
|
||||
{
|
||||
Entity entity = world.getEntityByID(entityId);
|
||||
if (entity instanceof ISimplePacketReceiver)
|
||||
{
|
||||
String id = data.readUTF();
|
||||
((ISimplePacketReceiver) entity).simplePacket(id, data, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("[CoreMachine] Error reading packet for an entity");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void sendEntityUpdatePacket(Entity entity, boolean toServer, String id, Object... objects)
|
||||
{
|
||||
Object[] obj = new Object[2 + objects.length];
|
||||
obj[0] = entity.entityId;
|
||||
obj[1] = id;
|
||||
for (int i = 0; i < objects.length; i++)
|
||||
{
|
||||
obj[2 + i] = objects[i];
|
||||
}
|
||||
Packet packet = PacketHandler.instance().getPacketWithID(DarkCore.CHANNEL, packetID, obj);
|
||||
if (toServer)
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer(packet);
|
||||
}
|
||||
else
|
||||
{
|
||||
PacketHandler.instance().sendPacketToClients(packet, entity.worldObj, new Vector3(entity), 64);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,96 +0,0 @@
|
|||
package com.builtbroken.minecraft.network;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
/** Helps update the server or client with general information about an item. Should mostly be used
|
||||
* for GUIs or render effects.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class PacketManagerItem implements IPacketManager
|
||||
{
|
||||
static int packetID = 0;
|
||||
|
||||
@Override
|
||||
public int getID()
|
||||
{
|
||||
return packetID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setID(int maxID)
|
||||
{
|
||||
packetID = maxID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacket(INetworkManager network, Packet250CustomPayload packet, Player player, ByteArrayDataInput data)
|
||||
{
|
||||
try
|
||||
{
|
||||
EntityPlayer entityPlayer = (EntityPlayer) player;
|
||||
String id = data.readUTF();
|
||||
int slot = data.readInt();
|
||||
ItemStack stack = null;
|
||||
if (slot >= 0)
|
||||
{
|
||||
stack = entityPlayer.inventory.getStackInSlot(slot);
|
||||
}
|
||||
else if (slot == -1)
|
||||
{
|
||||
stack = entityPlayer.inventory.getCurrentItem();
|
||||
}
|
||||
if (stack != null & stack.getItem() != null)
|
||||
{
|
||||
if (stack.getItem() instanceof ISimpleItemPacketReceiver)
|
||||
{
|
||||
((ISimpleItemPacketReceiver) stack.getItem()).simplePacket(entityPlayer, stack, id, data);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("[CoreLibrary] Error reading packet for item data");
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings("resource")
|
||||
public static Packet getPacket(EntityPlayer player, String channelName, String id, int slot, Object... dataToSend)
|
||||
{
|
||||
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
|
||||
DataOutputStream data = new DataOutputStream(bytes);
|
||||
|
||||
try
|
||||
{
|
||||
data.writeInt(packetID);
|
||||
data.writeUTF(id);
|
||||
data.writeInt(slot);
|
||||
data = PacketHandler.instance.encodeDataStream(data, dataToSend);
|
||||
|
||||
Packet250CustomPayload packet = new Packet250CustomPayload();
|
||||
packet.channel = channelName;
|
||||
packet.data = bytes.toByteArray();
|
||||
packet.length = packet.data.length;
|
||||
|
||||
return packet;
|
||||
}
|
||||
catch (IOException e)
|
||||
{
|
||||
System.out.println("Failed to create packet.");
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
}
|
|
@ -1,84 +0,0 @@
|
|||
package com.builtbroken.minecraft.network;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
|
||||
import com.builtbroken.minecraft.DarkCore;
|
||||
import com.builtbroken.minecraft.interfaces.IControlReceiver;
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class PacketManagerKeyEvent implements IPacketManager
|
||||
{
|
||||
static int packetID = 0;
|
||||
|
||||
private static PacketManagerKeyEvent instance;
|
||||
|
||||
private List<IControlReceiver> receivers = new ArrayList<IControlReceiver>();
|
||||
|
||||
public static PacketManagerKeyEvent instance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new PacketManagerKeyEvent();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public void register(IControlReceiver rec)
|
||||
{
|
||||
if (!this.receivers.contains(rec))
|
||||
{
|
||||
this.receivers.add(rec);
|
||||
}
|
||||
}
|
||||
|
||||
public void remove(IControlReceiver rec)
|
||||
{
|
||||
this.receivers.remove(rec);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getID()
|
||||
{
|
||||
return packetID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setID(int maxID)
|
||||
{
|
||||
packetID = maxID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacket(INetworkManager network, Packet250CustomPayload packet, Player player, ByteArrayDataInput data)
|
||||
{
|
||||
try
|
||||
{
|
||||
int key = data.readInt();
|
||||
for (IControlReceiver receiver : instance().receivers)
|
||||
{
|
||||
if (receiver.keyTyped((EntityPlayer) player, key))
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static void sendPacket(int key)
|
||||
{
|
||||
PacketDispatcher.sendPacketToServer(PacketHandler.instance().getPacketWithID(DarkCore.CHANNEL, PacketManagerKeyEvent.packetID, key));
|
||||
}
|
||||
}
|
|
@ -1,62 +0,0 @@
|
|||
package com.builtbroken.minecraft.network;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.network.INetworkManager;
|
||||
import net.minecraft.network.packet.Packet250CustomPayload;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public class PacketManagerTile implements IPacketManager
|
||||
{
|
||||
static int packetID = 0;
|
||||
|
||||
@Override
|
||||
public int getID()
|
||||
{
|
||||
return packetID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setID(int maxID)
|
||||
{
|
||||
packetID = maxID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handlePacket(INetworkManager network, Packet250CustomPayload packet, Player player, ByteArrayDataInput data)
|
||||
{
|
||||
try
|
||||
{
|
||||
int x = data.readInt();
|
||||
int y = data.readInt();
|
||||
int z = data.readInt();
|
||||
|
||||
World world = ((EntityPlayer) player).worldObj;
|
||||
|
||||
if (world != null)
|
||||
{
|
||||
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
|
||||
|
||||
if (tileEntity != null)
|
||||
{
|
||||
PacketDataWatcher.instance.onPacketData(tileEntity, packet, System.currentTimeMillis());
|
||||
if (tileEntity instanceof ISimplePacketReceiver)
|
||||
{
|
||||
String pId = data.readUTF();
|
||||
((ISimplePacketReceiver) tileEntity).simplePacket(pId, data, player);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("[CoreMachine] Error reading packet at tile packet manager");
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
|
@ -1,75 +0,0 @@
|
|||
package com.builtbroken.minecraft.prefab;
|
||||
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
||||
import com.builtbroken.minecraft.save.ISaveObj;
|
||||
import com.builtbroken.minecraft.save.NBTFileHelper;
|
||||
|
||||
/** Wrapper for data to be sent threw a network to a device
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class DataPack implements ISaveObj, Cloneable
|
||||
{
|
||||
private Object[] data;
|
||||
|
||||
public DataPack(Object... data)
|
||||
{
|
||||
this.data = data;
|
||||
}
|
||||
|
||||
public Object[] getData()
|
||||
{
|
||||
return this.data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void save(NBTTagCompound nbt)
|
||||
{
|
||||
if (data != null)
|
||||
{
|
||||
nbt.setInteger("dataCnt", data.length);
|
||||
for (int i = 0; i < data.length; i++)
|
||||
{
|
||||
if (data[i] != null)
|
||||
{
|
||||
NBTFileHelper.saveObject(nbt, "data" + i, data[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void load(NBTTagCompound nbt)
|
||||
{
|
||||
if (nbt.hasKey("dataCnt"))
|
||||
{
|
||||
int dataLength = nbt.getInteger("dataCnt");
|
||||
data = new Object[dataLength];
|
||||
for (int i = 0; i < dataLength; i++)
|
||||
{
|
||||
if (nbt.hasKey("data" + i))
|
||||
{
|
||||
data[i] = NBTFileHelper.loadObject(nbt, "data" + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public DataPack clone()
|
||||
{
|
||||
return new DataPack(this.data);
|
||||
}
|
||||
|
||||
public boolean isEqual(DataPack pack)
|
||||
{
|
||||
return this.data != null && pack.data != null && this.data.equals(pack.data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return "DataPack [Obj:" + (this.data != null ? data.length : "none") + "]";
|
||||
}
|
||||
}
|
|
@ -202,7 +202,6 @@ public abstract class TileEntityEnergyMachine extends TileEntityMachine implemen
|
|||
if (voltage > this.shortOutVoltage)
|
||||
{
|
||||
//TODO damage machine
|
||||
this.onDisable(this.worldObj.rand.nextInt(100));
|
||||
}
|
||||
}
|
||||
else
|
||||
|
|
|
@ -13,7 +13,6 @@ import universalelectricity.api.vector.Vector3;
|
|||
|
||||
import com.builtbroken.minecraft.DarkCore;
|
||||
import com.builtbroken.minecraft.IExtraInfo.IExtraTileEntityInfo;
|
||||
import com.builtbroken.minecraft.interfaces.IDisableable;
|
||||
import com.builtbroken.minecraft.interfaces.IExternalInv;
|
||||
import com.builtbroken.minecraft.interfaces.IInvBox;
|
||||
import com.builtbroken.minecraft.network.ISimplePacketReceiver;
|
||||
|
@ -23,7 +22,7 @@ import com.google.common.io.ByteArrayDataInput;
|
|||
import cpw.mods.fml.common.network.PacketDispatcher;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
|
||||
public abstract class TileEntityMachine extends TileEntityInv implements ISidedInventory, IExternalInv, IDisableable, ISimplePacketReceiver, IExtraTileEntityInfo
|
||||
public abstract class TileEntityMachine extends TileEntityInv implements ISidedInventory, IExternalInv, ISimplePacketReceiver, IExtraTileEntityInfo
|
||||
{
|
||||
/** Tick by which this machine stops working */
|
||||
protected int disabledTicks = 0;
|
||||
|
@ -96,7 +95,7 @@ public abstract class TileEntityMachine extends TileEntityInv implements ISidedI
|
|||
/** Can this tile function, or run threw normal processes */
|
||||
public boolean canFunction()
|
||||
{
|
||||
return !this.isDisabled() && this.enabled;
|
||||
return this.enabled;
|
||||
}
|
||||
|
||||
public boolean isFunctioning()
|
||||
|
@ -115,7 +114,6 @@ public abstract class TileEntityMachine extends TileEntityInv implements ISidedI
|
|||
{
|
||||
System.out.println("\n CanRun: " + this.canFunction());
|
||||
System.out.println(" RedPower: " + this.worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord));
|
||||
System.out.println(" IsDisabled: " + this.isDisabled());//TODO i'm going to kick myself if this is it, yep disabled
|
||||
System.out.println(" IsRunning: " + this.functioning);
|
||||
}
|
||||
|
||||
|
@ -254,27 +252,6 @@ public abstract class TileEntityMachine extends TileEntityInv implements ISidedI
|
|||
return PacketHandler.instance().getTilePacket(this.getChannel(), SimplePacketTypes.RUNNING.name, this, this.functioning);
|
||||
}
|
||||
|
||||
/** NetworkMod channel name */
|
||||
public String getChannel()
|
||||
{
|
||||
return DarkCore.CHANNEL;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDisable(int duration)
|
||||
{
|
||||
if (this.canBeDisabled)
|
||||
{
|
||||
this.disabledTicks = duration;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isDisabled()
|
||||
{
|
||||
return !this.canBeDisabled && this.disabledTicks > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean hasExtraConfigs()
|
||||
{
|
||||
|
|
|
@ -1,80 +0,0 @@
|
|||
package com.builtbroken.minecraft.prefab.invgui;
|
||||
|
||||
import java.awt.Color;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import universalelectricity.api.vector.Vector2;
|
||||
|
||||
import com.builtbroken.minecraft.DarkCore;
|
||||
|
||||
/** When done should be a prefab that can be used to render a power bar on the screen
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class GuiBar extends Gui
|
||||
{
|
||||
public static final ResourceLocation TEXTURE = new ResourceLocation(DarkCore.DOMAIN, DarkCore.GUI_DIRECTORY + "bar.png");
|
||||
|
||||
protected float currentLevel = 0;
|
||||
protected float maxLevel = 10;
|
||||
protected float scale = 1.0f;
|
||||
|
||||
protected Vector2 position;
|
||||
protected Color color = Color.red;
|
||||
|
||||
protected boolean horizontal = true;
|
||||
|
||||
private final int desiredH = 240;
|
||||
private final int desiredW = 427;
|
||||
|
||||
public GuiBar(int xx, int yy, float scale, boolean horizontal)
|
||||
{
|
||||
this.position = new Vector2(xx, yy);
|
||||
this.scale = scale;
|
||||
this.horizontal = horizontal;
|
||||
}
|
||||
|
||||
public GuiBar setColor(Color color)
|
||||
{
|
||||
this.color = color;
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Sets the parms for the bar that determ the length of the bar
|
||||
*
|
||||
* @param current - current level of the reading
|
||||
* @param max - max level of the reading; */
|
||||
public GuiBar setMeter(float current, float max)
|
||||
{
|
||||
this.currentLevel = current;
|
||||
this.maxLevel = max;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void draw(Minecraft minecraft)
|
||||
{
|
||||
GL11.glPushMatrix();
|
||||
if (scale != 1.0f)
|
||||
{
|
||||
//With everything scaled the gui will not align like a normal one so use a scaled distance from the main GUI
|
||||
ScaledResolution scaledresolution = new ScaledResolution(minecraft.gameSettings, minecraft.displayWidth, minecraft.displayHeight);
|
||||
int scaleH = scaledresolution.getScaledHeight();
|
||||
int scaleW = scaledresolution.getScaledWidth();
|
||||
//this.drawCenteredString(minecraft.fontRenderer, "Scale - " + scaleW + "x " + scaleH + "y", 100, 100, color);
|
||||
|
||||
float sh = (scaleH / desiredH) / scale;
|
||||
float sW = (scaleW / desiredW) / scale;
|
||||
//Start drawing after everying is scaled down
|
||||
GL11.glScalef(scale, scale, scale);
|
||||
|
||||
this.drawCenteredString(minecraft.fontRenderer, "Scale - " + scaleW + "x " + scaleH + "y", 100, 100, Color.blue.getRGB());
|
||||
}
|
||||
Gui.drawRect(this.position.intX(), this.position.intY(), this.position.intX() + (horizontal ? 10 : 3), this.position.intY() + (!horizontal ? 10 : 3), Color.black.getRGB());
|
||||
|
||||
}
|
||||
}
|
|
@ -1,190 +0,0 @@
|
|||
package com.builtbroken.minecraft.prefab.invgui;
|
||||
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import com.builtbroken.minecraft.DarkCore;
|
||||
import com.builtbroken.minecraft.prefab.TileEntityMachine;
|
||||
import com.builtbroken.minecraft.prefab.invgui.GuiButtonImage.ButtonIcon;
|
||||
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
|
||||
/** To be used with all machine that have a gui to allow generic settings and feature all all devices
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class GuiMachineBase extends GuiBase
|
||||
{
|
||||
|
||||
public ResourceLocation TEXTURE = new ResourceLocation(DarkCore.DOMAIN, DarkCore.GUI_DIRECTORY + "gui_grey.png");
|
||||
|
||||
protected static final int MAX_BUTTON_ID = 3;
|
||||
protected TileEntityMachine tileEntity;
|
||||
protected EntityPlayer entityPlayer;
|
||||
protected Object mod;
|
||||
protected int guiID = -1, guiID2 = -1, guiID3 = -1;
|
||||
protected ButtonIcon guiIcon = ButtonIcon.CHEST, guiIcon2 = ButtonIcon.PERSON, guiIcon3 = ButtonIcon.BLANK;
|
||||
protected String invName = "Home", invName2 = "2", invName3 = "3";
|
||||
|
||||
public GuiMachineBase(Object mod, EntityPlayer player, TileEntityMachine tileEntity)
|
||||
{
|
||||
this.tileEntity = tileEntity;
|
||||
this.entityPlayer = player;
|
||||
this.guiSize.y = 380 / 2;
|
||||
this.mod = mod;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Override
|
||||
public void initGui()
|
||||
{
|
||||
super.initGui();
|
||||
this.buttonList.clear();
|
||||
|
||||
// Inventory, Should be the Gui the machine opens to unless it has no inventory
|
||||
if (guiID != -1)
|
||||
this.buttonList.add(new GuiButtonImage(0, (this.width - this.guiSize.intX()) / 2 - 22, (this.height - this.guiSize.intY()) / 2 + 0, guiIcon));
|
||||
|
||||
// Machine settings
|
||||
if (guiID2 != -1)
|
||||
this.buttonList.add(new GuiButtonImage(1, (this.width - this.guiSize.intX()) / 2 - 22, (this.height - this.guiSize.intY()) / 2 + 22, guiIcon2));
|
||||
|
||||
if (guiID3 != -1)
|
||||
this.buttonList.add(new GuiButtonImage(2, (this.width - this.guiSize.intX()) / 2 - 22, (this.height - this.guiSize.intY()) / 2 + 44, guiIcon3));
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(GuiButton button)
|
||||
{
|
||||
switch (button.id)
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
if (guiID != -1)
|
||||
entityPlayer.openGui(mod, guiID, tileEntity.worldObj, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
break;
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
if (guiID2 != -1)
|
||||
entityPlayer.openGui(mod, guiID2, tileEntity.worldObj, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
if (guiID3 != -1)
|
||||
entityPlayer.openGui(mod, guiID3, tileEntity.worldObj, tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Draw the foreground layer for the GuiContainer (everything in front of the items) */
|
||||
@Override
|
||||
protected void drawForegroundLayer(int x, int y, float var1)
|
||||
{
|
||||
this.fontRenderer.drawString("\u00a77" + tileEntity.getInvName(), (int) (this.guiSize.intX() / 2 - 7 * 2.5), 4, 4210752);
|
||||
/** Render Tool Tips */
|
||||
if (((GuiButtonImage) this.buttonList.get(0)).isIntersect(x, y) && guiID != -1)
|
||||
{
|
||||
this.drawTooltip(x - this.c.intX(), y - this.c.intY() + 10, invName);
|
||||
}
|
||||
else if (((GuiButtonImage) this.buttonList.get(1)).isIntersect(x, y) && guiID2 != -1)
|
||||
{
|
||||
this.drawTooltip(x - this.c.intX(), y - this.c.intY() + 10, invName2);
|
||||
}
|
||||
else if (((GuiButtonImage) this.buttonList.get(2)).isIntersect(x, y) && guiID3 != -1)
|
||||
{
|
||||
this.drawTooltip(x - this.c.intX(), y - this.c.intY() + 10, invName3);
|
||||
}
|
||||
}
|
||||
|
||||
/** Draw the background layer for the GuiContainer (everything behind the items) */
|
||||
@Override
|
||||
protected void drawBackgroundLayer(int x, int y, float var1)
|
||||
{
|
||||
FMLClientHandler.instance().getClient().renderEngine.bindTexture(TEXTURE);
|
||||
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
|
||||
int containerWidth = (this.width - this.guiSize.intX()) / 2;
|
||||
int containerHeight = (this.height - this.guiSize.intY()) / 2;
|
||||
this.drawTexturedModalRect(containerWidth, containerHeight, 0, 0, this.guiSize.intX(), this.guiSize.intY());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawTooltip(int x, int y, String... toolTips)
|
||||
{
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL11.GL_LIGHTING);
|
||||
GL11.glDisable(GL11.GL_DEPTH_TEST);
|
||||
|
||||
if (toolTips != null)
|
||||
{
|
||||
int var5 = 0;
|
||||
int var6;
|
||||
int var7;
|
||||
|
||||
for (var6 = 0; var6 < toolTips.length; ++var6)
|
||||
{
|
||||
var7 = this.fontRenderer.getStringWidth(toolTips[var6]);
|
||||
|
||||
if (var7 > var5)
|
||||
{
|
||||
var5 = var7;
|
||||
}
|
||||
}
|
||||
|
||||
var6 = x + 12;
|
||||
var7 = y - 12;
|
||||
int var9 = 8;
|
||||
|
||||
if (toolTips.length > 1)
|
||||
{
|
||||
var9 += 2 + (toolTips.length - 1) * 10;
|
||||
}
|
||||
|
||||
if (this.c.intY() + var7 + var9 + 6 > this.height)
|
||||
{
|
||||
var7 = this.height - var9 - this.c.intY() - 6;
|
||||
}
|
||||
|
||||
this.zLevel = 300.0F;
|
||||
int var10 = -267386864;
|
||||
this.drawGradientRect(var6 - 3, var7 - 4, var6 + var5 + 3, var7 - 3, var10, var10);
|
||||
this.drawGradientRect(var6 - 3, var7 + var9 + 3, var6 + var5 + 3, var7 + var9 + 4, var10, var10);
|
||||
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 + var9 + 3, var10, var10);
|
||||
this.drawGradientRect(var6 - 4, var7 - 3, var6 - 3, var7 + var9 + 3, var10, var10);
|
||||
this.drawGradientRect(var6 + var5 + 3, var7 - 3, var6 + var5 + 4, var7 + var9 + 3, var10, var10);
|
||||
int var11 = 1347420415;
|
||||
int var12 = (var11 & 16711422) >> 1 | var11 & -16777216;
|
||||
this.drawGradientRect(var6 - 3, var7 - 3 + 1, var6 - 3 + 1, var7 + var9 + 3 - 1, var11, var12);
|
||||
this.drawGradientRect(var6 + var5 + 2, var7 - 3 + 1, var6 + var5 + 3, var7 + var9 + 3 - 1, var11, var12);
|
||||
this.drawGradientRect(var6 - 3, var7 - 3, var6 + var5 + 3, var7 - 3 + 1, var11, var11);
|
||||
this.drawGradientRect(var6 - 3, var7 + var9 + 2, var6 + var5 + 3, var7 + var9 + 3, var12, var12);
|
||||
|
||||
for (int var13 = 0; var13 < toolTips.length; ++var13)
|
||||
{
|
||||
String var14 = "\u00a77" + toolTips[var13];
|
||||
|
||||
this.fontRenderer.drawStringWithShadow(var14, var6, var7, -1);
|
||||
|
||||
if (var13 == 0)
|
||||
{
|
||||
var7 += 2;
|
||||
}
|
||||
|
||||
var7 += 10;
|
||||
}
|
||||
|
||||
this.zLevel = 0.0F;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -1,37 +0,0 @@
|
|||
package com.builtbroken.minecraft.prefab.invgui;
|
||||
|
||||
import net.minecraft.inventory.IInventory;
|
||||
import net.minecraft.inventory.Slot;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/** Slot that can only allow one itemStack into it
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class SlotRestricted extends Slot
|
||||
{
|
||||
private ItemStack[] itemStacks;
|
||||
|
||||
public SlotRestricted(IInventory par1iInventory, int par2, int par3, int par4, ItemStack... itemStacks)
|
||||
{
|
||||
super(par1iInventory, par2, par3, par4);
|
||||
this.itemStacks = itemStacks;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isItemValid(ItemStack itemStack)
|
||||
{
|
||||
if (itemStack != null && this.itemStacks != null)
|
||||
{
|
||||
for (int i = 0; i < itemStacks.length; i++)
|
||||
{
|
||||
ItemStack stack = itemStacks[i];
|
||||
if (stack != null && itemStack.isItemEqual(stack))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
|
@ -1,45 +0,0 @@
|
|||
package com.builtbroken.minecraft.recipes;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import com.builtbroken.common.Pair;
|
||||
|
||||
public class AssemblyObjectManager
|
||||
{
|
||||
/** Generic item or block based recipes. Entity recipes are handled by the entity */
|
||||
private HashMap<Pair<Integer, Integer>, IAssemblyRecipe> itemRecipes = new HashMap();
|
||||
|
||||
private static AssemblyObjectManager instance;
|
||||
|
||||
public static AssemblyObjectManager instance()
|
||||
{
|
||||
if (instance == null)
|
||||
{
|
||||
instance = new AssemblyObjectManager();
|
||||
}
|
||||
return instance;
|
||||
}
|
||||
|
||||
public IAssemblyRecipe getRecipeFor(Object object)
|
||||
{
|
||||
IAssemblyRecipe re = null;
|
||||
|
||||
if (re instanceof IAssemblyObject)
|
||||
{
|
||||
re = ((IAssemblyObject) object).getRecipe(object);
|
||||
}
|
||||
|
||||
if (re == null && object instanceof ItemStack)
|
||||
{
|
||||
re = itemRecipes.get(new Pair<Integer, Integer>(((ItemStack) object).itemID, ((ItemStack) object).getItemDamage()));
|
||||
if (re == null && ((ItemStack) object).getItem() instanceof IAssemblyObject)
|
||||
{
|
||||
re = ((IAssemblyObject) ((ItemStack) object).getItem()).getRecipe(object);
|
||||
}
|
||||
}
|
||||
|
||||
return re;
|
||||
}
|
||||
}
|
|
@ -1,38 +0,0 @@
|
|||
package com.builtbroken.minecraft.recipes;
|
||||
|
||||
/** Machine or entity that is creating a AssemblyObject. Avoid actually storing the recipe item if
|
||||
* there is one. Instead do what a few other mods do an give the illusion of the recipe being
|
||||
* imprinted into the machine while letting the player keep the item
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IAssemblier
|
||||
{
|
||||
/** @param assembler - this, used in the case that an item is the assembler, or even a block
|
||||
* without a tileEntiy. Eg a Workbench is an example of this as it has no tileEntiy but supports
|
||||
* crafting
|
||||
* @return current recipe */
|
||||
public IAssemblyRecipe getCurrentRecipe(Object object);
|
||||
|
||||
/** @param assembler - this, used in the case that an item is the assembler, or even a block
|
||||
* without a tileEntiy. Eg a Workbench is an example of this as it has no tileEntiy but supports
|
||||
* crafting
|
||||
* @return true if the recipe was set correctly */
|
||||
public boolean setCurrentRecipe(Object assembler, IAssemblyRecipe recipe);
|
||||
|
||||
/** @param assembler - this, used in the case that an item is the assembler, or even a block
|
||||
* without a tileEntiy. Eg a Workbench is an example of this as it has no tileEntiy but supports
|
||||
* crafting
|
||||
* @return current work in progress */
|
||||
public IAssemblyObject getCurrentWork(Object assembler);
|
||||
|
||||
/** Checks if the recipe can be created by this assembler. Should be used in cases were an
|
||||
* assembler is designed for one task type
|
||||
*
|
||||
* @param assembler - this, used in the case that an item is the assembler, or even a block
|
||||
* without a tileEntiy. Eg a Workbench is an example of this as it has no tileEntiy but supports
|
||||
* crafting
|
||||
* @param recipe - recipe
|
||||
* @return */
|
||||
public boolean canSupportRecipe(Object assembler, IAssemblyRecipe recipe);
|
||||
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.builtbroken.minecraft.recipes;
|
||||
|
||||
/** Applied to objects that are not complete and are being constructed from parts slowly. Used mainly
|
||||
* with assembly line armbots to create large objects like rockets automatically.
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IAssemblyObject
|
||||
{
|
||||
/** Gets the recipe that this object is being build from */
|
||||
public IAssemblyRecipe getRecipe(Object object);
|
||||
|
||||
/** Called each time the assembler makes a change to the object. Use this to trigger render
|
||||
* updates of the object */
|
||||
public void onChanged(Object object);
|
||||
|
||||
public void setStep(Object object, int step);
|
||||
|
||||
public int getStep(Object object);
|
||||
}
|
|
@ -1,19 +0,0 @@
|
|||
package com.builtbroken.minecraft.recipes;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
/** WIP feature to allow an item/block to be slowly built one step at a time. Object can be an
|
||||
* ItemStack, Entity, or even an object just for this purpose. Though if its not world based you'll
|
||||
* need to inform the assembler that it exists
|
||||
*
|
||||
* @author Darkgaurdsman */
|
||||
public interface IAssemblyRecipe
|
||||
{
|
||||
/** Cost in materials(ItemStack) to complete the next step in the build process */
|
||||
public ItemStack[] getCostAtStep(Object object, int step);
|
||||
|
||||
/** Number of steps to complete the crafting */
|
||||
public int getSteps(Object object);
|
||||
|
||||
public void nextStep(Object Object);
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package com.builtbroken.minecraft.recipes;
|
||||
|
||||
/** Advanced version of the assemblyRecipe. This is also used to display the recipe like a blueprint
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public interface IBlueprint extends IAssemblyRecipe
|
||||
{
|
||||
/** Check if the blueprint can be used by the object
|
||||
*
|
||||
* @param object - player, assembler,drone, entity, block, tileEntity
|
||||
* @return true if it can be used. This is mainly used for disabling recipes for players */
|
||||
public boolean canUseBlueprint(Object object);
|
||||
|
||||
/** Should a blueprint item be created for this blueprint. */
|
||||
public boolean createItemFor();
|
||||
|
||||
}
|
|
@ -1,15 +0,0 @@
|
|||
package com.builtbroken.minecraft.recipes;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
/** Items that are used as molds by the mold-injector to create items from liquid materials. Eg iron
|
||||
* armor from molten iron fluid
|
||||
*
|
||||
* @author Darkguardsman */
|
||||
public interface IInjectorMold
|
||||
{
|
||||
public ItemStack getOutput(FluidStack fluid, ItemStack mold);
|
||||
|
||||
public FluidStack getRequirement(ItemStack mold);
|
||||
}
|
|
@ -1,87 +0,0 @@
|
|||
package com.builtbroken.minecraft.worldgen;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraftforge.common.Configuration;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import cpw.mods.fml.common.FMLLog;
|
||||
|
||||
/** This class is used for storing ore generation data. If you are too lazy to generate your own
|
||||
* ores, you can do {@link #OreGenerator.addOre()} to add your ore to the list of ores to generate.
|
||||
*
|
||||
* @author Calclavia */
|
||||
public abstract class OreGenBase
|
||||
{
|
||||
public String name;
|
||||
|
||||
public String oreDictionaryName;
|
||||
|
||||
public boolean shouldGenerate = false;
|
||||
|
||||
public int blockIndexTexture;
|
||||
|
||||
public ItemStack oreStack;
|
||||
|
||||
public int oreID;
|
||||
|
||||
public int oreMeta;
|
||||
|
||||
/** What harvest level does this machine need to be acquired? */
|
||||
public int harvestLevel;
|
||||
|
||||
/** The predefined tool classes are "pickaxe", "shovel", "axe". You can add others for custom
|
||||
* tools. */
|
||||
public String harvestTool;
|
||||
|
||||
/** @param name - The name of the ore for display
|
||||
* @param textureFile - The 16x16 png texture of your ore to override
|
||||
* @param minGenerateLevel - The highest generation level of your ore
|
||||
* @param maxGenerateLevel - The lowest generation level of your ore
|
||||
* @param amountPerChunk - The amount of ores to generate per chunk
|
||||
* @param amountPerBranch - The amount of ores to generate in a clutter. E.g coal generates with
|
||||
* a lot of other coal next to it. How much do you want? */
|
||||
public OreGenBase(String name, String oreDiectionaryName, ItemStack stack, String harvestTool, int harvestLevel)
|
||||
{
|
||||
if (stack != null)
|
||||
{
|
||||
this.name = name;
|
||||
this.harvestTool = harvestTool;
|
||||
this.harvestLevel = harvestLevel;
|
||||
this.oreDictionaryName = oreDiectionaryName;
|
||||
this.oreStack = stack;
|
||||
this.oreID = stack.itemID;
|
||||
this.oreMeta = stack.getItemDamage();
|
||||
|
||||
OreDictionary.registerOre(oreDictionaryName, stack);
|
||||
MinecraftForge.setBlockHarvestLevel(Block.blocksList[stack.itemID], stack.getItemDamage(), harvestTool, harvestLevel);
|
||||
}
|
||||
else
|
||||
{
|
||||
FMLLog.severe("ItemStack is null while registering ore generation!");
|
||||
}
|
||||
}
|
||||
|
||||
public OreGenBase enable(Configuration config)
|
||||
{
|
||||
this.shouldGenerate = shouldGenerateOre(config, this.name);
|
||||
return this;
|
||||
}
|
||||
|
||||
/** Checks the config file and see if Universal Electricity should generate this ore */
|
||||
private static boolean shouldGenerateOre(Configuration configuration, String oreName)
|
||||
{
|
||||
configuration.load();
|
||||
boolean shouldGenerate = configuration.get("Ore_Generation", "Generate " + oreName, true).getBoolean(true);
|
||||
configuration.save();
|
||||
return shouldGenerate;
|
||||
}
|
||||
|
||||
public abstract void generate(World world, Random random, int varX, int varZ);
|
||||
|
||||
public abstract boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator);
|
||||
}
|
|
@ -1,146 +0,0 @@
|
|||
package com.builtbroken.minecraft.worldgen;
|
||||
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.util.MathHelper;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import net.minecraft.world.gen.ChunkProviderEnd;
|
||||
import net.minecraft.world.gen.ChunkProviderGenerate;
|
||||
import net.minecraft.world.gen.ChunkProviderHell;
|
||||
|
||||
/** This class is used for storing ore generation data. If you are too lazy to generate your own
|
||||
* ores, you can do {@link #OreGenerator.ORES_TO_GENERATE.add()} to add your ore to the list of ores
|
||||
* to generate.
|
||||
*
|
||||
* @author Calclavia */
|
||||
public class OreGenReplace extends OreGenBase
|
||||
{
|
||||
|
||||
public int minGenerateLevel;
|
||||
public int maxGenerateLevel;
|
||||
public int amountPerChunk;
|
||||
public int amountPerBranch;
|
||||
public int replaceID;
|
||||
|
||||
/** Dimensions to ignore ore generation */
|
||||
public boolean ignoreSurface = false;
|
||||
public boolean ignoreNether = true;
|
||||
public boolean ignoreEnd = true;
|
||||
|
||||
/** @param name - The name of the ore for display
|
||||
* @param textureFile - The 16x16 png texture of your ore to override
|
||||
* @param minGenerateLevel - The highest generation level of your ore
|
||||
* @param maxGenerateLevel - The lowest generation level of your ore
|
||||
* @param amountPerChunk - The amount of ores to generate per chunk
|
||||
* @param amountPerBranch - The amount of ores to generate in a clutter. E.g coal generates with
|
||||
* a lot of other coal next to it. How much do you want? */
|
||||
public OreGenReplace(String name, String oreDiectionaryName, ItemStack stack, int replaceID, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel)
|
||||
{
|
||||
super(name, oreDiectionaryName, stack, harvestTool, harvestLevel);
|
||||
this.minGenerateLevel = minGenerateLevel;
|
||||
this.maxGenerateLevel = maxGenerateLevel;
|
||||
this.amountPerChunk = amountPerChunk;
|
||||
this.amountPerBranch = amountPerBranch;
|
||||
this.replaceID = replaceID;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(World world, Random random, int varX, int varZ)
|
||||
{
|
||||
try
|
||||
{
|
||||
for (int i = 0; i < this.amountPerChunk; i++)
|
||||
{
|
||||
int x = varX + random.nextInt(16);
|
||||
int z = varZ + random.nextInt(16);
|
||||
int y = random.nextInt(Math.max(this.maxGenerateLevel - this.minGenerateLevel, 0)) + this.minGenerateLevel;
|
||||
this.generateReplace(world, random, x, y, z);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
System.out.println("Error generating ore: " + this.name);
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
public boolean generateReplace(World par1World, Random par2Random, int par3, int par4, int par5)
|
||||
{
|
||||
float var6 = par2Random.nextFloat() * (float) Math.PI;
|
||||
double var7 = par3 + 8 + MathHelper.sin(var6) * this.amountPerBranch / 8.0F;
|
||||
double var9 = par3 + 8 - MathHelper.sin(var6) * this.amountPerBranch / 8.0F;
|
||||
double var11 = par5 + 8 + MathHelper.cos(var6) * this.amountPerBranch / 8.0F;
|
||||
double var13 = par5 + 8 - MathHelper.cos(var6) * this.amountPerBranch / 8.0F;
|
||||
double var15 = par4 + par2Random.nextInt(3) - 2;
|
||||
double var17 = par4 + par2Random.nextInt(3) - 2;
|
||||
|
||||
for (int var19 = 0; var19 <= this.amountPerBranch; ++var19)
|
||||
{
|
||||
double var20 = var7 + (var9 - var7) * var19 / this.amountPerBranch;
|
||||
double var22 = var15 + (var17 - var15) * var19 / this.amountPerBranch;
|
||||
double var24 = var11 + (var13 - var11) * var19 / this.amountPerBranch;
|
||||
double var26 = par2Random.nextDouble() * this.amountPerBranch / 16.0D;
|
||||
double var28 = (MathHelper.sin(var19 * (float) Math.PI / this.amountPerBranch) + 1.0F) * var26 + 1.0D;
|
||||
double var30 = (MathHelper.sin(var19 * (float) Math.PI / this.amountPerBranch) + 1.0F) * var26 + 1.0D;
|
||||
int var32 = MathHelper.floor_double(var20 - var28 / 2.0D);
|
||||
int var33 = MathHelper.floor_double(var22 - var30 / 2.0D);
|
||||
int var34 = MathHelper.floor_double(var24 - var28 / 2.0D);
|
||||
int var35 = MathHelper.floor_double(var20 + var28 / 2.0D);
|
||||
int var36 = MathHelper.floor_double(var22 + var30 / 2.0D);
|
||||
int var37 = MathHelper.floor_double(var24 + var28 / 2.0D);
|
||||
|
||||
for (int var38 = var32; var38 <= var35; ++var38)
|
||||
{
|
||||
double var39 = (var38 + 0.5D - var20) / (var28 / 2.0D);
|
||||
|
||||
if (var39 * var39 < 1.0D)
|
||||
{
|
||||
for (int var41 = var33; var41 <= var36; ++var41)
|
||||
{
|
||||
double var42 = (var41 + 0.5D - var22) / (var30 / 2.0D);
|
||||
|
||||
if (var39 * var39 + var42 * var42 < 1.0D)
|
||||
{
|
||||
for (int var44 = var34; var44 <= var37; ++var44)
|
||||
{
|
||||
double var45 = (var44 + 0.5D - var24) / (var28 / 2.0D);
|
||||
|
||||
int block = par1World.getBlockId(var38, var41, var44);
|
||||
if (var39 * var39 + var42 * var42 + var45 * var45 < 1.0D && (this.replaceID == 0 || block == this.replaceID))
|
||||
{
|
||||
par1World.setBlock(var38, var41, var44, this.oreID, this.oreMeta, 2);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isOreGeneratedInWorld(World world, IChunkProvider chunkGenerator)
|
||||
{
|
||||
if (!this.shouldGenerate)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.ignoreSurface && chunkGenerator instanceof ChunkProviderGenerate)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.ignoreNether && chunkGenerator instanceof ChunkProviderHell)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (this.ignoreEnd && chunkGenerator instanceof ChunkProviderEnd)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package com.builtbroken.minecraft.worldgen;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
public class OreGenReplaceStone extends OreGenReplace
|
||||
{
|
||||
public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int minGenerateLevel, int maxGenerateLevel, int amountPerChunk, int amountPerBranch, String harvestTool, int harvestLevel)
|
||||
{
|
||||
super(name, oreDiectionaryName, stack, 1, minGenerateLevel, maxGenerateLevel, amountPerChunk, amountPerBranch, harvestTool, harvestLevel);
|
||||
}
|
||||
|
||||
// A simplified version of the constructor
|
||||
public OreGenReplaceStone(String name, String oreDiectionaryName, ItemStack stack, int maxGenerateLevel, int amountPerChunk, int amountPerBranch)
|
||||
{
|
||||
this(name, oreDiectionaryName, stack, 0, maxGenerateLevel, amountPerChunk, amountPerBranch, "pickaxe", 1);
|
||||
}
|
||||
}
|
|
@ -1,70 +0,0 @@
|
|||
package com.builtbroken.minecraft.worldgen;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Random;
|
||||
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.chunk.IChunkProvider;
|
||||
import cpw.mods.fml.common.IWorldGenerator;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
|
||||
public class OreGenerator implements IWorldGenerator
|
||||
{
|
||||
public static boolean isInitiated = false;
|
||||
|
||||
/** Add your ore data to this list of ores for it to automatically generate! No hassle indeed! */
|
||||
private static final List<OreGenBase> ORES_TO_GENERATE = new ArrayList<OreGenBase>();
|
||||
|
||||
/** Adds an ore to the ore generate list. Do this in pre-init. */
|
||||
public static void addOre(OreGenBase data)
|
||||
{
|
||||
if (!isInitiated)
|
||||
{
|
||||
GameRegistry.registerWorldGenerator(new OreGenerator());
|
||||
}
|
||||
|
||||
ORES_TO_GENERATE.add(data);
|
||||
}
|
||||
|
||||
/** Checks to see if this ore
|
||||
*
|
||||
* @param oreName
|
||||
* @return */
|
||||
public static boolean oreExists(String oreName)
|
||||
{
|
||||
for (OreGenBase ore : ORES_TO_GENERATE)
|
||||
{
|
||||
if (ore.oreDictionaryName == oreName)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Removes an ore to the ore generate list. Do this in init. */
|
||||
public static void removeOre(OreGenBase data)
|
||||
{
|
||||
ORES_TO_GENERATE.remove(data);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void generate(Random rand, int chunkX, int chunkZ, World world, IChunkProvider chunkGenerator, IChunkProvider chunkProvider)
|
||||
{
|
||||
chunkX = chunkX << 4;
|
||||
chunkZ = chunkZ << 4;
|
||||
|
||||
// Checks to make sure this is the normal
|
||||
// world
|
||||
for (OreGenBase oreData : ORES_TO_GENERATE)
|
||||
{
|
||||
if (oreData.shouldGenerate && oreData.isOreGeneratedInWorld(world, chunkGenerator))
|
||||
{
|
||||
oreData.generate(world, rand, chunkX, chunkZ);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue