Removed old ones, and added new ones :)
This commit is contained in:
parent
5164301ffb
commit
41795ef16d
9 changed files with 213 additions and 171 deletions
|
@ -53,7 +53,7 @@ public class ModPartUtils {
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public static boolean hasPart(World world, int x, int y, int z, String name) {
|
||||
return hasPart(world, new Location(x, y, z), name);
|
||||
|
|
|
@ -111,12 +111,10 @@ public class QModPart extends PartBase implements IPartCollidable, IPartSelectab
|
|||
|
||||
@Override
|
||||
public void onAdded() {
|
||||
if (iModPart.world == null || iModPart.location == null) {
|
||||
iModPart.setWorld(getWorld());
|
||||
iModPart.setLocation(new Location(getX(), getY(), getZ()));
|
||||
if(iModPart.location != null){
|
||||
iModPart.nearByChange();
|
||||
iModPart.onAdded();
|
||||
}
|
||||
iModPart.nearByChange();
|
||||
iModPart.onAdded();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,190 @@
|
|||
package me.modmuss50.network.partSystem.parts;
|
||||
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
import ic2.core.block.wiring.RenderBlockCable;
|
||||
import me.modmuss50.mods.lib.Functions;
|
||||
import me.modmuss50.mods.lib.vecmath.Vecs3d;
|
||||
import me.modmuss50.mods.lib.vecmath.Vecs3dCube;
|
||||
import me.modmuss50.network.partSystem.ModPart;
|
||||
import me.modmuss50.network.partSystem.ModPartUtils;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
|
||||
public class CablePart extends ModPart {
|
||||
public static Vecs3dCube[] boundingBoxes = new Vecs3dCube[14];
|
||||
public static float center = 0.6F;
|
||||
public static float offset = 0.10F;
|
||||
public Map<ForgeDirection, TileEntity> connectedSides;
|
||||
public int ticks = 0;
|
||||
protected ForgeDirection[] dirs = ForgeDirection.values();
|
||||
private boolean[] connections = new boolean[6];
|
||||
|
||||
public static void
|
||||
refreshBounding() {
|
||||
float centerFirst = center - offset;
|
||||
double w = 0.2D / 2;
|
||||
boundingBoxes[6] = new Vecs3dCube(centerFirst - w - 0.03, centerFirst - w - 0.08, centerFirst - w - 0.03, centerFirst + w + 0.08, centerFirst + w + 0.04, centerFirst + w + 0.08);
|
||||
|
||||
boundingBoxes[6] = new Vecs3dCube(centerFirst - w, centerFirst - w, centerFirst - w, centerFirst + w, centerFirst + w, centerFirst + w);
|
||||
|
||||
int i = 0;
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
double xMin1 = (dir.offsetX < 0 ? 0.0 : (dir.offsetX == 0 ? centerFirst - w : centerFirst + w));
|
||||
double xMax1 = (dir.offsetX > 0 ? 1.0 : (dir.offsetX == 0 ? centerFirst + w : centerFirst - w));
|
||||
|
||||
double yMin1 = (dir.offsetY < 0 ? 0.0 : (dir.offsetY == 0 ? centerFirst - w : centerFirst + w));
|
||||
double yMax1 = (dir.offsetY > 0 ? 1.0 : (dir.offsetY == 0 ? centerFirst + w : centerFirst - w));
|
||||
|
||||
double zMin1 = (dir.offsetZ < 0 ? 0.0 : (dir.offsetZ == 0 ? centerFirst - w : centerFirst + w));
|
||||
double zMax1 = (dir.offsetZ > 0 ? 1.0 : (dir.offsetZ == 0 ? centerFirst + w : centerFirst - w));
|
||||
|
||||
boundingBoxes[i] = new Vecs3dCube(xMin1, yMin1, zMin1, xMax1, yMax1, zMax1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCollisionBoxesToList(List<Vecs3dCube> boxes, Entity entity) {
|
||||
if (world != null || location != null) {
|
||||
checkConnectedSides();
|
||||
} else {
|
||||
connectedSides = new HashMap<ForgeDirection, TileEntity>();
|
||||
}
|
||||
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (connectedSides.containsKey(dir))
|
||||
boxes.add(boundingBoxes[Functions.getIntDirFromDirection(dir)]);
|
||||
}
|
||||
boxes.add(boundingBoxes[6]);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Vecs3dCube> getSelectionBoxes() {
|
||||
List<Vecs3dCube> vec3dCubeList = new ArrayList<Vecs3dCube>();
|
||||
checkConnectedSides();
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (connectedSides.containsKey(dir))
|
||||
vec3dCubeList.add(boundingBoxes[Functions.getIntDirFromDirection(dir)]);
|
||||
}
|
||||
vec3dCubeList.add(boundingBoxes[6]);
|
||||
return vec3dCubeList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Vecs3dCube> getOcclusionBoxes() {
|
||||
checkConnectedSides();
|
||||
List<Vecs3dCube> vecs3dCubesList = new ArrayList<Vecs3dCube>();
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
if (connectedSides.containsKey(dir))
|
||||
vecs3dCubesList.add(boundingBoxes[Functions.getIntDirFromDirection(dir)]);
|
||||
}
|
||||
return vecs3dCubesList;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderDynamic(Vecs3d translation, double delta) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound tag) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getName() {
|
||||
return "Cable";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getItemTextureName() {
|
||||
return "network:networkCable";
|
||||
}
|
||||
|
||||
@Override
|
||||
public void tick() {
|
||||
if (ticks == 0) {
|
||||
checkConnectedSides();
|
||||
ticks += 1;
|
||||
} else if (ticks == 40) {
|
||||
ticks = 0;
|
||||
} else {
|
||||
ticks += 1;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void nearByChange() {
|
||||
checkConnectedSides();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdded() {
|
||||
checkConnections(world, getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoved() {
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getItem() {
|
||||
return new ItemStack(ModPartUtils.getItemForPart(getName()));
|
||||
}
|
||||
|
||||
public boolean shouldConnectTo(TileEntity entity, ForgeDirection dir) {
|
||||
if (entity == null) {
|
||||
return false;
|
||||
} else if (entity instanceof IEnergyTile) {
|
||||
return true;
|
||||
} else {
|
||||
return ModPartUtils.hasPart(entity.getWorldObj(), entity.xCoord, entity.yCoord, entity.zCoord, this.getName());
|
||||
}
|
||||
}
|
||||
|
||||
public void checkConnectedSides() {
|
||||
refreshBounding();
|
||||
connectedSides = new HashMap<ForgeDirection, TileEntity>();
|
||||
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
|
||||
int d = Functions.getIntDirFromDirection(dir);
|
||||
if (world == null) {
|
||||
return;
|
||||
}
|
||||
TileEntity te = world.getTileEntity(getX() + dir.offsetX, getY() + dir.offsetY, getZ() + dir.offsetZ);
|
||||
if (shouldConnectTo(te, dir)) {
|
||||
//TODO if (ModPartUtils.checkOcclusion(getWorld(), getX(), getY(), getZ(), boundingBoxes[d])) {
|
||||
connectedSides.put(dir, te);
|
||||
// }
|
||||
}
|
||||
}
|
||||
checkConnections(world, getX(), getY(), getZ());
|
||||
getWorld().markBlockForUpdate(getX(), getY(), getZ());
|
||||
}
|
||||
|
||||
public void checkConnections(World world, int x, int y, int z) {
|
||||
for (int i = 0; i < 6; i++) {
|
||||
ForgeDirection dir = dirs[i];
|
||||
int dx = x + dir.offsetX;
|
||||
int dy = y + dir.offsetY;
|
||||
int dz = z + dir.offsetZ;
|
||||
connections[i] = shouldConnectTo(world.getTileEntity(dx, dy, dz), dir);
|
||||
world.func_147479_m(dx, dy, dz);
|
||||
}
|
||||
world.func_147479_m(x, y, z);
|
||||
}
|
||||
}
|
|
@ -17,6 +17,7 @@ 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;
|
||||
|
@ -48,6 +49,8 @@ public class Core {
|
|||
ModBlocks.init();
|
||||
//Register ModItems
|
||||
ModItems.init();
|
||||
//Register Multiparts
|
||||
ModParts.init();
|
||||
// Recipes
|
||||
ModRecipes.init();
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@ package techreborn.compat;
|
|||
|
||||
import cpw.mods.fml.common.Loader;
|
||||
import cpw.mods.fml.common.event.FMLInitializationEvent;
|
||||
import techreborn.compat.fmp.FMPFactory;
|
||||
import techreborn.compat.waila.CompatModuleWaila;
|
||||
|
||||
public class CompatManager {
|
||||
|
@ -13,8 +12,5 @@ public class CompatManager {
|
|||
{
|
||||
new CompatModuleWaila().init(event);
|
||||
}
|
||||
if(Loader.isModLoaded("ForgeMultipart")){
|
||||
FMPFactory.init();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,117 +0,0 @@
|
|||
package techreborn.compat.fmp;
|
||||
|
||||
import codechicken.lib.vec.Cuboid6;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.multipart.JNormalOcclusion;
|
||||
import codechicken.multipart.NormalOcclusionTest;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
import ic2.api.energy.event.EnergyTileLoadEvent;
|
||||
import ic2.api.energy.event.EnergyTileUnloadEvent;
|
||||
import ic2.api.energy.tile.IEnergyConductor;
|
||||
import ic2.api.energy.tile.IEnergyTile;
|
||||
import ic2.core.IC2;
|
||||
import ic2.core.ITickCallback;
|
||||
import ic2.core.block.wiring.TileEntityCable;
|
||||
import ic2.core.block.wiring.TileEntityLuminator;
|
||||
import ic2.core.network.NetworkManager;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class CablePart extends TMultiPart implements IEnergyConductor, JNormalOcclusion {
|
||||
|
||||
public boolean addedToEnergyNet = false;
|
||||
|
||||
@Override
|
||||
public String getType() {
|
||||
return "TRCable";
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getConductionLoss() {
|
||||
return 1D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getInsulationEnergyAbsorption() {
|
||||
return 2048;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getInsulationBreakdownEnergy() {
|
||||
return 9001.0D;
|
||||
}
|
||||
|
||||
@Override
|
||||
public double getConductorBreakdownEnergy() {
|
||||
return 2048;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeInsulation() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void removeConductor() {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean acceptsEnergyFrom(TileEntity te, ForgeDirection forgeDirection) {
|
||||
return canInteractWith(te);
|
||||
}
|
||||
|
||||
public boolean canInteractWith(TileEntity te) {
|
||||
return !(te instanceof IEnergyTile)?false:(te instanceof TileEntityLuminator?((TileEntityLuminator)te).canCableConnectFrom(this.x(), this.y(), this.z()):true);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean emitsEnergyTo(TileEntity tileEntity, ForgeDirection forgeDirection) {
|
||||
return canInteractWith(tileEntity);
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
super.update();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkUnload() {
|
||||
if(IC2.platform.isSimulating() && this.addedToEnergyNet) {
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
|
||||
this.addedToEnergyNet = false;
|
||||
}
|
||||
super.onChunkUnload();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onChunkLoad() {
|
||||
super.onChunkLoad();
|
||||
if(IC2.platform.isSimulating()) {
|
||||
|
||||
MinecraftForge.EVENT_BUS.post(new EnergyTileLoadEvent(this));
|
||||
this.addedToEnergyNet = true;
|
||||
this.onNeighborChanged();
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean occlusionTest(TMultiPart npart) {
|
||||
return NormalOcclusionTest.apply(this, npart);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Iterable<Cuboid6> getOcclusionBoxes() {
|
||||
List<Cuboid6> cubes = new ArrayList<Cuboid6>();
|
||||
cubes.add(new Cuboid6(0, 0, 0, 1, 1, 1));
|
||||
return cubes;
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -1,27 +0,0 @@
|
|||
package techreborn.compat.fmp;
|
||||
|
||||
import codechicken.multipart.MultiPartRegistry;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import net.minecraft.item.Item;
|
||||
import techreborn.client.TechRebornCreativeTab;
|
||||
|
||||
public class FMPFactory implements MultiPartRegistry.IPartFactory {
|
||||
|
||||
static Item cableItem;
|
||||
|
||||
@Override
|
||||
public TMultiPart createPart(String s, boolean b) {
|
||||
if(s.equals("TRCable")){
|
||||
return new CablePart();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static void init(){
|
||||
MultiPartRegistry.registerParts(new FMPFactory(), new String[]{"TRCable"});
|
||||
cableItem = new ItemCable().setCreativeTab(TechRebornCreativeTab.instance).setUnlocalizedName("TRCable");
|
||||
GameRegistry.registerItem(cableItem, "TRCable");
|
||||
}
|
||||
|
||||
}
|
|
@ -1,17 +0,0 @@
|
|||
package techreborn.compat.fmp;
|
||||
|
||||
import codechicken.lib.vec.BlockCoord;
|
||||
import codechicken.lib.vec.Vector3;
|
||||
import codechicken.multipart.JItemMultiPart;
|
||||
import codechicken.multipart.MultiPartRegistry;
|
||||
import codechicken.multipart.TMultiPart;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class ItemCable extends JItemMultiPart {
|
||||
@Override
|
||||
public TMultiPart newPart(ItemStack itemStack, EntityPlayer entityPlayer, World world, BlockCoord blockCoord, int i, Vector3 vector3) {
|
||||
return MultiPartRegistry.createPart("TRCable", false);
|
||||
}
|
||||
}
|
16
src/main/java/techreborn/init/ModParts.java
Normal file
16
src/main/java/techreborn/init/ModParts.java
Normal file
|
@ -0,0 +1,16 @@
|
|||
package techreborn.init;
|
||||
|
||||
import me.modmuss50.network.partSystem.ModPartRegistry;
|
||||
import me.modmuss50.network.partSystem.block.WorldProvider;
|
||||
import me.modmuss50.network.partSystem.parts.CablePart;
|
||||
|
||||
public class ModParts {
|
||||
|
||||
public static void init(){
|
||||
ModPartRegistry.registerPart(new CablePart());
|
||||
ModPartRegistry.addProvider("me.modmuss50.network.partSystem.QLib.QModPartFactory", "qmunitylib");
|
||||
ModPartRegistry.addProvider("me.modmuss50.network.partSystem.fmp.FMPFactory", "ForgeMultipart");
|
||||
ModPartRegistry.addProvider(new WorldProvider());
|
||||
ModPartRegistry.addAllPartsToSystems();
|
||||
}
|
||||
}
|
Loading…
Add table
Reference in a new issue