Remove parts of UE prefab that are unneeded

This commit is contained in:
Aidan C. Brady 2013-12-16 07:31:34 -05:00
parent 4aa91b13ee
commit 8de6b8754f
19 changed files with 0 additions and 1976 deletions

View file

@ -1,42 +0,0 @@
package universalelectricity.prefab;
import net.minecraft.util.DamageSource;
import cpw.mods.fml.common.registry.LanguageRegistry;
public class CustomDamageSource extends DamageSource
{
/**
* Use this damage source for all types of electrical attacks.
*/
public static final CustomDamageSource electrocution = ((CustomDamageSource) new CustomDamageSource("electrocution").setDamageBypassesArmor()).setDeathMessage("%1$s got electrocuted!");
public CustomDamageSource(String damageType)
{
super(damageType);
}
@Deprecated
public CustomDamageSource setDeathMessage(String deathMessage)
{
LanguageRegistry.instance().addStringLocalization("death.attack." + this.damageType, deathMessage);
return this;
}
@Override
public DamageSource setDamageBypassesArmor()
{
return super.setDamageBypassesArmor();
}
@Override
public DamageSource setDamageAllowedInCreativeMode()
{
return super.setDamageAllowedInCreativeMode();
}
@Override
public DamageSource setFireDamage()
{
return super.setFireDamage();
}
}

View file

@ -1,192 +0,0 @@
package universalelectricity.prefab;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.item.crafting.CraftingManager;
import net.minecraft.item.crafting.IRecipe;
import net.minecraftforge.common.Configuration;
import cpw.mods.fml.common.registry.GameRegistry;
/**
* This class is used to replace recipes that are already added in the existing recipe pool for
* crafting and smelting. All recipe functions take account of the Forge Ore Dictionary. It also
* includes some recipe helper functions to shorten some of your function calls.
*
* @author Calclavia
*
*/
public class RecipeHelper
{
public static List<IRecipe> getRecipesByOutput(ItemStack output)
{
List<IRecipe> list = new ArrayList<IRecipe>();
for (Object obj : CraftingManager.getInstance().getRecipeList())
{
if (obj instanceof IRecipe)
{
if (((IRecipe) obj).getRecipeOutput() == output)
{
list.add((IRecipe) obj);
}
}
}
return list;
}
/**
* Replaces a recipe with a new IRecipe.
*
* @return True if successful
*/
public static boolean replaceRecipe(IRecipe recipe, IRecipe newRecipe)
{
for (Object obj : CraftingManager.getInstance().getRecipeList())
{
if (obj instanceof IRecipe)
{
if (((IRecipe) obj).equals(recipe) || obj == recipe)
{
CraftingManager.getInstance().getRecipeList().remove(obj);
CraftingManager.getInstance().getRecipeList().add(newRecipe);
return true;
}
}
}
return false;
}
/**
* Replaces a recipe with the resulting ItemStack with a new IRecipe.
*
* @return True if successful
*/
public static boolean replaceRecipe(ItemStack recipe, IRecipe newRecipe)
{
if (removeRecipe(recipe))
{
CraftingManager.getInstance().getRecipeList().add(newRecipe);
return true;
}
return false;
}
/**
* Removes a recipe by its IRecipe class.
*
* @return True if successful
*/
public static boolean removeRecipe(IRecipe recipe)
{
for (Object obj : CraftingManager.getInstance().getRecipeList())
{
if (obj != null)
{
if (obj instanceof IRecipe)
{
if (((IRecipe) obj).equals(recipe) || obj == recipe)
{
CraftingManager.getInstance().getRecipeList().remove(obj);
return true;
}
}
}
}
return false;
}
/**
* Removes the first recipe found by its output.
*
* @return True if successful
*/
public static boolean removeRecipe(ItemStack stack)
{
for (Object obj : CraftingManager.getInstance().getRecipeList())
{
if (obj != null)
{
if (obj instanceof IRecipe)
{
if (((IRecipe) obj).getRecipeOutput() != null)
{
if (((IRecipe) obj).getRecipeOutput().isItemEqual(stack))
{
CraftingManager.getInstance().getRecipeList().remove(obj);
return true;
}
}
}
}
}
return false;
}
/**
* Removes all recipes found that has this output. You may use this with Forge Ore Dictionary to
* remove all recipes with the FoD ID.
*
* @return True if successful
*/
public static boolean removeRecipes(ItemStack... itemStacks)
{
boolean didRemove = false;
for (Iterator itr = CraftingManager.getInstance().getRecipeList().iterator(); itr.hasNext();)
{
Object obj = itr.next();
if (obj != null)
{
if (obj instanceof IRecipe)
{
if (((IRecipe) obj).getRecipeOutput() != null)
{
for (ItemStack itemStack : itemStacks)
{
if (((IRecipe) obj).getRecipeOutput().isItemEqual(itemStack))
{
itr.remove();
didRemove = true;
break;
}
}
}
}
}
}
return didRemove;
}
/**
* Use this function if you want to check if the recipe is allowed in the configuration file.
*/
public static void addRecipe(IRecipe recipe, String name, Configuration configuration, boolean defaultBoolean)
{
if (configuration != null)
{
configuration.load();
if (configuration.get("Crafting", "Allow " + name + " Crafting", defaultBoolean).getBoolean(defaultBoolean))
{
GameRegistry.addRecipe(recipe);
}
configuration.save();
}
}
public static void addRecipe(IRecipe recipe, Configuration config, boolean defaultBoolean)
{
addRecipe(recipe, recipe.getRecipeOutput().getUnlocalizedName(), config, defaultBoolean);
}
}

