Massive improvement to parts, should work a lot better now

@gigabit101 you asked for it, now you just need to place covers on ic2
cables, and you can place covers in the conecting bit.

Also fixes, slow responsiveness when placing/breaking cables
Also fixes cables rendering incorectally when a cover is placed between
two cables.
This commit is contained in:
Modmuss50 2015-10-05 17:39:45 +01:00
parent 1723410d17
commit 20a57d298f
12 changed files with 144 additions and 51 deletions

View file

@ -25,8 +25,8 @@ public class IconSupplier {
public void onTextureStitch(TextureStitchEvent.Pre event) {
TextureMap reg = event.map;
if (reg.getTextureType() == 0) {
insulatedCopperCable = reg.registerIcon("ic2" + ":wiring/cable/blockCableO");
copperCable = reg.registerIcon("ic2" + ":wiring/cable/blockCable");
insulatedCopperCable = reg.registerIcon("ic2" + ":wiring/cable/blockCable");
copperCable = reg.registerIcon("ic2" + ":wiring/cable/blockCableO");
goldCable = reg.registerIcon("ic2" + ":wiring/cable/blockGoldCable");
insulatedGoldCable = reg.registerIcon("ic2" + ":wiring/cable/blockGoldCableI");
doubleInsulatedGoldCable = reg.registerIcon("ic2" + ":wiring/cable/blockGoldCableII");

View file

@ -127,7 +127,6 @@ public class CasingConnectedTextureGenerator extends TextureAtlasSprite {
if (iconRegister instanceof TextureMap) {
TextureMap map = (TextureMap) iconRegister;
String name = CasingConnectedTextureGenerator.getDerivedName(types[meta] + "." + texNum);
System.out.println(name);
TextureAtlasSprite texture = map.getTextureExtry(name);
if (texture == null) {
texture = new CasingConnectedTextureGenerator(name, types[meta], connectedTexture);

View file

@ -129,7 +129,6 @@ public class LesuConnectedTextureGenerator extends TextureAtlasSprite {
if (iconRegister instanceof TextureMap) {
TextureMap map = (TextureMap) iconRegister;
String name = LesuConnectedTextureGenerator.getDerivedName("lesu." + texNum);
System.out.println(name);
TextureAtlasSprite texture = map.getTextureExtry(name);
if (texture == null) {
texture = new LesuConnectedTextureGenerator(name, "lesu", connectedTexture);

View file

@ -115,4 +115,6 @@ public interface IModPart {
public void onRemoved();
public IModPart copy();
public boolean needsItem();
}

View file

@ -29,4 +29,6 @@ public interface IPartProvider {
public boolean isTileFromProvider(TileEntity tileEntity);
public IModPart getPartFromWorld(World world, Location location, String name);
public void init();
}

View file

@ -95,4 +95,9 @@ public abstract class ModPart extends TileEntity implements IModPart {
public String getItemTextureName() {
return "";
}
@Override
public boolean needsItem() {
return true;
}
}

View file

@ -33,19 +33,25 @@ public class ModPartRegistry {
}
public static void addAllPartsToSystems() {
for (IPartProvider iPartProvider : providers) {
iPartProvider.init();
}
LogHelper.info("Started to load all parts");
for (ModPart modPart : ModPartRegistry.parts) {
Item part = new ModPartItem(modPart)
.setUnlocalizedName(modPart.getName())
.setCreativeTab(TechRebornCreativeTab.instance)
.setTextureName(modPart.getItemTextureName());
GameRegistry.registerItem(part, modPart.getName());
itemParts.put(modPart.getName(), part);
if (modPart instanceof CablePart) {
GameRegistry.addShapelessRecipe(new ItemStack(part), IC2Items.getItem(CablePart.getTextureNameFromType(((CablePart) modPart).type)));
((CablePart) modPart).stack = new ItemStack(part);
ModParts.stackCable.put(((CablePart) modPart).type, new ItemStack(part));
if(modPart.needsItem()){
Item part = new ModPartItem(modPart)
.setUnlocalizedName(modPart.getName())
.setCreativeTab(TechRebornCreativeTab.instance)
.setTextureName(modPart.getItemTextureName());
GameRegistry.registerItem(part, modPart.getName());
itemParts.put(modPart.getName(), part);
if (modPart instanceof CablePart) {
GameRegistry.addShapelessRecipe(new ItemStack(part), IC2Items.getItem(CablePart.getTextureNameFromType(((CablePart) modPart).type)));
((CablePart) modPart).stack = new ItemStack(part);
ModParts.stackCable.put(((CablePart) modPart).type, new ItemStack(part));
}
}
}

View file

@ -72,6 +72,11 @@ public class QModPartFactory implements IPartFactory, IPartProvider {
return null;
}
@Override
public void init() {
}
public String getCreatedPartType(ItemStack item, EntityPlayer player,
World world, MovingObjectPosition mop, ModPart modPart) {
return modPart.getName();

View file

@ -4,6 +4,7 @@
package techreborn.partSystem.fmp;
import codechicken.lib.data.MCDataInput;
import codechicken.lib.vec.BlockCoord;
import codechicken.lib.vec.Cuboid6;
import codechicken.multipart.MultiPartRegistry;
@ -12,6 +13,7 @@ import codechicken.multipart.TMultiPart;
import codechicken.multipart.TileMultipart;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import techreborn.lib.Location;
@ -20,15 +22,14 @@ import techreborn.partSystem.IModPart;
import techreborn.partSystem.IPartProvider;
import techreborn.partSystem.ModPart;
import techreborn.partSystem.ModPartRegistry;
import techreborn.partSystem.parts.CableConverter;
import java.util.List;
/**
* Created by mark on 09/12/14.
*/
public class FMPFactory implements MultiPartRegistry.IPartFactory,
public class FMPFactory implements MultiPartRegistry.IPartFactory2,
IPartProvider {
@Override
public TMultiPart createPart(String type, boolean client) {
for (ModPart modPart : ModPartRegistry.parts) {
if (modPart.getName().equals(type)) {
@ -50,12 +51,34 @@ public class FMPFactory implements MultiPartRegistry.IPartFactory,
return tileEntity instanceof TileMultipart;
}
//TODO
@Override
public IModPart getPartFromWorld(World world, Location location, String name) {
TileEntity tileEntity = world.getTileEntity(location.getX(),
location.getY(), location.getZ());
if (tileEntity instanceof TileMultipart) {
TileMultipart mp = (TileMultipart) tileEntity;
boolean ret = false;
List<TMultiPart> t = mp.jPartList();
for (TMultiPart p : t) {
if (ret == false) {
if (p.getType().equals(name)) {
if(p instanceof FMPModPart){
return ((FMPModPart) p).iModPart;
}
ret = true;
}
}
}
return null;
}
return null;
}
@Override
public void init() {
MultiPartRegistry.registerConverter(new CableConverter());
}
@Override
public String modID() {
return "ForgeMultipart";
@ -100,4 +123,14 @@ public class FMPFactory implements MultiPartRegistry.IPartFactory,
}
return false;
}
@Override
public TMultiPart createPart(String s, NBTTagCompound nbtTagCompound) {
return createPart(s, false);
}
@Override
public TMultiPart createPart(String s, MCDataInput mcDataInput) {
return createPart(s, false);
}
}

View file

@ -59,23 +59,6 @@ public class FMPModPart extends TMultiPart implements TSlottedPart,
return NormalOcclusionTest.apply(this, npart);
}
public void addCollisionBoxesToList(List<Vecs3dCube> l,
AxisAlignedBB bounds, Entity entity) {
List<Vecs3dCube> boxes = new ArrayList<Vecs3dCube>();
List<Vecs3dCube> boxes_ = new ArrayList<Vecs3dCube>();
iModPart.addCollisionBoxesToList(boxes_, entity);
for (Vecs3dCube c : boxes_) {
Vecs3dCube cube = c.clone();
cube.add(getX(), getY(), getZ());
boxes.add(cube);
}
boxes_.clear();
for (Vecs3dCube c : boxes) {
if (c.toAABB().intersectsWith(bounds))
l.add(c);
}
}
@Override
public Iterable<Cuboid6> getCollisionBoxes() {

View file

@ -0,0 +1,37 @@
package techreborn.partSystem.parts;
import codechicken.lib.vec.BlockCoord;
import codechicken.multipart.MultiPartRegistry;
import codechicken.multipart.TMultiPart;
import ic2.api.item.IC2Items;
import ic2.core.block.wiring.BlockCable;
import ic2.core.block.wiring.TileEntityCable;
import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import techreborn.partSystem.fmp.FMPModPart;
import java.util.Arrays;
public class CableConverter implements MultiPartRegistry.IPartConverter {
@Override
public Iterable<Block> blockTypes() {
return Arrays.asList(Block.getBlockFromItem(IC2Items.getItem("copperCableBlock").getItem()));
}
@Override
public TMultiPart convert(World world, BlockCoord blockCoord) {
Block block = world.getBlock(blockCoord.x, blockCoord.y, blockCoord.z);
if (block instanceof BlockCable) {
TileEntity tileEntity = world.getTileEntity(blockCoord.x, blockCoord.y, blockCoord.z);
if (tileEntity instanceof TileEntityCable) {
TileEntityCable cable = (TileEntityCable) tileEntity;
int type = cable.cableType;
CablePart newPart = new CablePart();
newPart.setType(type);
return new FMPModPart(newPart);
}
}
return null;
}
}

View file

@ -21,6 +21,7 @@ import net.minecraftforge.common.util.ForgeDirection;
import techreborn.client.render.RenderCablePart;
import techreborn.init.ModParts;
import techreborn.lib.Functions;
import techreborn.lib.Location;
import techreborn.lib.vecmath.Vecs3d;
import techreborn.lib.vecmath.Vecs3dCube;
import techreborn.partSystem.IModPart;
@ -114,12 +115,7 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
@Override
public List<Vecs3dCube> getOcclusionBoxes() {
List<Vecs3dCube> vecs3dCubesList = new ArrayList<Vecs3dCube>();
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if (connectedSides.containsKey(dir))
vecs3dCubesList.add(boundingBoxes[Functions
.getIntDirFromDirection(dir)]);
}
vecs3dCubesList.add(boundingBoxes[6]);
return vecs3dCubesList;
}
@ -176,6 +172,14 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
@Override
public void nearByChange() {
checkConnectedSides();
for(ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS){
worldObj.markBlockForUpdate(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ);
IModPart part = ModPartUtils.getPartFromWorld(world, new Location(xCoord + direction.offsetX, yCoord + direction.offsetY, zCoord + direction.offsetZ) , this.getName());
if(part != null){
CablePart cablePart = (CablePart) part;
cablePart.checkConnectedSides();
}
}
}
@Override
@ -186,7 +190,7 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
this.addedToEnergyNet = true;
nearByChange();
}
checkConnectedSides();
nearByChange();
}
@Override
@ -206,7 +210,7 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
@Override
public ItemStack getItem() {
return ModParts.stackCable.get(type);
return new ItemStack(IC2Items.getItem("copperCableItem").getItem(), 1, type);
}
public boolean shouldConnectTo(TileEntity entity, ForgeDirection dir) {
@ -215,8 +219,21 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
} else if (entity instanceof IEnergyTile) {
return true;
} else {
return ModPartUtils.hasPart(entity.getWorldObj(), entity.xCoord,
entity.yCoord, entity.zCoord, this.getName());
if(ModPartUtils.hasPart(entity.getWorldObj(), entity.xCoord, entity.yCoord, entity.zCoord, this.getName())){
CablePart otherCable = (CablePart) ModPartUtils.getPartFromWorld(entity.getWorldObj(), new Location(entity.xCoord, entity.yCoord, entity.zCoord), this.getName());
int thisDir = Functions.getIntDirFromDirection(dir);
int thereDir = Functions.getIntDirFromDirection(dir.getOpposite());
boolean hasconnection = otherCable.connections[thereDir];
otherCable.connections[thereDir] = false;
if(ModPartUtils.checkOcclusion(entity.getWorldObj(), entity.xCoord, entity.yCoord, entity.zCoord, boundingBoxes[thereDir])){
otherCable.connections[thereDir] = true;
return true;
}
otherCable.connections[thereDir] = hasconnection;
}
return false;
}
}
@ -386,10 +403,10 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
String p = null;
switch (cableType) {
case 0:
p = "copperCable";
p = "insulatedCopperCable";
break;
case 1:
p = "insulatedCopperCable";
p = "copperCable";
break;
case 2:
p = "goldCable";
@ -438,10 +455,10 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
String p = null;
switch (cableType) {
case 0:
p = "copperCableItem";
p = "insulatedCopperCableItem";
break;
case 1:
p = "insulatedCopperCableItem";
p = "copperCableItem";
break;
case 2:
p = "goldCableItem";
@ -567,4 +584,9 @@ public class CablePart extends ModPart implements IEnergyConductor, INetworkTile
public void writeDesc(NBTTagCompound tagCompound) {
writeConnectedSidesToNBT(tagCompound);
}
@Override
public boolean needsItem() {
return false;
}
}