Now the multipart system depends on Qlib, wont load if not installed.

Also a code format of the system
This commit is contained in:
Modmuss50 2015-04-24 19:46:01 +01:00
parent d6797868fb
commit e2467caede
22 changed files with 1542 additions and 1852 deletions

View file

@ -1,22 +1,5 @@
package techreborn; package techreborn;
import java.io.File;
import net.minecraftforge.common.MinecraftForge;
import techreborn.achievement.TRAchievements;
import techreborn.client.GuiHandler;
import techreborn.compat.CompatManager;
import techreborn.compat.recipes.RecipeManager;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
import techreborn.init.ModItems;
import techreborn.init.ModParts;
import techreborn.init.ModRecipes;
import techreborn.lib.ModInfo;
import techreborn.packets.PacketHandler;
import techreborn.proxies.CommonProxy;
import techreborn.util.LogHelper;
import techreborn.world.TROreGen;
import cpw.mods.fml.common.FMLCommonHandler; import cpw.mods.fml.common.FMLCommonHandler;
import cpw.mods.fml.common.Mod; import cpw.mods.fml.common.Mod;
import cpw.mods.fml.common.SidedProxy; import cpw.mods.fml.common.SidedProxy;
@ -27,6 +10,22 @@ import cpw.mods.fml.common.network.NetworkRegistry;
import cpw.mods.fml.common.registry.GameRegistry; import cpw.mods.fml.common.registry.GameRegistry;
import erogenousbeef.coreTR.multiblock.MultiblockEventHandler; import erogenousbeef.coreTR.multiblock.MultiblockEventHandler;
import erogenousbeef.coreTR.multiblock.MultiblockServerTickHandler; import erogenousbeef.coreTR.multiblock.MultiblockServerTickHandler;
import net.minecraftforge.common.MinecraftForge;
import techreborn.achievement.TRAchievements;
import techreborn.client.GuiHandler;
import techreborn.compat.CompatManager;
import techreborn.compat.recipes.RecipeManager;
import techreborn.config.ConfigTechReborn;
import techreborn.init.ModBlocks;
import techreborn.init.ModItems;
import techreborn.init.ModRecipes;
import techreborn.lib.ModInfo;
import techreborn.packets.PacketHandler;
import techreborn.proxies.CommonProxy;
import techreborn.util.LogHelper;
import techreborn.world.TROreGen;
import java.io.File;
@Mod(modid = ModInfo.MOD_ID, name = ModInfo.MOD_NAME, version = ModInfo.MOD_VERSION, dependencies = ModInfo.MOD_DEPENDENCUIES, guiFactory = ModInfo.GUI_FACTORY_CLASS) @Mod(modid = ModInfo.MOD_ID, name = ModInfo.MOD_NAME, version = ModInfo.MOD_VERSION, dependencies = ModInfo.MOD_DEPENDENCUIES, guiFactory = ModInfo.GUI_FACTORY_CLASS)
public class Core { public class Core {
@ -56,8 +55,6 @@ public class Core {
ModBlocks.init(); ModBlocks.init();
// Register ModItems // Register ModItems
ModItems.init(); ModItems.init();
// Register Multiparts
ModParts.init();
// Recipes // Recipes
ModRecipes.init(); ModRecipes.init();
// Compat // Compat

View file

@ -3,6 +3,7 @@ package techreborn.compat;
import techreborn.compat.waila.CompatModuleWaila; import techreborn.compat.waila.CompatModuleWaila;
import cpw.mods.fml.common.Loader; import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.event.FMLInitializationEvent; import cpw.mods.fml.common.event.FMLInitializationEvent;
import techreborn.init.ModParts;
public class CompatManager { public class CompatManager {
@ -12,5 +13,9 @@ public class CompatManager {
{ {
new CompatModuleWaila().init(event); new CompatModuleWaila().init(event);
} }
if(Loader.isModLoaded("qmunitylib")){
// Register Multiparts
ModParts.init();
}
} }
} }

View file

@ -1,11 +1,11 @@
package techreborn.partSystem; package techreborn.partSystem;
import java.util.ArrayList;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.ArrayList;
public interface ICustomHighlight { public interface ICustomHighlight {
ArrayList<AxisAlignedBB> getBoxes(World world, int x, int y, int z, ArrayList<AxisAlignedBB> getBoxes(World world, int x, int y, int z,

View file

@ -4,13 +4,8 @@
package techreborn.partSystem; package techreborn.partSystem;
import cpw.mods.fml.relauncher.SideOnly;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import java.util.List;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -21,9 +16,6 @@ import uk.co.qmunity.lib.client.render.RenderHelper;
import java.util.List; import java.util.List;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/** /**
* This is based of * This is based of
* https://github.com/Qmunity/QmunityLib/blob/master/src/main/java * https://github.com/Qmunity/QmunityLib/blob/master/src/main/java

View file

@ -27,8 +27,7 @@ public abstract class ModPart extends TileEntity implements IModPart {
* This is the world * This is the world
*/ */
@Override @Override
public World getWorld() public World getWorld() {
{
return world; return world;
} }
@ -36,8 +35,7 @@ public abstract class ModPart extends TileEntity implements IModPart {
/** /**
* This sets the world Don't use this unless you know what you are doing. * This sets the world Don't use this unless you know what you are doing.
*/ */
public void setWorld(World world) public void setWorld(World world) {
{
this.world = world; this.world = world;
setWorldObj(world); setWorldObj(world);
} }
@ -46,8 +44,7 @@ public abstract class ModPart extends TileEntity implements IModPart {
* Gets the x position in the world * Gets the x position in the world
*/ */
@Override @Override
public int getX() public int getX() {
{
return location.getX(); return location.getX();
} }
@ -55,8 +52,7 @@ public abstract class ModPart extends TileEntity implements IModPart {
* Gets the y position in the world * Gets the y position in the world
*/ */
@Override @Override
public int getY() public int getY() {
{
return location.getY(); return location.getY();
} }
@ -64,24 +60,21 @@ public abstract class ModPart extends TileEntity implements IModPart {
* Gets the z position in the world * Gets the z position in the world
*/ */
@Override @Override
public int getZ() public int getZ() {
{
return location.getZ(); return location.getZ();
} }
/** /**
* Gets the location of the part * Gets the location of the part
*/ */
public Location getLocation() public Location getLocation() {
{
return location; return location;
} }
/** /**
* Sets the x position in the world * Sets the x position in the world
*/ */
public void setLocation(Location location) public void setLocation(Location location) {
{
this.location = location; this.location = location;
this.xCoord = location.getX(); this.xCoord = location.getX();
this.yCoord = location.getY(); this.yCoord = location.getY();
@ -89,14 +82,12 @@ public abstract class ModPart extends TileEntity implements IModPart {
} }
@Override @Override
public World getWorldObj() public World getWorldObj() {
{
return getWorld(); return getWorld();
} }
@Override @Override
public void setWorldObj(World p_145834_1_) public void setWorldObj(World p_145834_1_) {
{
super.setWorldObj(p_145834_1_); super.setWorldObj(p_145834_1_);
} }
} }

View file

@ -14,50 +14,37 @@ public class ModPartItem extends Item {
ModPart modPart; ModPart modPart;
public ModPartItem(ModPart part) public ModPartItem(ModPart part) {
{
modPart = part; modPart = part;
setUnlocalizedName(Names.Unlocalized.Items.MULTIPART); setUnlocalizedName(Names.Unlocalized.Items.MULTIPART);
} }
@Override @Override
public boolean onItemUse(ItemStack item, EntityPlayer player, World world, public boolean onItemUse(ItemStack item, EntityPlayer player, World world,
int x, int y, int z, int face, float x_, float y_, float z_) int x, int y, int z, int face, float x_, float y_, float z_) {
{ if (ModPartRegistry.masterProvider != null) {
if (ModPartRegistry.masterProvider != null) try {
{
try
{
if (ModPartRegistry.masterProvider.placePart(item, player, if (ModPartRegistry.masterProvider.placePart(item, player,
world, x, y, z, face, x_, y_, z_, modPart.getClass() world, x, y, z, face, x_, y_, z_, modPart.getClass()
.newInstance())) .newInstance())) {
{
return true; return true;
} }
} catch (InstantiationException e) } catch (InstantiationException e) {
{
e.printStackTrace(); e.printStackTrace();
} catch (IllegalAccessException e) } catch (IllegalAccessException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
return false; return false;
} else } else {
{ for (IPartProvider partProvider : ModPartRegistry.providers) {
for (IPartProvider partProvider : ModPartRegistry.providers) try {
{
try
{
if (partProvider.placePart(item, player, world, x, y, z, if (partProvider.placePart(item, player, world, x, y, z,
face, x_, y_, z_, modPart.getClass().newInstance())) face, x_, y_, z_, modPart.getClass().newInstance())) {
{
return true; return true;
} }
} catch (InstantiationException e) } catch (InstantiationException e) {
{
e.printStackTrace(); e.printStackTrace();
} catch (IllegalAccessException e) } catch (IllegalAccessException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -66,13 +53,11 @@ public class ModPartItem extends Item {
} }
@Override @Override
public String getUnlocalizedName(ItemStack stack) public String getUnlocalizedName(ItemStack stack) {
{
return modPart.getName(); return modPart.getName();
} }
public ModPart getModPart() public ModPart getModPart() {
{
return modPart; return modPart;
} }
} }

View file

@ -4,15 +4,15 @@
package techreborn.partSystem; package techreborn.partSystem;
import java.util.ArrayList; import cpw.mods.fml.common.Loader;
import java.util.HashMap; import cpw.mods.fml.common.registry.GameRegistry;
import java.util.Map;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import techreborn.client.TechRebornCreativeTab; import techreborn.client.TechRebornCreativeTab;
import techreborn.util.LogHelper; import techreborn.util.LogHelper;
import cpw.mods.fml.common.Loader;
import cpw.mods.fml.common.registry.GameRegistry; import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
public class ModPartRegistry { public class ModPartRegistry {
@ -24,17 +24,14 @@ public class ModPartRegistry {
public static Map<Item, String> itemParts = new HashMap<Item, String>(); public static Map<Item, String> itemParts = new HashMap<Item, String>();
public static void registerPart(ModPart iModPart) public static void registerPart(ModPart iModPart) {
{
parts.add(iModPart); parts.add(iModPart);
} }
public static void addAllPartsToSystems() public static void addAllPartsToSystems() {
{
LogHelper.info("Started to load all parts"); LogHelper.info("Started to load all parts");
for (ModPart modPart : ModPartRegistry.parts) for (ModPart modPart : ModPartRegistry.parts) {
{
Item part = new ModPartItem(modPart) Item part = new ModPartItem(modPart)
.setUnlocalizedName(modPart.getName()) .setUnlocalizedName(modPart.getName())
.setCreativeTab(TechRebornCreativeTab.instance) .setCreativeTab(TechRebornCreativeTab.instance)
@ -43,46 +40,36 @@ public class ModPartRegistry {
itemParts.put(part, modPart.getName()); itemParts.put(part, modPart.getName());
} }
for (IPartProvider iPartProvider : providers) for (IPartProvider iPartProvider : providers) {
{
iPartProvider.registerPart(); iPartProvider.registerPart();
} }
} }
public static Item getItem(String string) public static Item getItem(String string) {
{ for (Map.Entry<Item, String> entry : itemParts.entrySet()) {
for (Map.Entry<Item, String> entry : itemParts.entrySet()) if (entry.getValue().equals(string)) {
{
if (entry.getValue().equals(string))
{
return entry.getKey(); return entry.getKey();
} }
} }
return null; return null;
} }
public static void addProvider(String className, String modid) public static void addProvider(String className, String modid) {
{ if (Loader.isModLoaded(modid) || modid.equals("Minecraft")) {
if (Loader.isModLoaded(modid) || modid.equals("Minecraft")) try {
{
try
{
IPartProvider iPartProvider = null; IPartProvider iPartProvider = null;
iPartProvider = (IPartProvider) Class.forName(className) iPartProvider = (IPartProvider) Class.forName(className)
.newInstance(); .newInstance();
providers.add(iPartProvider); providers.add(iPartProvider);
} catch (ClassNotFoundException e) } catch (ClassNotFoundException e) {
{
e.printStackTrace(); e.printStackTrace();
LogHelper.error("Failed to load " + className LogHelper.error("Failed to load " + className
+ " to the part system!"); + " to the part system!");
} catch (InstantiationException e) } catch (InstantiationException e) {
{
e.printStackTrace(); e.printStackTrace();
LogHelper.error("Failed to load " + className LogHelper.error("Failed to load " + className
+ " to the part system!"); + " to the part system!");
} catch (IllegalAccessException e) } catch (IllegalAccessException e) {
{
e.printStackTrace(); e.printStackTrace();
LogHelper.error("Failed to load " + className LogHelper.error("Failed to load " + className
+ " to the part system!"); + " to the part system!");
@ -91,11 +78,9 @@ public class ModPartRegistry {
} }
// Only use this one if it is a standalone Provider // Only use this one if it is a standalone Provider
public static void addProvider(IPartProvider iPartProvider) public static void addProvider(IPartProvider iPartProvider) {
{
if (Loader.isModLoaded(iPartProvider.modID()) if (Loader.isModLoaded(iPartProvider.modID())
|| iPartProvider.modID().equals("Minecraft")) || iPartProvider.modID().equals("Minecraft")) {
{
providers.add(iPartProvider); providers.add(iPartProvider);
} }
} }

View file

@ -4,47 +4,39 @@
package techreborn.partSystem; package techreborn.partSystem;
import java.util.Map;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.world.World; import net.minecraft.world.World;
import techreborn.lib.Location; import techreborn.lib.Location;
import techreborn.lib.vecmath.Vecs3dCube; import techreborn.lib.vecmath.Vecs3dCube;
import java.util.Map;
public class ModPartUtils { public class ModPartUtils {
public static boolean checkOcclusion(World world, Location location, public static boolean checkOcclusion(World world, Location location,
Vecs3dCube cube) Vecs3dCube cube) {
{ if (world == null) {
if (world == null)
{
return false; return false;
} }
IPartProvider partProvider = getPartProvider(world, location); IPartProvider partProvider = getPartProvider(world, location);
if (partProvider != null) if (partProvider != null) {
{
return partProvider.checkOcclusion(world, location, cube); return partProvider.checkOcclusion(world, location, cube);
} }
return false; return false;
} }
public static boolean checkOcclusion(World world, int x, int y, int z, public static boolean checkOcclusion(World world, int x, int y, int z,
Vecs3dCube cube) Vecs3dCube cube) {
{
return checkOcclusion(world, new Location(x, y, z), cube); return checkOcclusion(world, new Location(x, y, z), cube);
} }
public static boolean checkOcclusionInvert(World world, Location location, public static boolean checkOcclusionInvert(World world, Location location,
Vecs3dCube cube) Vecs3dCube cube) {
{ if (world == null) {
if (world == null)
{
return false; return false;
} }
for (IPartProvider iPartProvider : ModPartRegistry.providers) for (IPartProvider iPartProvider : ModPartRegistry.providers) {
{ if (!iPartProvider.checkOcclusion(world, location, cube)) {
if (!iPartProvider.checkOcclusion(world, location, cube))
{
return false; return false;
} }
} }
@ -52,48 +44,37 @@ public class ModPartUtils {
} }
public static boolean checkOcclusionInvert(World world, int x, int y, public static boolean checkOcclusionInvert(World world, int x, int y,
int z, Vecs3dCube cube) int z, Vecs3dCube cube) {
{
return checkOcclusionInvert(world, new Location(x, y, z), cube); return checkOcclusionInvert(world, new Location(x, y, z), cube);
} }
public static boolean hasPart(World world, Location location, String name) public static boolean hasPart(World world, Location location, String name) {
{ for (IPartProvider iPartProvider : ModPartRegistry.providers) {
for (IPartProvider iPartProvider : ModPartRegistry.providers) if (iPartProvider.hasPart(world, location, name)) {
{
if (iPartProvider.hasPart(world, location, name))
{
return true; return true;
} }
} }
return false; return false;
} }
public static boolean hasPart(World world, int x, int y, int z, String name) public static boolean hasPart(World world, int x, int y, int z, String name) {
{
return hasPart(world, new Location(x, y, z), name); return hasPart(world, new Location(x, y, z), name);
} }
public static Item getItemForPart(String string) public static Item getItemForPart(String string) {
{
for (Map.Entry<Item, String> item : ModPartRegistry.itemParts for (Map.Entry<Item, String> item : ModPartRegistry.itemParts
.entrySet()) .entrySet()) {
{ if (item.getValue().equals(string)) {
if (item.getValue().equals(string))
{
return item.getKey(); return item.getKey();
} }
} }
return null; return null;
} }
public static IPartProvider getPartProvider(World world, Location location) public static IPartProvider getPartProvider(World world, Location location) {
{ for (IPartProvider partProvider : ModPartRegistry.providers) {
for (IPartProvider partProvider : ModPartRegistry.providers)
{
if (partProvider.isTileFromProvider(world.getTileEntity( if (partProvider.isTileFromProvider(world.getTileEntity(
location.getX(), location.getY(), location.getZ()))) location.getX(), location.getY(), location.getZ()))) {
{
return partProvider; return partProvider;
} }
} }

View file

@ -4,44 +4,38 @@
package techreborn.partSystem.QLib; package techreborn.partSystem.QLib;
import java.util.ArrayList;
import java.util.List;
import techreborn.lib.vecmath.Vecs3d; import techreborn.lib.vecmath.Vecs3d;
import techreborn.lib.vecmath.Vecs3dCube; import techreborn.lib.vecmath.Vecs3dCube;
import uk.co.qmunity.lib.vec.Vec3d; import uk.co.qmunity.lib.vec.Vec3d;
import uk.co.qmunity.lib.vec.Vec3dCube; import uk.co.qmunity.lib.vec.Vec3dCube;
import java.util.ArrayList;
import java.util.List;
/** /**
* Created by mark on 09/12/14. * Created by mark on 09/12/14.
*/ */
public class ModLib2QLib { public class ModLib2QLib {
public static Vec3d convert(Vecs3d input) public static Vec3d convert(Vecs3d input) {
{
return new Vec3d(input.getX(), input.getY(), input.getZ()); return new Vec3d(input.getX(), input.getY(), input.getZ());
} }
public static Vec3dCube convert(Vecs3dCube input) public static Vec3dCube convert(Vecs3dCube input) {
{
return new Vec3dCube(input.toAABB()); return new Vec3dCube(input.toAABB());
} }
public static Vecs3d convert(Vec3d input) public static Vecs3d convert(Vec3d input) {
{
return new Vecs3d(input.getX(), input.getY(), input.getZ()); return new Vecs3d(input.getX(), input.getY(), input.getZ());
} }
public static Vecs3dCube convert(Vec3dCube input) public static Vecs3dCube convert(Vec3dCube input) {
{
return new Vecs3dCube(input.toAABB()); return new Vecs3dCube(input.toAABB());
} }
public static List<Vecs3dCube> convert(List<Vec3dCube> input) public static List<Vecs3dCube> convert(List<Vec3dCube> input) {
{
List<Vecs3dCube> list = new ArrayList<Vecs3dCube>(); List<Vecs3dCube> list = new ArrayList<Vecs3dCube>();
for (Vec3dCube cube : input) for (Vec3dCube cube : input) {
{
list.add(new Vecs3dCube(cube.toAABB())); list.add(new Vecs3dCube(cube.toAABB()));
} }
return list; return list;
@ -49,11 +43,9 @@ public class ModLib2QLib {
// Its got to be called becuase of some weird thing see: // Its got to be called becuase of some weird thing see:
// https://stackoverflow.com/questions/1998544/method-has-the-same-erasure-as-another-method-in-type // https://stackoverflow.com/questions/1998544/method-has-the-same-erasure-as-another-method-in-type
public static List<Vec3dCube> convert2(List<Vecs3dCube> input) public static List<Vec3dCube> convert2(List<Vecs3dCube> input) {
{
List<Vec3dCube> list = new ArrayList<Vec3dCube>(); List<Vec3dCube> list = new ArrayList<Vec3dCube>();
for (Vecs3dCube cube : input) for (Vecs3dCube cube : input) {
{
list.add(new Vec3dCube(cube.toAABB())); list.add(new Vec3dCube(cube.toAABB()));
} }
return list; return list;

View file

@ -4,9 +4,6 @@
package techreborn.partSystem.QLib; package techreborn.partSystem.QLib;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.renderer.RenderBlocks; import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
@ -23,51 +20,47 @@ import uk.co.qmunity.lib.vec.Vec3d;
import uk.co.qmunity.lib.vec.Vec3dCube; import uk.co.qmunity.lib.vec.Vec3dCube;
import uk.co.qmunity.lib.vec.Vec3i; import uk.co.qmunity.lib.vec.Vec3i;
import java.util.ArrayList;
import java.util.List;
public class QModPart extends PartBase implements IPartCollidable, public class QModPart extends PartBase implements IPartCollidable,
IPartSelectable, IPartRenderPlacement, IPartTicking, IPartSelectable, IPartRenderPlacement, IPartTicking,
IPartUpdateListener { IPartUpdateListener {
ModPart iModPart; ModPart iModPart;
public QModPart(ModPart iModPart) public QModPart(ModPart iModPart) {
{
this.iModPart = iModPart; this.iModPart = iModPart;
} }
@Override @Override
public void setParent(ITilePartHolder parent) public void setParent(ITilePartHolder parent) {
{
super.setParent(parent); super.setParent(parent);
} }
@Override @Override
public String getType() public String getType() {
{
return iModPart.getName(); return iModPart.getName();
} }
@Override @Override
public ItemStack getItem() public ItemStack getItem() {
{
return iModPart.getItem(); return iModPart.getItem();
} }
@Override @Override
public void addCollisionBoxesToList(List<Vec3dCube> boxes, Entity entity) public void addCollisionBoxesToList(List<Vec3dCube> boxes, Entity entity) {
{
List<Vecs3dCube> cubes = new ArrayList<Vecs3dCube>(); List<Vecs3dCube> cubes = new ArrayList<Vecs3dCube>();
iModPart.addCollisionBoxesToList(cubes, entity); iModPart.addCollisionBoxesToList(cubes, entity);
for (Vecs3dCube cube : cubes) for (Vecs3dCube cube : cubes) {
{
if (cube != null) if (cube != null)
boxes.add(ModLib2QLib.convert(cube)); boxes.add(ModLib2QLib.convert(cube));
} }
} }
@Override @Override
public void renderDynamic(Vec3d translation, double delta, int pass) public void renderDynamic(Vec3d translation, double delta, int pass) {
{
iModPart.renderDynamic(ModLib2QLib.convert(translation), delta); iModPart.renderDynamic(ModLib2QLib.convert(translation), delta);
} }
@ -78,28 +71,23 @@ public class QModPart extends PartBase implements IPartCollidable,
@Override @Override
public QMovingObjectPosition rayTrace(Vec3d start, Vec3d end) public QMovingObjectPosition rayTrace(Vec3d start, Vec3d end) {
{
return RayTracer.instance().rayTraceCubes(this, start, end); return RayTracer.instance().rayTraceCubes(this, start, end);
} }
@Override @Override
public List<Vec3dCube> getSelectionBoxes() public List<Vec3dCube> getSelectionBoxes() {
{
return ModLib2QLib.convert2(iModPart.getSelectionBoxes()); return ModLib2QLib.convert2(iModPart.getSelectionBoxes());
} }
@Override @Override
public World getWorld() public World getWorld() {
{
return getParent().getWorld(); return getParent().getWorld();
} }
@Override @Override
public void update() public void update() {
{ if (iModPart.world == null || iModPart.location == null) {
if (iModPart.world == null || iModPart.location == null)
{
iModPart.setWorld(getWorld()); iModPart.setWorld(getWorld());
iModPart.setLocation(new Location(getX(), getY(), getZ())); iModPart.setLocation(new Location(getX(), getY(), getZ()));
} }
@ -107,22 +95,18 @@ public class QModPart extends PartBase implements IPartCollidable,
} }
@Override @Override
public void onPartChanged(IPart part) public void onPartChanged(IPart part) {
{
iModPart.nearByChange(); iModPart.nearByChange();
} }
@Override @Override
public void onNeighborBlockChange() public void onNeighborBlockChange() {
{
iModPart.nearByChange(); iModPart.nearByChange();
} }
@Override @Override
public void onNeighborTileChange() public void onNeighborTileChange() {
{ if (iModPart.world == null || iModPart.location == null) {
if (iModPart.world == null || iModPart.location == null)
{
iModPart.setWorld(getWorld()); iModPart.setWorld(getWorld());
iModPart.setLocation(new Location(getX(), getY(), getZ())); iModPart.setLocation(new Location(getX(), getY(), getZ()));
} }
@ -130,26 +114,21 @@ public class QModPart extends PartBase implements IPartCollidable,
} }
@Override @Override
public void onAdded() public void onAdded() {
{ if (iModPart.location != null) {
if (iModPart.location != null)
{
iModPart.nearByChange(); iModPart.nearByChange();
iModPart.onAdded(); iModPart.onAdded();
} }
} }
@Override @Override
public void onRemoved() public void onRemoved() {
{
iModPart.onRemoved(); iModPart.onRemoved();
} }
@Override @Override
public void onLoaded() public void onLoaded() {
{ if (iModPart.world == null || iModPart.location == null) {
if (iModPart.world == null || iModPart.location == null)
{
iModPart.setWorld(getWorld()); iModPart.setWorld(getWorld());
iModPart.setLocation(new Location(getX(), getY(), getZ())); iModPart.setLocation(new Location(getX(), getY(), getZ()));
} }
@ -157,14 +136,12 @@ public class QModPart extends PartBase implements IPartCollidable,
} }
@Override @Override
public void onUnloaded() public void onUnloaded() {
{
} }
@Override @Override
public void onConverted() public void onConverted() {
{
} }
} }

View file

@ -4,8 +4,6 @@
package techreborn.partSystem.QLib; package techreborn.partSystem.QLib;
import java.util.List;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -27,22 +25,18 @@ import uk.co.qmunity.lib.tile.TileMultipart;
import uk.co.qmunity.lib.vec.Vec3dCube; import uk.co.qmunity.lib.vec.Vec3dCube;
import uk.co.qmunity.lib.vec.Vec3i; import uk.co.qmunity.lib.vec.Vec3i;
import java.util.List;
public class QModPartFactory implements IPartFactory, IPartProvider { public class QModPartFactory implements IPartFactory, IPartProvider {
@Override @Override
public IPart createPart(String type, boolean client) public IPart createPart(String type, boolean client) {
{ for (ModPart modPart : ModPartRegistry.parts) {
for (ModPart modPart : ModPartRegistry.parts) if (modPart.getName().equals(type)) {
{ try {
if (modPart.getName().equals(type))
{
try
{
return new QModPart(modPart.getClass().newInstance()); return new QModPart(modPart.getClass().newInstance());
} catch (InstantiationException e) } catch (InstantiationException e) {
{
e.printStackTrace(); e.printStackTrace();
} catch (IllegalAccessException e) } catch (IllegalAccessException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -53,8 +47,7 @@ public class QModPartFactory implements IPartFactory, IPartProvider {
@Override @Override
public boolean placePart(ItemStack item, EntityPlayer player, World world, public boolean placePart(ItemStack item, EntityPlayer player, World world,
int x, int y, int z, int face, float x_, float y_, float z_, int x, int y, int z, int face, float x_, float y_, float z_,
ModPart modPart) ModPart modPart) {
{
IPart part = createPart( IPart part = createPart(
item, item,
player, player,
@ -71,20 +64,17 @@ public class QModPartFactory implements IPartFactory, IPartProvider {
} }
@Override @Override
public boolean isTileFromProvider(TileEntity tileEntity) public boolean isTileFromProvider(TileEntity tileEntity) {
{
return tileEntity instanceof TileMultipart; return tileEntity instanceof TileMultipart;
} }
public String getCreatedPartType(ItemStack item, EntityPlayer player, public String getCreatedPartType(ItemStack item, EntityPlayer player,
World world, MovingObjectPosition mop, ModPart modPart) World world, MovingObjectPosition mop, ModPart modPart) {
{
return modPart.getName(); return modPart.getName();
} }
public IPart createPart(ItemStack item, EntityPlayer player, World world, public IPart createPart(ItemStack item, EntityPlayer player, World world,
MovingObjectPosition mop, ModPart modPart) MovingObjectPosition mop, ModPart modPart) {
{
return PartRegistry.createPart( return PartRegistry.createPart(
getCreatedPartType(item, player, world, mop, modPart), getCreatedPartType(item, player, world, mop, modPart),
@ -92,41 +82,33 @@ public class QModPartFactory implements IPartFactory, IPartProvider {
} }
@Override @Override
public String modID() public String modID() {
{
return QLModInfo.MODID; return QLModInfo.MODID;
} }
@Override @Override
public void registerPart() public void registerPart() {
{
PartRegistry.registerFactory(new QModPartFactory()); PartRegistry.registerFactory(new QModPartFactory());
} }
@Override @Override
public boolean checkOcclusion(World world, Location location, public boolean checkOcclusion(World world, Location location,
Vecs3dCube cube) Vecs3dCube cube) {
{
return MultipartCompatibility.checkOcclusion(world, location.x, return MultipartCompatibility.checkOcclusion(world, location.x,
location.y, location.z, new Vec3dCube(cube.toAABB())); location.y, location.z, new Vec3dCube(cube.toAABB()));
} }
@Override @Override
public boolean hasPart(World world, Location location, String name) public boolean hasPart(World world, Location location, String name) {
{
TileEntity tileEntity = world.getTileEntity(location.getX(), TileEntity tileEntity = world.getTileEntity(location.getX(),
location.getY(), location.getZ()); location.getY(), location.getZ());
if (tileEntity instanceof TileMultipart) if (tileEntity instanceof TileMultipart) {
{
TileMultipart mp = (TileMultipart) tileEntity; TileMultipart mp = (TileMultipart) tileEntity;
boolean ret = false; boolean ret = false;
List<IPart> t = mp.getParts(); List<IPart> t = mp.getParts();
for (IPart p : t) for (IPart p : t) {
{ if (ret == false) {
if (ret == false) if (p.getType().equals(name)) {
{
if (p.getType().equals(name))
{
ret = true; ret = true;
} }
} }

View file

@ -4,9 +4,6 @@
package techreborn.partSystem.block; package techreborn.partSystem.block;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
@ -24,18 +21,19 @@ import techreborn.partSystem.ICustomHighlight;
import techreborn.partSystem.IModPart; import techreborn.partSystem.IModPart;
import techreborn.partSystem.ModPart; import techreborn.partSystem.ModPart;
import java.util.ArrayList;
import java.util.List;
/** /**
* Created by mark on 10/12/14. * Created by mark on 10/12/14.
*/ */
public class BlockModPart extends BlockContainer implements ICustomHighlight { public class BlockModPart extends BlockContainer implements ICustomHighlight {
public BlockModPart(Material met) public BlockModPart(Material met) {
{
super(met); super(met);
} }
public static TileEntityModPart get(IBlockAccess world, int x, int y, int z) public static TileEntityModPart get(IBlockAccess world, int x, int y, int z) {
{
TileEntity te = world.getTileEntity(x, y, z); TileEntity te = world.getTileEntity(x, y, z);
if (te == null) if (te == null)
@ -46,8 +44,7 @@ public class BlockModPart extends BlockContainer implements ICustomHighlight {
} }
@Override @Override
public TileEntity createNewTileEntity(World world, int i) public TileEntity createNewTileEntity(World world, int i) {
{
return new TileEntityModPart(); return new TileEntityModPart();
} }
@ -55,8 +52,7 @@ public class BlockModPart extends BlockContainer implements ICustomHighlight {
{"rawtypes", "unchecked"}) {"rawtypes", "unchecked"})
@Override @Override
public void addCollisionBoxesToList(World world, int x, int y, int z, public void addCollisionBoxesToList(World world, int x, int y, int z,
AxisAlignedBB bounds, List l, Entity entity) AxisAlignedBB bounds, List l, Entity entity) {
{
TileEntityModPart te = get(world, x, y, z); TileEntityModPart te = get(world, x, y, z);
if (te == null) if (te == null)
return; return;
@ -68,15 +64,13 @@ public class BlockModPart extends BlockContainer implements ICustomHighlight {
} }
@Override @Override
public boolean isOpaqueCube() public boolean isOpaqueCube() {
{
return false; return false;
} }
@Override @Override
public int getRenderType() public int getRenderType() {
{
return -1; return -1;
} }
@ -84,20 +78,17 @@ public class BlockModPart extends BlockContainer implements ICustomHighlight {
@Override @Override
// TODO move to array list // TODO move to array list
public ArrayList<AxisAlignedBB> getBoxes(World world, int x, int y, int z, public ArrayList<AxisAlignedBB> getBoxes(World world, int x, int y, int z,
EntityPlayer player) EntityPlayer player) {
{
TileEntityModPart te = get(world, x, y, z); TileEntityModPart te = get(world, x, y, z);
if (te == null) if (te == null)
return null; return null;
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>(); List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
ArrayList<AxisAlignedBB> list = new ArrayList<AxisAlignedBB>(); ArrayList<AxisAlignedBB> list = new ArrayList<AxisAlignedBB>();
if (!te.getParts().isEmpty()) if (!te.getParts().isEmpty()) {
{
for (ModPart modPart : te.getParts()) for (ModPart modPart : te.getParts())
boxes.addAll(modPart.getSelectionBoxes()); boxes.addAll(modPart.getSelectionBoxes());
for (int i = 0; i < boxes.size(); i++) for (int i = 0; i < boxes.size(); i++) {
{
Vecs3dCube cube = boxes.get(i); Vecs3dCube cube = boxes.get(i);
list.add(cube.toAABB()); list.add(cube.toAABB());
} }
@ -107,39 +98,31 @@ public class BlockModPart extends BlockContainer implements ICustomHighlight {
} }
public void onNeighborBlockChange(World world, int x, int y, int z, public void onNeighborBlockChange(World world, int x, int y, int z,
Block block) Block block) {
{ for (ModPart part : get(world, x, y, z).getParts()) {
for (ModPart part : get(world, x, y, z).getParts())
{
part.nearByChange(); part.nearByChange();
} }
} }
@Override @Override
public MovingObjectPosition collisionRayTrace(World wrd, int x, int y, public MovingObjectPosition collisionRayTrace(World wrd, int x, int y,
int z, Vec3 origin, Vec3 direction) int z, Vec3 origin, Vec3 direction) {
{
ArrayList<AxisAlignedBB> aabbs = getBoxes(wrd, x, y, z, null); ArrayList<AxisAlignedBB> aabbs = getBoxes(wrd, x, y, z, null);
MovingObjectPosition closest = null; MovingObjectPosition closest = null;
for (AxisAlignedBB aabb : aabbs) for (AxisAlignedBB aabb : aabbs) {
{
MovingObjectPosition mop = aabb.getOffsetBoundingBox(x, y, z) MovingObjectPosition mop = aabb.getOffsetBoundingBox(x, y, z)
.calculateIntercept(origin, direction); .calculateIntercept(origin, direction);
if (mop != null) if (mop != null) {
{
if (closest != null if (closest != null
&& mop.hitVec.distanceTo(origin) < closest.hitVec && mop.hitVec.distanceTo(origin) < closest.hitVec
.distanceTo(origin)) .distanceTo(origin)) {
{
closest = mop; closest = mop;
} else } else {
{
closest = mop; closest = mop;
} }
} }
} }
if (closest != null) if (closest != null) {
{
closest.blockX = x; closest.blockX = x;
closest.blockY = y; closest.blockY = y;
closest.blockZ = z; closest.blockZ = z;
@ -148,10 +131,8 @@ public class BlockModPart extends BlockContainer implements ICustomHighlight {
} }
@Override @Override
public void onBlockAdded(World world, int x, int y, int z) public void onBlockAdded(World world, int x, int y, int z) {
{ for (ModPart part : get(world, x, y, z).getParts()) {
for (ModPart part : get(world, x, y, z).getParts())
{
part.onAdded(); part.onAdded();
} }
super.onBlockAdded(world, x, y, z); super.onBlockAdded(world, x, y, z);
@ -159,10 +140,8 @@ public class BlockModPart extends BlockContainer implements ICustomHighlight {
@Override @Override
public void breakBlock(World world, int x, int y, int z, Block oldid, public void breakBlock(World world, int x, int y, int z, Block oldid,
int oldmeta) int oldmeta) {
{ for (ModPart part : get(world, x, y, z).getParts()) {
for (ModPart part : get(world, x, y, z).getParts())
{
part.onRemoved(); part.onRemoved();
} }
super.breakBlock(world, x, y, z, oldid, oldmeta); super.breakBlock(world, x, y, z, oldid, oldmeta);
@ -170,14 +149,11 @@ public class BlockModPart extends BlockContainer implements ICustomHighlight {
@Override @Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, public ArrayList<ItemStack> getDrops(World world, int x, int y, int z,
int metadata, int fortune) int metadata, int fortune) {
{
ArrayList<ItemStack> l = new ArrayList<ItemStack>(); ArrayList<ItemStack> l = new ArrayList<ItemStack>();
TileEntityModPart te = get(world, x, y, z); TileEntityModPart te = get(world, x, y, z);
if (te != null) if (te != null) {
{ for (IModPart p : te.getParts()) {
for (IModPart p : te.getParts())
{
ItemStack item = p.getItem(); ItemStack item = p.getItem();
if (item != null) if (item != null)
l.add(item); l.add(item);

View file

@ -6,24 +6,20 @@ package techreborn.partSystem.block;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import techreborn.lib.vecmath.Vecs3d; import techreborn.lib.vecmath.Vecs3d;
import techreborn.partSystem.ModPart; import techreborn.partSystem.ModPart;
public class RenderModPart extends TileEntitySpecialRenderer { public class RenderModPart extends TileEntitySpecialRenderer {
@Override @Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, public void renderTileEntityAt(TileEntity tileEntity, double x, double y,
double z, float delta) double z, float delta) {
{
TileEntityModPart te = (TileEntityModPart) tileEntity; TileEntityModPart te = (TileEntityModPart) tileEntity;
GL11.glPushMatrix(); GL11.glPushMatrix();
GL11.glTranslated(x, y, z); GL11.glTranslated(x, y, z);
{ {
for (ModPart modPart : te.getParts()) for (ModPart modPart : te.getParts()) {
{
modPart.renderDynamic(new Vecs3d(0, 0, 0), delta); modPart.renderDynamic(new Vecs3d(0, 0, 0), delta);
} }
} }

View file

@ -4,11 +4,6 @@
package techreborn.partSystem.block; package techreborn.partSystem.block;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList; import net.minecraft.nbt.NBTTagList;
@ -24,94 +19,83 @@ import techreborn.partSystem.ModPart;
import techreborn.partSystem.ModPartRegistry; import techreborn.partSystem.ModPartRegistry;
import techreborn.partSystem.parts.NullPart; import techreborn.partSystem.parts.NullPart;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class TileEntityModPart extends TileEntity { public class TileEntityModPart extends TileEntity {
private Map<String, ModPart> parts = new HashMap<String, ModPart>(); private Map<String, ModPart> parts = new HashMap<String, ModPart>();
public void addCollisionBoxesToList(List<Vecs3dCube> l, public void addCollisionBoxesToList(List<Vecs3dCube> l,
AxisAlignedBB bounds, Entity entity) AxisAlignedBB bounds, Entity entity) {
{
if (getParts().size() == 0) if (getParts().size() == 0)
addPart(new NullPart()); addPart(new NullPart());
List<Vecs3dCube> boxes2 = new ArrayList<Vecs3dCube>(); List<Vecs3dCube> boxes2 = new ArrayList<Vecs3dCube>();
for (ModPart mp : getParts()) for (ModPart mp : getParts()) {
{
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>(); List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
mp.addCollisionBoxesToList(boxes, entity); mp.addCollisionBoxesToList(boxes, entity);
for (int i = 0; i < boxes.size(); i++) for (int i = 0; i < boxes.size(); i++) {
{
Vecs3dCube cube = boxes.get(i).clone(); Vecs3dCube cube = boxes.get(i).clone();
cube.add(getX(), getY(), getZ()); cube.add(getX(), getY(), getZ());
boxes2.add(cube); boxes2.add(cube);
} }
} }
for (Vecs3dCube c : boxes2) for (Vecs3dCube c : boxes2) {
{
// if (c.toAABB().intersectsWith(bounds)) // if (c.toAABB().intersectsWith(bounds))
l.add(c); l.add(c);
} }
} }
public List<Vecs3dCube> getOcclusionBoxes() public List<Vecs3dCube> getOcclusionBoxes() {
{
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>(); List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
for (ModPart mp : getParts()) for (ModPart mp : getParts()) {
{
boxes.addAll(mp.getOcclusionBoxes()); boxes.addAll(mp.getOcclusionBoxes());
} }
return boxes; return boxes;
} }
@Override @Override
public AxisAlignedBB getRenderBoundingBox() public AxisAlignedBB getRenderBoundingBox() {
{
return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1, return AxisAlignedBB.getBoundingBox(xCoord, yCoord, zCoord, xCoord + 1,
yCoord + 1, zCoord + 1); yCoord + 1, zCoord + 1);
} }
public World getWorld() public World getWorld() {
{
return getWorldObj(); return getWorldObj();
} }
public int getX() public int getX() {
{
return xCoord; return xCoord;
} }
public int getY() public int getY() {
{
return yCoord; return yCoord;
} }
public int getZ() public int getZ() {
{
return zCoord; return zCoord;
} }
@Override @Override
public void updateEntity() public void updateEntity() {
{ if (parts.isEmpty()) {
if (parts.isEmpty())
{
worldObj.setBlockToAir(xCoord, yCoord, zCoord); worldObj.setBlockToAir(xCoord, yCoord, zCoord);
} }
for (ModPart mp : getParts()) for (ModPart mp : getParts()) {
{ if (mp.world != null && mp.location != null) {
if (mp.world != null && mp.location != null)
{
mp.tick(); mp.tick();
} }
} }
} }
@Override @Override
public void writeToNBT(NBTTagCompound tag) public void writeToNBT(NBTTagCompound tag) {
{
super.writeToNBT(tag); super.writeToNBT(tag);
@ -121,29 +105,23 @@ public class TileEntityModPart extends TileEntity {
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) public void readFromNBT(NBTTagCompound tag) {
{
super.readFromNBT(tag); super.readFromNBT(tag);
NBTTagList l = tag.getTagList("parts", new NBTTagCompound().getId()); NBTTagList l = tag.getTagList("parts", new NBTTagCompound().getId());
try try {
{
readParts(l); readParts(l);
} catch (IllegalAccessException e) } catch (IllegalAccessException e) {
{
e.printStackTrace(); e.printStackTrace();
} catch (InstantiationException e) } catch (InstantiationException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
private void writeParts(NBTTagList l, boolean update) private void writeParts(NBTTagList l, boolean update) {
{
for (ModPart p : getParts()) for (ModPart p : getParts()) {
{
String id = getIdentifier(p); String id = getIdentifier(p);
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
@ -159,21 +137,16 @@ public class TileEntityModPart extends TileEntity {
} }
private void readParts(NBTTagList l) throws IllegalAccessException, private void readParts(NBTTagList l) throws IllegalAccessException,
InstantiationException InstantiationException {
{
for (int i = 0; i < l.tagCount(); i++) for (int i = 0; i < l.tagCount(); i++) {
{
NBTTagCompound tag = l.getCompoundTagAt(i); NBTTagCompound tag = l.getCompoundTagAt(i);
String id = tag.getString("id"); String id = tag.getString("id");
ModPart p = getPart(id); ModPart p = getPart(id);
if (p == null) if (p == null) {
{ for (ModPart modPart : ModPartRegistry.parts) {
for (ModPart modPart : ModPartRegistry.parts) if (modPart.getName().equals(id)) {
{
if (modPart.getName().equals(id))
{
p = modPart.getClass().newInstance(); p = modPart.getClass().newInstance();
} }
} }
@ -187,25 +160,20 @@ public class TileEntityModPart extends TileEntity {
} }
} }
public void addPart(ModPart modPart) public void addPart(ModPart modPart) {
{ try {
try
{
ModPart newPart = modPart.getClass().newInstance(); ModPart newPart = modPart.getClass().newInstance();
newPart.setWorld(getWorldObj()); newPart.setWorld(getWorldObj());
newPart.setLocation(new Location(xCoord, yCoord, zCoord)); newPart.setLocation(new Location(xCoord, yCoord, zCoord));
parts.put(newPart.getName(), newPart); parts.put(newPart.getName(), newPart);
} catch (InstantiationException e) } catch (InstantiationException e) {
{
e.printStackTrace(); e.printStackTrace();
} catch (IllegalAccessException e) } catch (IllegalAccessException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
private ModPart getPart(String id) private ModPart getPart(String id) {
{
for (String s : parts.keySet()) for (String s : parts.keySet())
if (s.equals(id)) if (s.equals(id))
return parts.get(s); return parts.get(s);
@ -213,8 +181,7 @@ public class TileEntityModPart extends TileEntity {
return null; return null;
} }
private String getIdentifier(ModPart part) private String getIdentifier(ModPart part) {
{
for (String s : parts.keySet()) for (String s : parts.keySet())
if (parts.get(s).equals(part)) if (parts.get(s).equals(part))
return s; return s;
@ -223,42 +190,35 @@ public class TileEntityModPart extends TileEntity {
} }
@Override @Override
public Packet getDescriptionPacket() public Packet getDescriptionPacket() {
{
NBTTagCompound tag = new NBTTagCompound(); NBTTagCompound tag = new NBTTagCompound();
writeToNBT(tag); writeToNBT(tag);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, tag); return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 0, tag);
} }
@Override @Override
public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) public void onDataPacket(NetworkManager net, S35PacketUpdateTileEntity pkt) {
{
readFromNBT(pkt.func_148857_g()); readFromNBT(pkt.func_148857_g());
} }
public List<ModPart> getParts() public List<ModPart> getParts() {
{
List<ModPart> parts = new ArrayList<ModPart>(); List<ModPart> parts = new ArrayList<ModPart>();
for (String s : this.parts.keySet()) for (String s : this.parts.keySet()) {
{
ModPart p = this.parts.get(s); ModPart p = this.parts.get(s);
parts.add(p); parts.add(p);
} }
return parts; return parts;
} }
public List<String> getPartsByName() public List<String> getPartsByName() {
{
List<String> parts = new ArrayList<String>(); List<String> parts = new ArrayList<String>();
for (String s : this.parts.keySet()) for (String s : this.parts.keySet()) {
{
parts.add(s); parts.add(s);
} }
return parts; return parts;
} }
public boolean canAddPart(ModPart modpart) public boolean canAddPart(ModPart modpart) {
{
List<Vecs3dCube> cubes = new ArrayList<Vecs3dCube>(); List<Vecs3dCube> cubes = new ArrayList<Vecs3dCube>();
modpart.addCollisionBoxesToList(cubes, null); modpart.addCollisionBoxesToList(cubes, null);
for (Vecs3dCube c : cubes) for (Vecs3dCube c : cubes)

View file

@ -4,6 +4,8 @@
package techreborn.partSystem.block; package techreborn.partSystem.block;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
@ -16,8 +18,6 @@ import techreborn.lib.Location;
import techreborn.lib.vecmath.Vecs3dCube; import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.IPartProvider; import techreborn.partSystem.IPartProvider;
import techreborn.partSystem.ModPart; import techreborn.partSystem.ModPart;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.common.registry.GameRegistry;
/** /**
* Created by mark on 10/12/14. * Created by mark on 10/12/14.
@ -26,14 +26,12 @@ public class WorldProvider implements IPartProvider {
Block blockModPart; Block blockModPart;
@Override @Override
public String modID() public String modID() {
{
return "Minecraft"; return "Minecraft";
} }
@Override @Override
public void registerPart() public void registerPart() {
{
// Loads all of the items // Loads all of the items
blockModPart = new BlockModPart(Material.ground) blockModPart = new BlockModPart(Material.ground)
@ -45,30 +43,24 @@ public class WorldProvider implements IPartProvider {
"TileEntityModPart"); "TileEntityModPart");
} }
public void clientRegister() public void clientRegister() {
{
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityModPart.class, ClientRegistry.bindTileEntitySpecialRenderer(TileEntityModPart.class,
new RenderModPart()); new RenderModPart());
} }
@Override @Override
public boolean checkOcclusion(World world, Location location, public boolean checkOcclusion(World world, Location location,
Vecs3dCube cube) Vecs3dCube cube) {
{
return true; return true;
} }
@Override @Override
public boolean hasPart(World world, Location location, String name) public boolean hasPart(World world, Location location, String name) {
{
TileEntity tileEntity = world.getTileEntity(location.getX(), TileEntity tileEntity = world.getTileEntity(location.getX(),
location.getY(), location.getZ()); location.getY(), location.getZ());
if (tileEntity instanceof TileEntityModPart) if (tileEntity instanceof TileEntityModPart) {
{ for (ModPart part : ((TileEntityModPart) tileEntity).getParts()) {
for (ModPart part : ((TileEntityModPart) tileEntity).getParts()) if (part.getName().equals(name)) {
{
if (part.getName().equals(name))
{
return true; return true;
} }
} }
@ -79,12 +71,10 @@ public class WorldProvider implements IPartProvider {
@Override @Override
public boolean placePart(ItemStack item, EntityPlayer player, World world, public boolean placePart(ItemStack item, EntityPlayer player, World world,
int x, int y, int z, int side, float hitX, float hitY, float hitZ, int x, int y, int z, int side, float hitX, float hitY, float hitZ,
ModPart modPart) ModPart modPart) {
{
ForgeDirection forgeDirection = ForgeDirection.getOrientation(side); ForgeDirection forgeDirection = ForgeDirection.getOrientation(side);
if (world.getBlock(x + forgeDirection.offsetX, y if (world.getBlock(x + forgeDirection.offsetX, y
+ forgeDirection.offsetY, z + forgeDirection.offsetZ) == Blocks.air) + forgeDirection.offsetY, z + forgeDirection.offsetZ) == Blocks.air) {
{
TileEntityModPart modPart1; TileEntityModPart modPart1;
world.setBlock(x + forgeDirection.offsetX, y world.setBlock(x + forgeDirection.offsetX, y
+ forgeDirection.offsetY, z + forgeDirection.offsetZ, + forgeDirection.offsetY, z + forgeDirection.offsetZ,
@ -98,8 +88,7 @@ public class WorldProvider implements IPartProvider {
// } // }
} }
// this adds a part to a block // this adds a part to a block
if (world.getBlock(x, y, z) == blockModPart) if (world.getBlock(x, y, z) == blockModPart) {
{
TileEntityModPart tileEntityModPart = (TileEntityModPart) world TileEntityModPart tileEntityModPart = (TileEntityModPart) world
.getTileEntity(x + forgeDirection.offsetX, y .getTileEntity(x + forgeDirection.offsetX, y
+ forgeDirection.offsetY, z + forgeDirection.offsetY, z
@ -110,8 +99,7 @@ public class WorldProvider implements IPartProvider {
return true; return true;
} }
if (world.getBlock(x + forgeDirection.offsetX, y if (world.getBlock(x + forgeDirection.offsetX, y
+ forgeDirection.offsetY, z + forgeDirection.offsetZ) == blockModPart) + forgeDirection.offsetY, z + forgeDirection.offsetZ) == blockModPart) {
{
TileEntityModPart tileEntityModPart = (TileEntityModPart) world TileEntityModPart tileEntityModPart = (TileEntityModPart) world
.getTileEntity(x + forgeDirection.offsetX, y .getTileEntity(x + forgeDirection.offsetX, y
+ forgeDirection.offsetY, z + forgeDirection.offsetY, z
@ -125,8 +113,7 @@ public class WorldProvider implements IPartProvider {
} }
@Override @Override
public boolean isTileFromProvider(TileEntity tileEntity) public boolean isTileFromProvider(TileEntity tileEntity) {
{
return tileEntity instanceof TileEntityModPart; return tileEntity instanceof TileEntityModPart;
} }
} }

View file

@ -1,5 +1,8 @@
package techreborn.partSystem.client; package techreborn.partSystem.client;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.ScaledResolution; import net.minecraft.client.gui.ScaledResolution;
import net.minecraft.client.renderer.Tessellator; import net.minecraft.client.renderer.Tessellator;
@ -10,16 +13,11 @@ import net.minecraft.util.MovingObjectPosition;
import net.minecraft.util.Vec3; import net.minecraft.util.Vec3;
import net.minecraftforge.client.event.RenderWorldLastEvent; import net.minecraftforge.client.event.RenderWorldLastEvent;
import net.minecraftforge.common.util.ForgeDirection; import net.minecraftforge.common.util.ForgeDirection;
import org.lwjgl.opengl.GL11; import org.lwjgl.opengl.GL11;
import techreborn.lib.Location; import techreborn.lib.Location;
import techreborn.lib.vecmath.Vecs3d; import techreborn.lib.vecmath.Vecs3d;
import techreborn.partSystem.IModPart; import techreborn.partSystem.IModPart;
import techreborn.partSystem.ModPartItem; import techreborn.partSystem.ModPartItem;
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/** /**
* This is based of * This is based of
@ -35,8 +33,7 @@ public class PartPlacementRenderer {
private int width = 0, height = 0; private int width = 0, height = 0;
@SubscribeEvent @SubscribeEvent
public void onRenderTick(RenderWorldLastEvent event) public void onRenderTick(RenderWorldLastEvent event) {
{
EntityPlayer player = Minecraft.getMinecraft().thePlayer; EntityPlayer player = Minecraft.getMinecraft().thePlayer;
ItemStack item = player.getCurrentEquippedItem(); ItemStack item = player.getCurrentEquippedItem();
if (item == null) if (item == null)
@ -57,8 +54,7 @@ public class PartPlacementRenderer {
ForgeDirection faceHit = ForgeDirection.getOrientation(mop.sideHit); ForgeDirection faceHit = ForgeDirection.getOrientation(mop.sideHit);
Location location = new Location(mop.blockX, mop.blockY, mop.blockZ); Location location = new Location(mop.blockX, mop.blockY, mop.blockZ);
if (fb == null || width != Minecraft.getMinecraft().displayWidth if (fb == null || width != Minecraft.getMinecraft().displayWidth
|| height != Minecraft.getMinecraft().displayHeight) || height != Minecraft.getMinecraft().displayHeight) {
{
width = Minecraft.getMinecraft().displayWidth; width = Minecraft.getMinecraft().displayWidth;
height = Minecraft.getMinecraft().displayHeight; height = Minecraft.getMinecraft().displayHeight;
fb = new Framebuffer(width, height, true); fb = new Framebuffer(width, height, true);

View file

@ -4,8 +4,12 @@
package techreborn.partSystem.fmp; package techreborn.partSystem.fmp;
import java.util.List; import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Cuboid6;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.NormallyOccludedPart;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.tileentity.TileEntity;
@ -15,12 +19,8 @@ import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.IPartProvider; import techreborn.partSystem.IPartProvider;
import techreborn.partSystem.ModPart; import techreborn.partSystem.ModPart;
import techreborn.partSystem.ModPartRegistry; import techreborn.partSystem.ModPartRegistry;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Cuboid6; import java.util.List;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.NormallyOccludedPart;
import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
/** /**
* Created by mark on 09/12/14. * Created by mark on 09/12/14.
@ -28,20 +28,14 @@ import codechicken.multipart.TileMultipart;
public class FMPFactory implements MultiPartRegistry.IPartFactory, public class FMPFactory implements MultiPartRegistry.IPartFactory,
IPartProvider { IPartProvider {
@Override @Override
public TMultiPart createPart(String type, boolean client) public TMultiPart createPart(String type, boolean client) {
{ for (ModPart modPart : ModPartRegistry.parts) {
for (ModPart modPart : ModPartRegistry.parts) if (modPart.getName().equals(type)) {
{ try {
if (modPart.getName().equals(type))
{
try
{
return new FMPModPart(modPart.getClass().newInstance()); return new FMPModPart(modPart.getClass().newInstance());
} catch (InstantiationException e) } catch (InstantiationException e) {
{
e.printStackTrace(); e.printStackTrace();
} catch (IllegalAccessException e) } catch (IllegalAccessException e) {
{
e.printStackTrace(); e.printStackTrace();
} }
} }
@ -51,29 +45,24 @@ public class FMPFactory implements MultiPartRegistry.IPartFactory,
public boolean placePart(ItemStack item, EntityPlayer player, World world, public boolean placePart(ItemStack item, EntityPlayer player, World world,
int x, int y, int z, int side, float hitX, float hitY, float hitZ, int x, int y, int z, int side, float hitX, float hitY, float hitZ,
ModPart modPart) ModPart modPart) {
{
return new FakeFMPPlacerItem(modPart).onItemUse(item, player, world, x, return new FakeFMPPlacerItem(modPart).onItemUse(item, player, world, x,
y, z, side, hitX, hitY, hitZ); y, z, side, hitX, hitY, hitZ);
} }
@Override @Override
public boolean isTileFromProvider(TileEntity tileEntity) public boolean isTileFromProvider(TileEntity tileEntity) {
{
return tileEntity instanceof TileMultipart; return tileEntity instanceof TileMultipart;
} }
@Override @Override
public String modID() public String modID() {
{
return "ForgeMultipart"; return "ForgeMultipart";
} }
@Override @Override
public void registerPart() public void registerPart() {
{ for (ModPart modPart : ModPartRegistry.parts) {
for (ModPart modPart : ModPartRegistry.parts)
{
MultiPartRegistry.registerParts(new FMPFactory(), new String[] MultiPartRegistry.registerParts(new FMPFactory(), new String[]
{modPart.getName()}); {modPart.getName()});
} }
@ -81,8 +70,7 @@ public class FMPFactory implements MultiPartRegistry.IPartFactory,
@Override @Override
public boolean checkOcclusion(World world, Location location, public boolean checkOcclusion(World world, Location location,
Vecs3dCube cube) Vecs3dCube cube) {
{
codechicken.multipart.TileMultipart tmp = codechicken.multipart.TileMultipart codechicken.multipart.TileMultipart tmp = codechicken.multipart.TileMultipart
.getOrConvertTile(world, new BlockCoord(location.getX(), .getOrConvertTile(world, new BlockCoord(location.getX(),
location.getY(), location.getZ())); location.getY(), location.getZ()));
@ -93,21 +81,16 @@ public class FMPFactory implements MultiPartRegistry.IPartFactory,
} }
@Override @Override
public boolean hasPart(World world, Location location, String name) public boolean hasPart(World world, Location location, String name) {
{
TileEntity tileEntity = world.getTileEntity(location.getX(), TileEntity tileEntity = world.getTileEntity(location.getX(),
location.getY(), location.getZ()); location.getY(), location.getZ());
if (tileEntity instanceof TileMultipart) if (tileEntity instanceof TileMultipart) {
{
TileMultipart mp = (TileMultipart) tileEntity; TileMultipart mp = (TileMultipart) tileEntity;
boolean ret = false; boolean ret = false;
List<TMultiPart> t = mp.jPartList(); List<TMultiPart> t = mp.jPartList();
for (TMultiPart p : t) for (TMultiPart p : t) {
{ if (ret == false) {
if (ret == false) if (p.getType().equals(name)) {
{
if (p.getType().equals(name))
{
ret = true; ret = true;
} }
} }

View file

@ -4,17 +4,6 @@
package techreborn.partSystem.fmp; package techreborn.partSystem.fmp;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World;
import techreborn.lib.Location;
import techreborn.lib.vecmath.Vecs3d;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.ModPart;
import codechicken.lib.raytracer.IndexedCuboid6; import codechicken.lib.raytracer.IndexedCuboid6;
import codechicken.lib.vec.Cuboid6; import codechicken.lib.vec.Cuboid6;
import codechicken.lib.vec.Vector3; import codechicken.lib.vec.Vector3;
@ -25,7 +14,6 @@ import codechicken.multipart.TMultiPart;
import codechicken.multipart.TSlottedPart; import codechicken.multipart.TSlottedPart;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.util.AxisAlignedBB; import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -35,26 +23,26 @@ import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.ModPart; import techreborn.partSystem.ModPart;
import uk.co.qmunity.lib.client.render.RenderHelper; import uk.co.qmunity.lib.client.render.RenderHelper;
import java.util.ArrayList;
import java.util.List;
public class FMPModPart extends TMultiPart implements TSlottedPart, public class FMPModPart extends TMultiPart implements TSlottedPart,
JNormalOcclusion, ISidedHollowConnect { JNormalOcclusion, ISidedHollowConnect {
ModPart iModPart; ModPart iModPart;
public FMPModPart(ModPart iModPart) public FMPModPart(ModPart iModPart) {
{
this.iModPart = iModPart; this.iModPart = iModPart;
} }
@Override @Override
public int getHollowSize(int i) public int getHollowSize(int i) {
{
return 0; return 0;
} }
@Override @Override
public Iterable<Cuboid6> getOcclusionBoxes() public Iterable<Cuboid6> getOcclusionBoxes() {
{
List<Cuboid6> cubes = new ArrayList<Cuboid6>(); List<Cuboid6> cubes = new ArrayList<Cuboid6>();
for (Vecs3dCube c : iModPart.getOcclusionBoxes()) for (Vecs3dCube c : iModPart.getOcclusionBoxes())
cubes.add(new Cuboid6(c.toAABB())); cubes.add(new Cuboid6(c.toAABB()));
@ -62,40 +50,34 @@ public class FMPModPart extends TMultiPart implements TSlottedPart,
} }
@Override @Override
public boolean occlusionTest(TMultiPart npart) public boolean occlusionTest(TMultiPart npart) {
{
return NormalOcclusionTest.apply(this, npart); return NormalOcclusionTest.apply(this, npart);
} }
public void addCollisionBoxesToList(List<Vecs3dCube> l, public void addCollisionBoxesToList(List<Vecs3dCube> l,
AxisAlignedBB bounds, Entity entity) AxisAlignedBB bounds, Entity entity) {
{
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>(); List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
List<Vecs3dCube> boxes_ = new ArrayList<Vecs3dCube>(); List<Vecs3dCube> boxes_ = new ArrayList<Vecs3dCube>();
iModPart.addCollisionBoxesToList(boxes_, entity); iModPart.addCollisionBoxesToList(boxes_, entity);
for (Vecs3dCube c : boxes_) for (Vecs3dCube c : boxes_) {
{
Vecs3dCube cube = c.clone(); Vecs3dCube cube = c.clone();
cube.add(getX(), getY(), getZ()); cube.add(getX(), getY(), getZ());
boxes.add(cube); boxes.add(cube);
} }
boxes_.clear(); boxes_.clear();
for (Vecs3dCube c : boxes) for (Vecs3dCube c : boxes) {
{
if (c.toAABB().intersectsWith(bounds)) if (c.toAABB().intersectsWith(bounds))
l.add(c); l.add(c);
} }
} }
@Override @Override
public Iterable<Cuboid6> getCollisionBoxes() public Iterable<Cuboid6> getCollisionBoxes() {
{
List<Cuboid6> cubes = new ArrayList<Cuboid6>(); List<Cuboid6> cubes = new ArrayList<Cuboid6>();
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>(); List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
iModPart.addCollisionBoxesToList(boxes, null); iModPart.addCollisionBoxesToList(boxes, null);
for (Vecs3dCube c : boxes) for (Vecs3dCube c : boxes) {
{
if (c != null) if (c != null)
cubes.add(new Cuboid6(c.toAABB())); cubes.add(new Cuboid6(c.toAABB()));
} }
@ -104,11 +86,9 @@ public class FMPModPart extends TMultiPart implements TSlottedPart,
} }
@Override @Override
public Iterable<IndexedCuboid6> getSubParts() public Iterable<IndexedCuboid6> getSubParts() {
{
List<IndexedCuboid6> cubes = new ArrayList<IndexedCuboid6>(); List<IndexedCuboid6> cubes = new ArrayList<IndexedCuboid6>();
if (iModPart.getSelectionBoxes() != null) if (iModPart.getSelectionBoxes() != null) {
{
for (Vecs3dCube c : iModPart.getSelectionBoxes()) for (Vecs3dCube c : iModPart.getSelectionBoxes())
if (c != null) if (c != null)
cubes.add(new IndexedCuboid6(0, new Cuboid6(c.toAABB()))); cubes.add(new IndexedCuboid6(0, new Cuboid6(c.toAABB())));
@ -122,52 +102,42 @@ public class FMPModPart extends TMultiPart implements TSlottedPart,
@Override @Override
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void renderDynamic(Vector3 pos, float frame, int pass) public void renderDynamic(Vector3 pos, float frame, int pass) {
{
iModPart.renderDynamic(new Vecs3d(pos.x, pos.y, pos.z), frame); iModPart.renderDynamic(new Vecs3d(pos.x, pos.y, pos.z), frame);
} }
@Override @Override
public String getType() public String getType() {
{
return iModPart.getName(); return iModPart.getName();
} }
@Override @Override
public int getSlotMask() public int getSlotMask() {
{
return 0; return 0;
} }
public World getWorld() public World getWorld() {
{
return world(); return world();
} }
public int getX() public int getX() {
{ if (iModPart.world == null || iModPart.location == null) {
if (iModPart.world == null || iModPart.location == null)
{
iModPart.setWorld(world()); iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z())); iModPart.setLocation(new Location(x(), y(), z()));
} }
return x(); return x();
} }
public int getY() public int getY() {
{ if (iModPart.world == null || iModPart.location == null) {
if (iModPart.world == null || iModPart.location == null)
{
iModPart.setWorld(world()); iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z())); iModPart.setLocation(new Location(x(), y(), z()));
} }
return y(); return y();
} }
public int getZ() public int getZ() {
{ if (iModPart.world == null || iModPart.location == null) {
if (iModPart.world == null || iModPart.location == null)
{
iModPart.setWorld(world()); iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z())); iModPart.setLocation(new Location(x(), y(), z()));
} }
@ -175,8 +145,7 @@ public class FMPModPart extends TMultiPart implements TSlottedPart,
} }
@Override @Override
public void onAdded() public void onAdded() {
{
iModPart.setWorld(world()); iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z())); iModPart.setLocation(new Location(x(), y(), z()));
iModPart.nearByChange(); iModPart.nearByChange();
@ -184,35 +153,29 @@ public class FMPModPart extends TMultiPart implements TSlottedPart,
} }
@Override @Override
public void update() public void update() {
{ if (iModPart.location != null) {
if (iModPart.location != null)
{
iModPart.tick(); iModPart.tick();
} }
} }
@Override @Override
public void onNeighborChanged() public void onNeighborChanged() {
{
super.onNeighborChanged(); super.onNeighborChanged();
if (iModPart.world == null || iModPart.location == null) if (iModPart.world == null || iModPart.location == null) {
{
iModPart.setWorld(world()); iModPart.setWorld(world());
iModPart.setLocation(new Location(x(), y(), z())); iModPart.setLocation(new Location(x(), y(), z()));
} }
iModPart.nearByChange(); iModPart.nearByChange();
} }
public void onRemoved() public void onRemoved() {
{
iModPart.onRemoved(); iModPart.onRemoved();
super.onRemoved(); super.onRemoved();
} }
@Override @Override
public boolean renderStatic(Vector3 pos, int pass) public boolean renderStatic(Vector3 pos, int pass) {
{
boolean render = false; boolean render = false;
render = iModPart.renderStatic(new Vecs3d(pos.x, pos.y, pos.z), uk.co.qmunity.lib.client.render.RenderHelper.instance, pass); render = iModPart.renderStatic(new Vecs3d(pos.x, pos.y, pos.z), uk.co.qmunity.lib.client.render.RenderHelper.instance, pass);
RenderHelper.instance.resetRenderedSides(); RenderHelper.instance.resetRenderedSides();

View file

@ -4,15 +4,15 @@
package techreborn.partSystem.fmp; package techreborn.partSystem.fmp;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import techreborn.partSystem.ModPart;
import codechicken.lib.vec.BlockCoord; import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Vector3; import codechicken.lib.vec.Vector3;
import codechicken.multipart.JItemMultiPart; import codechicken.multipart.JItemMultiPart;
import codechicken.multipart.MultiPartRegistry; import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.TMultiPart; import codechicken.multipart.TMultiPart;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import techreborn.partSystem.ModPart;
/** /**
* This item is never added into the game, it is only used to add the part to * This item is never added into the game, it is only used to add the part to
@ -21,15 +21,13 @@ import codechicken.multipart.TMultiPart;
public class FakeFMPPlacerItem extends JItemMultiPart { public class FakeFMPPlacerItem extends JItemMultiPart {
ModPart modPart; ModPart modPart;
public FakeFMPPlacerItem(ModPart part) public FakeFMPPlacerItem(ModPart part) {
{
modPart = part; modPart = part;
} }
@Override @Override
public TMultiPart newPart(ItemStack item, EntityPlayer player, World world, public TMultiPart newPart(ItemStack item, EntityPlayer player, World world,
BlockCoord pos, int side, Vector3 vhit) BlockCoord pos, int side, Vector3 vhit) {
{
TMultiPart w = MultiPartRegistry.createPart(modPart.getName(), false); TMultiPart w = MultiPartRegistry.createPart(modPart.getName(), false);
return w; return w;
} }

View file

@ -36,8 +36,7 @@ public class CablePart extends ModPart implements IEnergyConductor {
private boolean[] connections = new boolean[6]; private boolean[] connections = new boolean[6];
public boolean addedToEnergyNet = false; public boolean addedToEnergyNet = false;
public static void refreshBounding() public static void refreshBounding() {
{
float centerFirst = center - offset; float centerFirst = center - offset;
double w = 0.2D / 2; double w = 0.2D / 2;
boundingBoxes[6] = new Vecs3dCube(centerFirst - w - 0.03, centerFirst boundingBoxes[6] = new Vecs3dCube(centerFirst - w - 0.03, centerFirst
@ -49,8 +48,7 @@ public class CablePart extends ModPart implements IEnergyConductor {
+ w); + w);
int i = 0; int i = 0;
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
{
double xMin1 = (dir.offsetX < 0 ? 0.0 double xMin1 = (dir.offsetX < 0 ? 0.0
: (dir.offsetX == 0 ? centerFirst - w : centerFirst + w)); : (dir.offsetX == 0 ? centerFirst - w : centerFirst + w));
double xMax1 = (dir.offsetX > 0 ? 1.0 double xMax1 = (dir.offsetX > 0 ? 1.0
@ -73,18 +71,14 @@ public class CablePart extends ModPart implements IEnergyConductor {
} }
@Override @Override
public void addCollisionBoxesToList(List<Vecs3dCube> boxes, Entity entity) public void addCollisionBoxesToList(List<Vecs3dCube> boxes, Entity entity) {
{ if (world != null || location != null) {
if (world != null || location != null)
{
checkConnectedSides(); checkConnectedSides();
} else } else {
{
connectedSides = new HashMap<ForgeDirection, TileEntity>(); connectedSides = new HashMap<ForgeDirection, TileEntity>();
} }
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
{
if (connectedSides.containsKey(dir)) if (connectedSides.containsKey(dir))
boxes.add(boundingBoxes[Functions.getIntDirFromDirection(dir)]); boxes.add(boundingBoxes[Functions.getIntDirFromDirection(dir)]);
} }
@ -92,12 +86,10 @@ public class CablePart extends ModPart implements IEnergyConductor {
} }
@Override @Override
public List<Vecs3dCube> getSelectionBoxes() public List<Vecs3dCube> getSelectionBoxes() {
{
List<Vecs3dCube> vec3dCubeList = new ArrayList<Vecs3dCube>(); List<Vecs3dCube> vec3dCubeList = new ArrayList<Vecs3dCube>();
checkConnectedSides(); checkConnectedSides();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
{
if (connectedSides.containsKey(dir)) if (connectedSides.containsKey(dir))
vec3dCubeList.add(boundingBoxes[Functions vec3dCubeList.add(boundingBoxes[Functions
.getIntDirFromDirection(dir)]); .getIntDirFromDirection(dir)]);
@ -107,13 +99,11 @@ public class CablePart extends ModPart implements IEnergyConductor {
} }
@Override @Override
public List<Vecs3dCube> getOcclusionBoxes() public List<Vecs3dCube> getOcclusionBoxes() {
{
checkConnectedSides(); checkConnectedSides();
List<Vecs3dCube> vecs3dCubesList = new ArrayList<Vecs3dCube>(); List<Vecs3dCube> vecs3dCubesList = new ArrayList<Vecs3dCube>();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
{
if (connectedSides.containsKey(dir)) if (connectedSides.containsKey(dir))
vecs3dCubesList.add(boundingBoxes[Functions vecs3dCubesList.add(boundingBoxes[Functions
.getIntDirFromDirection(dir)]); .getIntDirFromDirection(dir)]);
@ -122,8 +112,7 @@ public class CablePart extends ModPart implements IEnergyConductor {
} }
@Override @Override
public void renderDynamic(Vecs3d translation, double delta) public void renderDynamic(Vecs3d translation, double delta) {
{
} }
@ -141,46 +130,37 @@ public class CablePart extends ModPart implements IEnergyConductor {
} }
@Override @Override
public void writeToNBT(NBTTagCompound tag) public void writeToNBT(NBTTagCompound tag) {
{
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) public void readFromNBT(NBTTagCompound tag) {
{
} }
@Override @Override
public String getName() public String getName() {
{
return "Cable"; return "Cable";
} }
@Override @Override
public String getItemTextureName() public String getItemTextureName() {
{
return "network:networkCable"; return "network:networkCable";
} }
@Override @Override
public void tick() public void tick() {
{ if (ticks == 0) {
if (ticks == 0)
{
checkConnectedSides(); checkConnectedSides();
ticks += 1; ticks += 1;
} else if (ticks == 40) } else if (ticks == 40) {
{
ticks = 0; ticks = 0;
} else } else {
{
ticks += 1; ticks += 1;
} }
if (IC2.platform.isSimulating()) if (IC2.platform.isSimulating()) {
{
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this)); MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
this.addedToEnergyNet = true; this.addedToEnergyNet = true;
checkConnectedSides(); checkConnectedSides();
@ -189,8 +169,7 @@ public class CablePart extends ModPart implements IEnergyConductor {
} }
@Override @Override
public void nearByChange() public void nearByChange() {
{
checkConnectedSides(); checkConnectedSides();
} }
@ -200,51 +179,40 @@ public class CablePart extends ModPart implements IEnergyConductor {
} }
@Override @Override
public void onRemoved() public void onRemoved() {
{ if (IC2.platform.isSimulating() && this.addedToEnergyNet) {
if (IC2.platform.isSimulating() && this.addedToEnergyNet)
{
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this)); MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
this.addedToEnergyNet = false; this.addedToEnergyNet = false;
} }
} }
@Override @Override
public ItemStack getItem() public ItemStack getItem() {
{
return new ItemStack(ModPartUtils.getItemForPart(getName())); return new ItemStack(ModPartUtils.getItemForPart(getName()));
} }
public boolean shouldConnectTo(TileEntity entity, ForgeDirection dir) public boolean shouldConnectTo(TileEntity entity, ForgeDirection dir) {
{ if (entity == null) {
if (entity == null)
{
return false; return false;
} else if (entity instanceof IEnergyTile) } else if (entity instanceof IEnergyTile) {
{
return true; return true;
} else } else {
{
return ModPartUtils.hasPart(entity.getWorldObj(), entity.xCoord, return ModPartUtils.hasPart(entity.getWorldObj(), entity.xCoord,
entity.yCoord, entity.zCoord, this.getName()); entity.yCoord, entity.zCoord, this.getName());
} }
} }
public void checkConnectedSides() public void checkConnectedSides() {
{
refreshBounding(); refreshBounding();
connectedSides = new HashMap<ForgeDirection, TileEntity>(); connectedSides = new HashMap<ForgeDirection, TileEntity>();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
{
int d = Functions.getIntDirFromDirection(dir); int d = Functions.getIntDirFromDirection(dir);
if (world == null) if (world == null) {
{
return; return;
} }
TileEntity te = world.getTileEntity(getX() + dir.offsetX, getY() TileEntity te = world.getTileEntity(getX() + dir.offsetX, getY()
+ dir.offsetY, getZ() + dir.offsetZ); + dir.offsetY, getZ() + dir.offsetZ);
if (shouldConnectTo(te, dir)) if (shouldConnectTo(te, dir)) {
{
// TODO if (ModPartUtils.checkOcclusion(getWorld(), getX(), // TODO if (ModPartUtils.checkOcclusion(getWorld(), getX(),
// getY(), getZ(), boundingBoxes[d])) { // getY(), getZ(), boundingBoxes[d])) {
connectedSides.put(dir, te); connectedSides.put(dir, te);
@ -255,10 +223,8 @@ public class CablePart extends ModPart implements IEnergyConductor {
getWorld().markBlockForUpdate(getX(), getY(), getZ()); getWorld().markBlockForUpdate(getX(), getY(), getZ());
} }
public void checkConnections(World world, int x, int y, int z) public void checkConnections(World world, int x, int y, int z) {
{ for (int i = 0; i < 6; i++) {
for (int i = 0; i < 6; i++)
{
ForgeDirection dir = dirs[i]; ForgeDirection dir = dirs[i];
int dx = x + dir.offsetX; int dx = x + dir.offsetX;
int dy = y + dir.offsetY; int dy = y + dir.offsetY;
@ -271,52 +237,44 @@ public class CablePart extends ModPart implements IEnergyConductor {
} }
@Override @Override
public double getConductionLoss() public double getConductionLoss() {
{
return 0D; return 0D;
} }
@Override @Override
public double getInsulationEnergyAbsorption() public double getInsulationEnergyAbsorption() {
{
return 256; return 256;
} }
@Override @Override
public double getInsulationBreakdownEnergy() public double getInsulationBreakdownEnergy() {
{
return 2048; return 2048;
} }
@Override @Override
public double getConductorBreakdownEnergy() public double getConductorBreakdownEnergy() {
{
return 2048; return 2048;
} }
@Override @Override
public void removeInsulation() public void removeInsulation() {
{
} }
@Override @Override
public void removeConductor() public void removeConductor() {
{
} }
@Override @Override
public boolean acceptsEnergyFrom(TileEntity tileEntity, public boolean acceptsEnergyFrom(TileEntity tileEntity,
ForgeDirection forgeDirection) ForgeDirection forgeDirection) {
{
return true; return true;
} }
@Override @Override
public boolean emitsEnergyTo(TileEntity tileEntity, public boolean emitsEnergyTo(TileEntity tileEntity,
ForgeDirection forgeDirection) ForgeDirection forgeDirection) {
{
return true; return true;
} }
} }

View file

@ -4,10 +4,6 @@
package techreborn.partSystem.parts; package techreborn.partSystem.parts;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -16,33 +12,32 @@ import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.ModPart; import techreborn.partSystem.ModPart;
import uk.co.qmunity.lib.client.render.RenderHelper; import uk.co.qmunity.lib.client.render.RenderHelper;
import java.util.ArrayList;
import java.util.List;
/** /**
* Created by mark on 11/12/14. * Created by mark on 11/12/14.
*/ */
public class NullPart extends ModPart { public class NullPart extends ModPart {
@Override @Override
public void addCollisionBoxesToList(List<Vecs3dCube> boxes, Entity entity) public void addCollisionBoxesToList(List<Vecs3dCube> boxes, Entity entity) {
{
boxes.add(new Vecs3dCube(0, 0, 0, 1, 1, 1)); boxes.add(new Vecs3dCube(0, 0, 0, 1, 1, 1));
} }
@Override @Override
public List<Vecs3dCube> getSelectionBoxes() public List<Vecs3dCube> getSelectionBoxes() {
{
List<Vecs3dCube> cubes = new ArrayList<Vecs3dCube>(); List<Vecs3dCube> cubes = new ArrayList<Vecs3dCube>();
cubes.add(new Vecs3dCube(0, 0, 0, 1, 1, 1)); cubes.add(new Vecs3dCube(0, 0, 0, 1, 1, 1));
return cubes; return cubes;
} }
@Override @Override
public List<Vecs3dCube> getOcclusionBoxes() public List<Vecs3dCube> getOcclusionBoxes() {
{
return null; return null;
} }
@Override @Override
public void renderDynamic(Vecs3d translation, double delta) public void renderDynamic(Vecs3d translation, double delta) {
{
} }
@ -52,56 +47,47 @@ public class NullPart extends ModPart {
} }
@Override @Override
public void writeToNBT(NBTTagCompound tag) public void writeToNBT(NBTTagCompound tag) {
{
} }
@Override @Override
public void readFromNBT(NBTTagCompound tag) public void readFromNBT(NBTTagCompound tag) {
{
} }
@Override @Override
public ItemStack getItem() public ItemStack getItem() {
{
return null; return null;
} }
@Override @Override
public String getName() public String getName() {
{
return "NullPart"; return "NullPart";
} }
@Override @Override
public String getItemTextureName() public String getItemTextureName() {
{
return ""; return "";
} }
@Override @Override
public void tick() public void tick() {
{
} }
@Override @Override
public void nearByChange() public void nearByChange() {
{
} }
@Override @Override
public void onAdded() public void onAdded() {
{
} }
@Override @Override
public void onRemoved() public void onRemoved() {
{
} }
} }