View file

@ -1,95 +0,0 @@
package universalelectricity.prefab;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
/**
* Creates a slot with a specific amount of items that matches the slot's requirements. Allows easy
* shift right clicking management and slot blocking in classes. In your container you can use
* this.getSlot(i).isItemValid to justify the player's shift clicking actions to match the slot.
*
* @author Calclavia
*
*/
public class SlotSpecific extends Slot
{
public ItemStack[] validItemStacks = new ItemStack[0];
public Class[] validClasses = new Class[0];
public boolean isInverted = false;
public boolean isMetadataSensitive = false;
public SlotSpecific(IInventory par2IInventory, int par3, int par4, int par5, ItemStack... itemStacks)
{
super(par2IInventory, par3, par4, par5);
this.setItemStacks(itemStacks);
}
public SlotSpecific(IInventory par2IInventory, int par3, int par4, int par5, Class... validClasses)
{
super(par2IInventory, par3, par4, par5);
this.setClasses(validClasses);
}
public SlotSpecific setMetadataSensitive()
{
this.isMetadataSensitive = true;
return this;
}
public SlotSpecific setItemStacks(ItemStack... validItemStacks)
{
this.validItemStacks = validItemStacks;
return this;
}
public SlotSpecific setClasses(Class... validClasses)
{
this.validClasses = validClasses;
return this;
}
public SlotSpecific toggleInverted()
{
this.isInverted = !this.isInverted;
return this;
}
/**
* Check if the stack is a valid item for this slot. Always true beside for the armor slots.
*/
@Override
public boolean isItemValid(ItemStack compareStack)
{
boolean returnValue = false;
for (ItemStack itemStack : this.validItemStacks)
{
if (compareStack.isItemEqual(itemStack) || (!this.isMetadataSensitive && compareStack.itemID == itemStack.itemID))
{
returnValue = true;
break;
}
}
if (!returnValue)
{
for (Class clazz : this.validClasses)
{
if (clazz.equals(compareStack.getItem().getClass()) || clazz.isInstance(compareStack.getItem()))
{
returnValue = true;
break;
}
}
}
if (this.isInverted)
{
return !returnValue;
}
return returnValue;
}
}

View file

