More cable work

This commit is contained in:
modmuss50 2016-03-05 14:24:31 +00:00
parent 7d514b718a
commit a94039a5c2
15 changed files with 165 additions and 29 deletions

View file

@ -18,7 +18,7 @@ public class ClientPartModelBakery {
@SubscribeEvent(priority = EventPriority.LOWEST) @SubscribeEvent(priority = EventPriority.LOWEST)
public void onModelBake(ModelBakeEvent event){ public void onModelBake(ModelBakeEvent event){
for(EnumCableType type : EnumCableType.values()){ for(EnumCableType type : EnumCableType.values()){
event.modelRegistry.putObject(new ModelResourceLocation("techreborn:cable#type=" + type.name()), new RenderCablePart(type)); event.modelRegistry.putObject(new ModelResourceLocation("techreborn:cable#type=" + type.getName().toLowerCase()), new RenderCablePart(type));
} }
} }

View file

@ -35,7 +35,7 @@ public class RenderCablePart implements ISmartMultipartModel {
} }
public RenderCablePart(EnumCableType type) { public RenderCablePart(EnumCableType type) {
texture = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite("fluxedredstone:blocks/cable_redstone"); texture = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(type.textureName);
this.type = type; this.type = type;
} }
@ -63,7 +63,7 @@ public class RenderCablePart implements ISmartMultipartModel {
ArrayList<BakedQuad> list = new ArrayList<BakedQuad>(); ArrayList<BakedQuad> list = new ArrayList<BakedQuad>();
BlockFaceUV uv = new BlockFaceUV(new float[]{0.0F, 0.0F, 16.0F, 16.0F}, 0); BlockFaceUV uv = new BlockFaceUV(new float[]{0.0F, 0.0F, 16.0F, 16.0F}, 0);
BlockPartFace face = new BlockPartFace(null, 0, "", uv); BlockPartFace face = new BlockPartFace(null, 0, "", uv);
int thickness = 4; int thickness = 16 - (int) type.cableThickness * 2;
int lastThickness = 16 - thickness; int lastThickness = 16 - thickness;
addCubeToList(new Vecs3dCube(thickness, thickness, thickness, lastThickness, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture); addCubeToList(new Vecs3dCube(thickness, thickness, thickness, lastThickness, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture);
if (state != null) { if (state != null) {

View file

@ -33,7 +33,7 @@ import java.util.Map;
/** /**
* Created by mark on 02/03/2016. * Created by mark on 02/03/2016.
*/ */
public class CableMultipart extends Multipart implements IOccludingPart, ISlottedPart, ITickable { public abstract class CableMultipart extends Multipart implements IOccludingPart, ISlottedPart, ITickable, ICableType {
public Vecs3dCube[] boundingBoxes = new Vecs3dCube[14]; public Vecs3dCube[] boundingBoxes = new Vecs3dCube[14];
public float center = 0.6F; public float center = 0.6F;
@ -48,23 +48,16 @@ public class CableMultipart extends Multipart implements IOccludingPart, ISlotte
public static final IUnlistedProperty<Boolean> EAST = Properties.toUnlisted(PropertyBool.create("east")); public static final IUnlistedProperty<Boolean> EAST = Properties.toUnlisted(PropertyBool.create("east"));
public static final IUnlistedProperty<Boolean> SOUTH = Properties.toUnlisted(PropertyBool.create("south")); public static final IUnlistedProperty<Boolean> SOUTH = Properties.toUnlisted(PropertyBool.create("south"));
public static final IUnlistedProperty<Boolean> WEST = Properties.toUnlisted(PropertyBool.create("west")); public static final IUnlistedProperty<Boolean> WEST = Properties.toUnlisted(PropertyBool.create("west"));
public static final IProperty TYPE = PropertyEnum.create("type", EnumCableType.class); public static final IProperty<EnumCableType> TYPE = PropertyEnum.create("type", EnumCableType.class);
EnumCableType type; public CableMultipart() {
public CableMultipart(EnumCableType type) {
this.type = type;
connectedSides = new HashMap<>(); connectedSides = new HashMap<>();
refreshBounding(); refreshBounding();
} }
public CableMultipart(){
this(EnumCableType.COPPER);
}
public void refreshBounding() { public void refreshBounding() {
float centerFirst = center - offset; float centerFirst = center - offset;
double w = (type.cableThickness / 16) - 0.5; double w = getCableType().cableThickness / 16;
boundingBoxes[6] = new Vecs3dCube(centerFirst - w - 0.03, centerFirst boundingBoxes[6] = new Vecs3dCube(centerFirst - w - 0.03, centerFirst
- w - 0.08, centerFirst - w - 0.03, centerFirst + w + 0.08, - w - 0.08, centerFirst - w - 0.03, centerFirst + w + 0.08,
centerFirst + w + 0.04, centerFirst + w + 0.08); centerFirst + w + 0.04, centerFirst + w + 0.08);
@ -245,7 +238,7 @@ public class CableMultipart extends Multipart implements IOccludingPart, ISlotte
.withProperty(SOUTH, shouldConnectTo(EnumFacing.SOUTH)) .withProperty(SOUTH, shouldConnectTo(EnumFacing.SOUTH))
.withProperty(WEST, shouldConnectTo(EnumFacing.WEST)) .withProperty(WEST, shouldConnectTo(EnumFacing.WEST))
.withProperty(EAST, shouldConnectTo(EnumFacing.EAST)) .withProperty(EAST, shouldConnectTo(EnumFacing.EAST))
.withProperty(TYPE, type); .withProperty(TYPE, getCableType());
} }
@Override @Override
@ -268,4 +261,6 @@ public class CableMultipart extends Multipart implements IOccludingPart, ISlotte
public String getModelPath() { public String getModelPath() {
return "techreborn:cable"; return "techreborn:cable";
} }
} }

View file

@ -1,29 +1,36 @@
package techreborn.parts; package techreborn.parts;
import net.minecraft.util.IStringSerializable; import net.minecraft.util.IStringSerializable;
import techreborn.parts.types.*;
public enum EnumCableType implements IStringSerializable { public enum EnumCableType implements IStringSerializable {
COPPER("copper"), COPPER("copper", "minecraft:blocks/iron_block", 128, 4.0F, true, CopperCable.class),
TIN("tin"), TIN("tin", "minecraft:blocks/iron_block", 32, 4.0F, true, TinCable.class),
GOLD("gold"), GOLD("gold", "minecraft:blocks/iron_block", 512, 3.0F, true, GoldCable.class),
HV("hv"), HV("hv", "minecraft:blocks/iron_block", 2048, 6.0F, true, HVCable.class),
GLASSFIBER("glassfiber"), GLASSFIBER("glassfiber", "minecraft:blocks/iron_block", 8192, 4.0F, false, GlassFiberCable.class),
ICOPPER("insulatedcopper"), ICOPPER("insulatedcopper", "minecraft:blocks/iron_block", 128, 6.0F, false, InsulatedCopperCable.class),
IGOLD("insulatedgold"), IGOLD("insulatedgold", "minecraft:blocks/iron_block", 512, 6.0F, false, InsulatedGoldCable.class),
IHV("insulatedhv"); IHV("insulatedhv", "minecraft:blocks/iron_block", 2048, 10.0F, false, InsulatedHVCable.class);
private String friendlyName; private String friendlyName;
public String textureName = "minecraft:blocks/iron_block"; public String textureName = "minecraft:blocks/iron_block";
public int transferRate= 128; public int transferRate= 128;
public double cableThickness = 3.0; public float cableThickness = 3.0F;
public boolean canKill = false; public boolean canKill = false;
public Class<? extends CableMultipart> cableClass;
EnumCableType(String friendlyName) { EnumCableType(String friendlyName, String textureName, int transferRate, float cableThickness, boolean canKill, Class<? extends CableMultipart> cableClass) {
this.friendlyName = friendlyName; this.friendlyName = friendlyName;
this.textureName = textureName;
this.transferRate = transferRate;
this.cableThickness = cableThickness /2;
this.canKill = canKill;
this.cableClass = cableClass;
} }
@Override @Override
public String getName() { public String getName() {
return friendlyName; return friendlyName.toLowerCase();
} }
} }

View file

@ -0,0 +1,10 @@
package techreborn.parts;
/**
* Created by Mark on 05/03/2016.
*/
public interface ICableType {
EnumCableType getCableType();
}

View file

@ -32,7 +32,7 @@ public class ItemCables extends ItemMultiPart implements ITexturedItem {
return new ItemStack(TechRebornParts.cables, count, i); return new ItemStack(TechRebornParts.cables, count, i);
} }
} }
throw new InvalidParameterException("The cabel " + name + " could not be found."); throw new InvalidParameterException("The cable " + name + " could not be found.");
} }
public static ItemStack getCableByName(String name) { public static ItemStack getCableByName(String name) {
@ -49,7 +49,12 @@ public class ItemCables extends ItemMultiPart implements ITexturedItem {
@Override @Override
public IMultipart createPart(World world, BlockPos pos, EnumFacing side, Vec3 hit, ItemStack stack, EntityPlayer player) { public IMultipart createPart(World world, BlockPos pos, EnumFacing side, Vec3 hit, ItemStack stack, EntityPlayer player) {
return new CableMultipart(EnumCableType.values()[stack.getItemDamage()]); try {
return TechRebornParts.multipartHashMap.get(EnumCableType.values()[stack.getItemDamage()]).newInstance();
} catch (InstantiationException | IllegalAccessException e) {
e.printStackTrace();
}
return null;
} }

View file

@ -10,6 +10,8 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
import techreborn.compat.ICompatModule; import techreborn.compat.ICompatModule;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
/** /**
@ -20,6 +22,8 @@ public class TechRebornParts implements ICompatModule {
@Nullable @Nullable
public static Item cables; public static Item cables;
public static HashMap<EnumCableType, Class<? extends CableMultipart>> multipartHashMap = new HashMap<>();
@Override @Override
public void preInit(FMLPreInitializationEvent event) { public void preInit(FMLPreInitializationEvent event) {
@ -27,7 +31,10 @@ public class TechRebornParts implements ICompatModule {
@Override @Override
public void init(FMLInitializationEvent event) { public void init(FMLInitializationEvent event) {
MultipartRegistry.registerPart(CableMultipart.class, "techreborn:cable"); for(EnumCableType cableType : EnumCableType.values()){
multipartHashMap.put(cableType, cableType.cableClass);
MultipartRegistry.registerPart(cableType.cableClass, "techreborn:cable." + cableType.name());
}
cables = new ItemCables(); cables = new ItemCables();
GameRegistry.registerItem(cables, "cables"); GameRegistry.registerItem(cables, "cables");
} }

View file

@ -0,0 +1,14 @@
package techreborn.parts.types;
import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 05/03/2016.
*/
public class CopperCable extends CableMultipart {
@Override
public EnumCableType getCableType() {
return EnumCableType.COPPER;
}
}

View file

@ -0,0 +1,14 @@
package techreborn.parts.types;
import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 05/03/2016.
*/
public class GlassFiberCable extends CableMultipart {
@Override
public EnumCableType getCableType() {
return EnumCableType.GLASSFIBER;
}
}

View file

@ -0,0 +1,14 @@
package techreborn.parts.types;
import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 05/03/2016.
*/
public class GoldCable extends CableMultipart {
@Override
public EnumCableType getCableType() {
return EnumCableType.GOLD;
}
}

View file

@ -0,0 +1,14 @@
package techreborn.parts.types;
import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 05/03/2016.
*/
public class HVCable extends CableMultipart {
@Override
public EnumCableType getCableType() {
return EnumCableType.HV;
}
}

View file

@ -0,0 +1,14 @@
package techreborn.parts.types;
import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 05/03/2016.
*/
public class InsulatedCopperCable extends CableMultipart {
@Override
public EnumCableType getCableType() {
return EnumCableType.ICOPPER;
}
}

View file

@ -0,0 +1,14 @@
package techreborn.parts.types;
import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 05/03/2016.
*/
public class InsulatedGoldCable extends CableMultipart {
@Override
public EnumCableType getCableType() {
return EnumCableType.IGOLD;
}
}

View file

@ -0,0 +1,14 @@
package techreborn.parts.types;
import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 05/03/2016.
*/
public class InsulatedHVCable extends CableMultipart {
@Override
public EnumCableType getCableType() {
return EnumCableType.IHV;
}
}

View file

@ -0,0 +1,14 @@
package techreborn.parts.types;
import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 05/03/2016.
*/
public class TinCable extends CableMultipart {
@Override
public EnumCableType getCableType() {
return EnumCableType.COPPER;
}
}