@ -1,88 +0,0 @@
package universalelectricity.prefab;
import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.common.registry.LanguageRegistry;
import cpw.mods.fml.relauncher.Side;
/**
* A class to help you out with translations.
*
* @author Calclavia
*
*/
public class TranslationHelper
{
/**
* Loads all the language files for a mod. This supports the loading of "child" language files
* for sub-languages to be loaded all from one file instead of creating multiple of them. An
* example of this usage would be different Spanish sub-translations (es_MX, es_YU).
*
* @param languagePath - The path to the mod's language file folder.
* @param languageSupported - The languages supported. E.g: new String[]{"en_US", "en_AU",
* "en_UK"}
* @return The amount of language files loaded successfully.
*/
public static int loadLanguages(String languagePath, String[] languageSupported)
{
int languages = 0;
/**
* Load all languages.
*/
for (String language : languageSupported)
{
LanguageRegistry.instance().loadLocalization(languagePath + language + ".properties", language, false);
if (LanguageRegistry.instance().getStringLocalization("children", language) != "")
{
try
{
String[] children = LanguageRegistry.instance().getStringLocalization("children", language).split(",");
for (String child : children)
{
if (child != "" || child != null)
{
LanguageRegistry.instance().loadLocalization(languagePath + language + ".properties", child, false);
languages++;
}
}
}
catch (Exception e)
{
FMLLog.severe("Failed to load a child language file.");
e.printStackTrace();
}
}
languages++;
}
return languages;
}
/**
* Gets the local text of your translation based on the given key. This will look through your
* mod's translation file that was previously registered. Make sure you enter the full name
*
* @param key - e.g tile.block.name
* @return The translated string or the default English translation if none was found.
*/
public static String getLocal(String key)
{
String text = null;
if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
{
text = LanguageRegistry.instance().getStringLocalization(key);
}
if (text == null || text == "")
{
text = LanguageRegistry.instance().getStringLocalization(key, "en_US");
}
return text;
}
}

View file

@ -1,200 +0,0 @@
package universalelectricity.prefab.block;
import java.lang.reflect.Method;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
/**
* An advanced block class that is to be extended for wrenching capabilities.
*/
public abstract class BlockAdvanced extends Block
{
public BlockAdvanced(int id, Material material)
{
super(id, material);
this.setHardness(0.6f);
}
/**
* DO NOT OVERRIDE THIS FUNCTION! Called when the block is right clicked by the player. This
* modified version detects electric items and wrench actions on your machine block. Do not
* override this function. Use onMachineActivated instead! (It does the same thing)
*
* @param world The World Object.
* @param x , y, z The coordinate of the block.
* @param side The side the player clicked on.
* @param hitX , hitY, hitZ The position the player clicked on relative to the block.
*/
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
int metadata = world.getBlockMetadata(x, y, z);
/**
* Check if the player is holding a wrench or an electric item. If so, call the wrench
* event.
*/
if (this.isUsableWrench(entityPlayer, entityPlayer.inventory.getCurrentItem(), x, y, z))
{
this.damageWrench(entityPlayer, entityPlayer.inventory.getCurrentItem(), x, y, z);
if (entityPlayer.isSneaking())
{
if (this.onSneakUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ))
{
return true;
}
}
if (this.onUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ))
{
return true;
}
}
if (entityPlayer.isSneaking())
{
if (this.onSneakMachineActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ))
{
return true;
}
}
return this.onMachineActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ);
}
/**
* A function that denotes if an itemStack is a wrench that can be used. Override this for more
* wrench compatibility. Compatible with Buildcraft and IC2 wrench API via reflection.
*
* @return True if it is a wrench.
*/
public boolean isUsableWrench(EntityPlayer entityPlayer, ItemStack itemStack, int x, int y, int z)
{
if (entityPlayer != null && itemStack != null)
{
Class wrenchClass = itemStack.getItem().getClass();
/**
* UE and Buildcraft
*/
try
{
Method methodCanWrench = wrenchClass.getMethod("canWrench", EntityPlayer.class, Integer.TYPE, Integer.TYPE, Integer.TYPE);
return (Boolean) methodCanWrench.invoke(itemStack.getItem(), entityPlayer, x, y, z);
}
catch (NoClassDefFoundError e)
{
}
catch (Exception e)
{
}
/**
* Industrialcraft
*/
try
{
if (wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrench") || wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrenchElectric"))
{
return itemStack.getItemDamage() < itemStack.getMaxDamage();
}
}
catch (Exception e)
{
}
}
return false;
}
/**
* This function damages a wrench. Works with Buildcraft and Industrialcraft wrenches.
*
* @return True if damage was successfull.
*/
public boolean damageWrench(EntityPlayer entityPlayer, ItemStack itemStack, int x, int y, int z)
{
if (this.isUsableWrench(entityPlayer, itemStack, x, y, z))
{
Class wrenchClass = itemStack.getItem().getClass();
/**
* UE and Buildcraft
*/
try
{
Method methodWrenchUsed = wrenchClass.getMethod("wrenchUsed", EntityPlayer.class, Integer.TYPE, Integer.TYPE, Integer.TYPE);
methodWrenchUsed.invoke(itemStack.getItem(), entityPlayer, x, y, z);
return true;
}
catch (Exception e)
{
}
/**
* Industrialcraft
*/
try
{
if (wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrench") || wrenchClass == Class.forName("ic2.core.item.tool.ItemToolWrenchElectric"))
{
Method methodWrenchDamage = wrenchClass.getMethod("damage", ItemStack.class, Integer.TYPE, EntityPlayer.class);
methodWrenchDamage.invoke(itemStack.getItem(), itemStack, 1, entityPlayer);
return true;
}
}
catch (Exception e)
{
}
}
return false;
}
/**
* Called when the machine is right clicked by the player
*
* @return True if something happens
*/
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
return false;
}
/**
* Called when the machine is being wrenched by a player while sneaking.
*
* @return True if something happens
*/
public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
return false;
}
/**
* Called when a player uses a wrench on the machine
*
* @return True if some happens
*/
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
return false;
}
/**
* Called when a player uses a wrench on the machine while sneaking. Only works with the UE
* wrench.
*
* @return True if some happens
*/
public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
return this.onUseWrench(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ);
}
}

View file

@ -1,193 +0,0 @@
package universalelectricity.prefab.block;
import java.util.List;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import universalelectricity.core.block.IConductor;
import universalelectricity.core.vector.Vector3;
import universalelectricity.prefab.tile.TileEntityConductor;
public abstract class BlockConductor extends BlockContainer
{
public boolean isWireCollision = true;
public Vector3 minVector = new Vector3(0.3, 0.3, 0.3);
public Vector3 maxVector = new Vector3(0.7, 0.7, 0.7);
public BlockConductor(int id, Material material)
{
super(id, material);
}
/**
* Called whenever the block is added into the world. Args: world, x, y, z
*/
@Override
public void onBlockAdded(World world, int x, int y, int z)
{
super.onBlockAdded(world, x, y, z);
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof IConductor)
{
((IConductor) tileEntity).refresh();
}
}
/**
* Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed
* (coordinates passed are their own) Args: x, y, z, neighbor blockID
*/
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int blockID)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof IConductor)
{
((IConductor) tileEntity).refresh();
}
}
/**
* Returns a bounding box from the pool of bounding boxes (this means this box can change after
* the pool has been cleared to be reused)
*/
@Override
public AxisAlignedBB getCollisionBoundingBoxFromPool(World world, int x, int y, int z)
{
this.setBlockBoundsBasedOnState(world, x, y, z);
return super.getCollisionBoundingBoxFromPool(world, x, y, z);
}
@Override
public AxisAlignedBB getSelectedBoundingBoxFromPool(World world, int x, int y, int z)
{
this.setBlockBoundsBasedOnState(world, x, y, z);
return super.getSelectedBoundingBoxFromPool(world, x, y, z);
}
/**
* Returns the bounding box of the wired rectangular prism to render.
*/
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
{
if (this.isWireCollision)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileEntityConductor)
{
TileEntity[] connectable = ((TileEntityConductor) tileEntity).getAdjacentConnections();
if (connectable != null)
{
float minX = (float) this.minVector.x;
float minY = (float) this.minVector.y;
float minZ = (float) this.minVector.z;
float maxX = (float) this.maxVector.x;
float maxY = (float) this.maxVector.y;
float maxZ = (float) this.maxVector.z;
if (connectable[0] != null)
{
minY = 0.0F;
}
if (connectable[1] != null)
{
maxY = 1.0F;
}
if (connectable[2] != null)
{
minZ = 0.0F;
}
if (connectable[3] != null)
{
maxZ = 1.0F;
}
if (connectable[4] != null)
{
minX = 0.0F;
}
if (connectable[5] != null)
{
maxX = 1.0F;
}
this.setBlockBounds(minX, minY, minZ, maxX, maxY, maxZ);
}
}
}
}
@Override
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB axisalignedbb, List list, Entity entity)
{
if (this.isWireCollision)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileEntityConductor)
{
TileEntity[] connectable = ((TileEntityConductor) tileEntity).getAdjacentConnections();
this.setBlockBounds((float) this.minVector.x, (float) this.minVector.y, (float) this.minVector.z, (float) this.maxVector.x, (float) this.maxVector.y, (float) this.maxVector.z);
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity);
if (connectable[4] != null)
{
this.setBlockBounds(0, (float) this.minVector.y, (float) this.minVector.z, (float) this.maxVector.x, (float) this.maxVector.y, (float) this.maxVector.z);
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity);
}
if (connectable[5] != null)
{
this.setBlockBounds((float) this.minVector.x, (float) this.minVector.y, (float) this.minVector.z, 1, (float) this.maxVector.y, (float) this.maxVector.z);
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity);
}
if (connectable[0] != null)
{
this.setBlockBounds((float) this.minVector.x, 0, (float) this.minVector.z, (float) this.maxVector.x, (float) this.maxVector.y, (float) this.maxVector.z);
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity);
}
if (connectable[1] != null)
{
this.setBlockBounds((float) this.minVector.x, (float) this.minVector.y, (float) this.minVector.z, (float) this.maxVector.x, 1, (float) this.maxVector.z);
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity);
}
if (connectable[2] != null)
{
this.setBlockBounds((float) this.minVector.x, (float) this.minVector.y, 0, (float) this.maxVector.x, (float) this.maxVector.y, (float) this.maxVector.z);
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity);
}
if (connectable[3] != null)
{
this.setBlockBounds((float) this.minVector.x, (float) this.minVector.y, (float) this.minVector.z, (float) this.maxVector.x, (float) this.maxVector.y, 1);
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity);
}
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
}
else
{
super.addCollisionBoxesToList(world, x, y, z, axisalignedbb, list, entity);
}
}
}

View file

@ -1,88 +0,0 @@
package universalelectricity.prefab.block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
/**
* A block that can rotate based on placed position and wrenching.
*
* @author Calclavia
*/
public abstract class BlockRotatable extends BlockTile implements IRotatableBlock
{
protected byte rotationMask = 60;
public BlockRotatable(int id, Material material)
{
super(id, material);
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase entityLiving, ItemStack itemStack)
{
int angle = MathHelper.floor_double((entityLiving.rotationYaw * 4.0F / 360.0F) + 0.5D) & 3;
int change = 3;
switch (angle)
{
case 0:
change = 2;
break;
case 1:
change = 5;
break;
case 2:
change = 3;
break;
case 3:
change = 4;
break;
}
world.setBlockMetadataWithNotify(x, y, z, change, 3);
}
@Override
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
return this.rotateBlock(world, x, y, z, ForgeDirection.getOrientation(side));
}
@Override
public boolean rotateBlock(World worldObj, int x, int y, int z, ForgeDirection axis)
{
int currentRotMeta = worldObj.getBlockMetadata(x, y, z);
ForgeDirection orientation = ForgeDirection.getOrientation(currentRotMeta);
ForgeDirection rotated = orientation.getRotation(axis);
int rmeta = rotated.ordinal();
int rmetaBit = 1 << rmeta;
System.out.println(rmetaBit + ": " + (rmetaBit & this.rotationMask));
if ((rmetaBit & this.rotationMask) == rmetaBit)
{
worldObj.setBlockMetadataWithNotify(x, y, z, rmeta, 3);
return true;
}
return false;
}
@Override
public ForgeDirection getDirection(World world, int x, int y, int z)
{
return ForgeDirection.getOrientation(world.getBlockMetadata(x, y, z));
}
@Override
public void setDirection(World world, int x, int y, int z, ForgeDirection direction)
{
world.setBlockMetadataWithNotify(x, y, z, direction.ordinal(), 3);
}
}

View file

@ -1,122 +0,0 @@
package universalelectricity.prefab.block;
import java.util.Random;
import net.minecraft.block.ITileEntityProvider;
import net.minecraft.block.material.Material;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
/**
* An advanced block class that is to be extended for wrenching capabilities.
*/
public abstract class BlockTile extends BlockAdvanced implements ITileEntityProvider
{
public BlockTile(int id, Material material)
{
super(id, material);
this.isBlockContainer = true;
}
/**
* Called whenever the block is added into the world. Args: world, x, y, z
*/
@Override
public void onBlockAdded(World par1World, int par2, int par3, int par4)
{
super.onBlockAdded(par1World, par2, par3, par4);
}
/**
* ejects contained items into the world, and notifies neighbours of an update, as appropriate
*/
@Override
public void breakBlock(World world, int x, int y, int z, int par5, int par6)
{
this.dropEntireInventory(world, x, y, z, par5, par6);
super.breakBlock(world, x, y, z, par5, par6);
world.removeBlockTileEntity(x, y, z);
}
/**
* Called when the block receives a BlockEvent - see World.addBlockEvent. By default, passes it
* on to the tile entity at this location. Args: world, x, y, z, blockID, EventID, event
* parameter
*/
@Override
public boolean onBlockEventReceived(World par1World, int par2, int par3, int par4, int par5, int par6)
{
super.onBlockEventReceived(par1World, par2, par3, par4, par5, par6);
TileEntity tileentity = par1World.getBlockTileEntity(par2, par3, par4);
return tileentity != null ? tileentity.receiveClientEvent(par5, par6) : false;
}
/**
* Override this if you don't need it. This will eject all items out of this machine if it has
* an inventory.
*/
public void dropEntireInventory(World world, int x, int y, int z, int par5, int par6)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity != null)
{
if (tileEntity instanceof IInventory)
{
IInventory inventory = (IInventory) tileEntity;
for (int var6 = 0; var6 < inventory.getSizeInventory(); ++var6)
{
ItemStack var7 = inventory.getStackInSlot(var6);
if (var7 != null)
{
Random random = new Random();
float var8 = random.nextFloat() * 0.8F + 0.1F;
float var9 = random.nextFloat() * 0.8F + 0.1F;
float var10 = random.nextFloat() * 0.8F + 0.1F;
while (var7.stackSize > 0)
{
int var11 = random.nextInt(21) + 10;
if (var11 > var7.stackSize)
{
var11 = var7.stackSize;
}
var7.stackSize -= var11;
EntityItem var12 = new EntityItem(world, (x + var8), (y + var9), (z + var10), new ItemStack(var7.itemID, var11, var7.getItemDamage()));
if (var7.hasTagCompound())
{
var12.getEntityItem().setTagCompound((NBTTagCompound) var7.getTagCompound().copy());
}
float var13 = 0.05F;
var12.motionX = ((float) random.nextGaussian() * var13);
var12.motionY = ((float) random.nextGaussian() * var13 + 0.2F);
var12.motionZ = ((float) random.nextGaussian() * var13);
world.spawnEntityInWorld(var12);
}
}
}
}
}
}
/**
* Returns the TileEntity used by this block. You should use the metadata sensitive version of
* this to get the maximum optimization!
*/
@Override
public TileEntity createNewTileEntity(World var1)
{
return null;
}
}

View file

@ -1,17 +0,0 @@
package universalelectricity.prefab.block;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
/** The interface is applied to Blocks that can rotate.
*
* @author DarkGuardsman */
public interface IRotatableBlock
{
/** @return Gets the facing direction. Always returns the front side of the block. */
public ForgeDirection getDirection(World world, int x, int y, int z);
/** @param Sets the facing direction. */
public void setDirection(World world, int x, int y, int z, ForgeDirection direection);
}

View file

@ -1,15 +0,0 @@
package universalelectricity.prefab.network;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet250CustomPayload;
import com.google.common.io.ByteArrayDataInput;
public interface IPacketReceiver
{
/**
* Sends some data to the tile entity.
*/
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream);
}

View file

@ -1,336 +0,0 @@
package universalelectricity.prefab.network;
import java.io.ByteArrayOutputStream;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import net.minecraft.entity.player.EntityPlayer;
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.core.vector.Vector3;
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;
/**
* This class is used for sending and receiving packets between the server and the client. You can
* directly use this by registering this packet manager with NetworkMod. Example:
*
* @NetworkMod(channels = { "BasicComponents" }, clientSideRequired = true, serverSideRequired =
* false, packetHandler = PacketManager.class)
*
* Check out {@link #BasicComponents} for better reference.
*
* @author Calclavia
*/
public class PacketManager implements IPacketHandler, IPacketReceiver
{
public enum PacketType
{
UNSPECIFIED, TILEENTITY;
public static PacketType get(int id)
{
if (id >= 0 && id < PacketType.values().length)
{
return PacketType.values()[id];
}
return UNSPECIFIED;
}
}
/**
* Writes a compressed NBTTagCompound to the OutputStream
*/
public static 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 static 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 static 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 static 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);
}
}
@SuppressWarnings("resource")
public static 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 static Packet getPacket(String channelName, Object... sendData)
{
return getPacketWithID(channelName, PacketType.UNSPECIFIED.ordinal(), sendData);
}
/**
* Gets a packet for the tile entity.
*
* @return
*/
@SuppressWarnings("resource")
public static Packet getPacket(String channelName, TileEntity sender, Object... sendData)
{
ByteArrayOutputStream bytes = new ByteArrayOutputStream();
DataOutputStream data = new DataOutputStream(bytes);
try
{
data.writeInt(PacketType.TILEENTITY.ordinal());
data.writeInt(sender.xCoord);
data.writeInt(sender.yCoord);
data.writeInt(sender.zCoord);
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 static 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 static 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 static void sendPacketToClients(Packet packet)
{
try
{
PacketDispatcher.sendPacketToAllPlayers(packet);
}
catch (Exception e)
{
System.out.println("Sending packet to client failed.");
e.printStackTrace();
}
}
public static DataOutputStream encodeDataStream(DataOutputStream data, Object... sendData)
{
try
{
for (Object dataValue : sendData)
{
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();
PacketType packetType = PacketType.get(packetTypeID);
if (packetType == PacketType.TILEENTITY)
{
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)
{
if (tileEntity instanceof IPacketReceiver)
{
((IPacketReceiver) tileEntity).handlePacketData(network, packetTypeID, packet, ((EntityPlayer) player), data);
}
}
}
}
else
{
this.handlePacketData(network, packetTypeID, packet, ((EntityPlayer) player), data);
}
}
catch (Exception e)
{
e.printStackTrace();
}
}
@Override
public void handlePacketData(INetworkManager network, int packetType, Packet250CustomPayload packet, EntityPlayer player, ByteArrayDataInput dataStream)
{
}
}

View file

@ -1,98 +0,0 @@
package universalelectricity.prefab.ore;
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);
}

View file

@ -1,153 +0,0 @@
package universalelectricity.prefab.ore;
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;
}
}

View file

@ -1,17 +0,0 @@
package universalelectricity.prefab.ore;
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);
}
}

View file

@ -1,78 +0,0 @@
package universalelectricity.prefab.ore;
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);
}
}
}
}

View file

@ -1,35 +0,0 @@
package universalelectricity.prefab.potion;
import net.minecraft.potion.Potion;
public abstract class CustomPotion extends Potion
{
/**
* Creates a new type of potion
*
* @param id - The ID of this potion. Make it greater than 20.
* @param isBadEffect - Is this potion a good potion or a bad one?
* @param color - The color of this potion.
* @param name - The name of this potion.
*/
public CustomPotion(int id, boolean isBadEffect, int color, String name)
{
super(id, isBadEffect, color);
this.setPotionName("potion." + name);
Potion.potionTypes[this.getId()] = this;
}
@Override
public Potion setIconIndex(int par1, int par2)
{
super.setIconIndex(par1, par2);
return this;
}
@Override
protected Potion setEffectiveness(double par1)
{
super.setEffectiveness(par1);
return this;
}
}

View file

@ -1,40 +0,0 @@
package universalelectricity.prefab.potion;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.item.ItemStack;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionEffect;
public class CustomPotionEffect extends PotionEffect
{
public CustomPotionEffect(int potionID, int duration, int amplifier)
{
super(potionID, duration, amplifier);
}
public CustomPotionEffect(Potion potion, int duration, int amplifier)
{
this(potion.getId(), duration, amplifier);
}
/**
* Creates a potion effect with custom curable items.
*
* @param curativeItems - ItemStacks that can cure this potion effect
*/
public CustomPotionEffect(int potionID, int duration, int amplifier, List<ItemStack> curativeItems)
{
super(potionID, duration, amplifier);
if (curativeItems == null)
{
this.setCurativeItems(new ArrayList<ItemStack>());
}
else
{
this.setCurativeItems(curativeItems);
}
}
}

View file

@ -1,36 +0,0 @@
package universalelectricity.prefab.vector;
import universalelectricity.core.vector.Vector2;
public class Region2
{
public Vector2 min;
public Vector2 max;
public Region2()
{
this(new Vector2(), new Vector2());
}
public Region2(Vector2 min, Vector2 max)
{
this.min = min;
this.max = max;
}
/**
* Checks if a point is located inside a region
*/
public boolean isIn(Vector2 point)
{
return (point.x > this.min.x && point.x < this.max.x) && (point.y > this.min.y && point.y < this.max.y);
}
/**
* Returns whether the given region intersects with this one.
*/
public boolean isIn(Region2 region)
{
return region.max.x > this.min.x && region.min.x < this.max.x ? (region.max.y > this.min.y && region.min.y < this.max.y ? true : false) : false;
}
}

View file

@ -1,131 +0,0 @@
package universalelectricity.prefab.vector;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import universalelectricity.core.vector.Vector3;
/**
* A cubical region class.
*
* @author Calclavia
*/
public class Region3
{
public Vector3 min;
public Vector3 max;
public Region3()
{
this(new Vector3(), new Vector3());
}
public Region3(Vector3 min, Vector3 max)
{
this.min = min;
this.max = max;
}
public Region3(AxisAlignedBB aabb)
{
this.min = new Vector3(aabb.minX, aabb.minY, aabb.minZ);
this.max = new Vector3(aabb.maxX, aabb.maxY, aabb.maxZ);
}
public AxisAlignedBB toAABB()
{
return AxisAlignedBB.getBoundingBox(this.min.x, this.min.y, this.min.z, this.max.x, this.max.y, this.max.z);
}
public Region2 toRegion2()
{
return new Region2(this.min.toVector2(), this.max.toVector2());
}
/**
* Checks if a point is located inside a region
*/
public boolean isIn(Vector3 point)
{
return (point.x > this.min.x && point.x < this.max.x) && (point.y > this.min.y && point.y < this.max.y) && (point.z > this.min.z && point.z < this.max.z);
}
/**
* Returns whether the given region intersects with this one.
*/
public boolean isIn(Region3 region)
{
return region.max.x > this.min.x && region.min.x < this.max.x ? (region.max.y > this.min.y && region.min.y < this.max.y ? region.max.z > this.min.z && region.min.z < this.max.z : false) : false;
}
public void expand(Vector3 difference)
{
this.min.subtract(difference);
this.max.add(difference);
}
/**
* @return List of vectors within this region.
*/
public List<Vector3> getVectors()
{
List<Vector3> vectors = new ArrayList<Vector3>();
for (int x = this.min.intX(); x < this.max.intX(); x++)
{
for (int y = this.min.intY(); x < this.max.intY(); y++)
{
for (int z = this.min.intZ(); x < this.max.intZ(); z++)
{
vectors.add(new Vector3(x, y, z));
}
}
}
return vectors;
}
public List<Vector3> getVectors(Vector3 center, int radius)
{
List<Vector3> vectors = new ArrayList<Vector3>();
for (int x = this.min.intX(); x < this.max.intX(); x++)
{
for (int y = this.min.intY(); x < this.max.intY(); y++)
{
for (int z = this.min.intZ(); x < this.max.intZ(); z++)
{
Vector3 vector3 = new Vector3(x, y, z);
if (center.distanceTo(vector3) <= radius)
{
vectors.add(vector3);
}
}
}
}
return vectors;
}
/**
* Returns all entities in this region.
*/
public List<Entity> getEntities(World world, Class<? extends Entity> entityClass)
{
return world.getEntitiesWithinAABB(entityClass, this.toAABB());
}
public List<Entity> getEntitiesExlude(World world, Entity entity)
{
return world.getEntitiesWithinAABBExcludingEntity(entity, this.toAABB());
}
public List<Entity> getEntities(World world)
{
return this.getEntities(world, Entity.class);
}
}