Power system re-write, recipe fixes.
Please note that this version breaks all wires placed in worlds before.
This commit is contained in:
parent
25c581e129
commit
d982cc4028
33 changed files with 507 additions and 859 deletions
|
@ -30,8 +30,6 @@ public class TechRebornParts implements ICompatModule
|
|||
@Nullable
|
||||
public static Item fluidPipe;
|
||||
|
||||
public static HashMap<EnumCableType, Class<? extends CableMultipart>> multipartHashMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void preInit(FMLPreInitializationEvent event)
|
||||
{
|
||||
|
@ -39,17 +37,13 @@ public class TechRebornParts implements ICompatModule
|
|||
}
|
||||
|
||||
@Override
|
||||
public void init(FMLInitializationEvent event)
|
||||
{
|
||||
for (EnumCableType cableType : EnumCableType.values())
|
||||
{
|
||||
multipartHashMap.put(cableType, cableType.cableClass);
|
||||
MultipartRegistry.registerPart(cableType.cableClass, "techreborn:cable." + cableType.name());
|
||||
}
|
||||
public void init(FMLInitializationEvent event) {
|
||||
|
||||
cables = new ItemCables();
|
||||
cables.setRegistryName("cables");
|
||||
GameRegistry.register(cables);
|
||||
|
||||
MultipartRegistry.registerPart(CableMultipart.class, "techreborn:cable");
|
||||
MultipartRegistry.registerPart(EmptyFluidPipe.class, "techreborn:fluidpipe.empty");
|
||||
MultipartRegistry.registerPart(InsertingFluidPipe.class, "techreborn:fluidpipe.inserting");
|
||||
MultipartRegistry.registerPart(ExtractingFluidPipe.class, "techreborn:fluidpipe.extracting");
|
||||
|
|
|
@ -1,9 +1,5 @@
|
|||
package techreborn.parts.powerCables;
|
||||
|
||||
import reborncore.mcmultipart.MCMultiPartMod;
|
||||
import reborncore.mcmultipart.microblock.IMicroblock;
|
||||
import reborncore.mcmultipart.multipart.*;
|
||||
import reborncore.mcmultipart.raytrace.PartMOP;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
|
@ -15,8 +11,13 @@ import net.minecraft.entity.Entity;
|
|||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
|
@ -29,11 +30,12 @@ import reborncore.api.power.IEnergyInterfaceTile;
|
|||
import reborncore.common.misc.Functions;
|
||||
import reborncore.common.misc.vecmath.Vecs3dCube;
|
||||
import reborncore.common.util.WorldUtils;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.init.ModSounds;
|
||||
import reborncore.mcmultipart.MCMultiPartMod;
|
||||
import reborncore.mcmultipart.microblock.IMicroblock;
|
||||
import reborncore.mcmultipart.multipart.*;
|
||||
import reborncore.mcmultipart.raytrace.PartMOP;
|
||||
import techreborn.parts.TechRebornParts;
|
||||
import techreborn.parts.walia.IPartWaliaProvider;
|
||||
import techreborn.power.TRPowerNet;
|
||||
import techreborn.utils.damageSources.ElectrialShockSource;
|
||||
|
||||
import java.util.*;
|
||||
|
@ -41,7 +43,7 @@ import java.util.*;
|
|||
/**
|
||||
* Created by modmuss50 on 02/03/2016.
|
||||
*/
|
||||
public abstract class CableMultipart extends Multipart
|
||||
public class CableMultipart extends Multipart
|
||||
implements INormallyOccludingPart, ISlottedPart, ITickable, ICableType, IPartWaliaProvider {
|
||||
|
||||
public static final IUnlistedProperty<Boolean> UP = Properties.toUnlisted(PropertyBool.create("up"));
|
||||
|
@ -55,10 +57,14 @@ public abstract class CableMultipart extends Multipart
|
|||
public float center = 0.6F;
|
||||
public float offset = 0.10F;
|
||||
public Map<EnumFacing, BlockPos> connectedSides;
|
||||
public int ticks = 0;
|
||||
public ItemStack stack;
|
||||
public TRPowerNet mergeWith = null;
|
||||
private TRPowerNet network;
|
||||
public double lastEnergyPacket;
|
||||
public EnumCableType cableType = EnumCableType.ICOPPER;
|
||||
|
||||
public CableMultipart(EnumCableType cableType) {
|
||||
this.cableType = cableType;
|
||||
connectedSides = new HashMap<>();
|
||||
refreshBounding();
|
||||
}
|
||||
|
||||
public CableMultipart() {
|
||||
connectedSides = new HashMap<>();
|
||||
|
@ -144,7 +150,6 @@ public abstract class CableMultipart extends Multipart
|
|||
@Override
|
||||
public void onRemoved() {
|
||||
super.onRemoved();
|
||||
removeFromNetwork();
|
||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||
CableMultipart multipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
|
||||
if (multipart != null) {
|
||||
|
@ -153,12 +158,6 @@ public abstract class CableMultipart extends Multipart
|
|||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnloaded() {
|
||||
super.onUnloaded();
|
||||
removeFromNetwork();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOcclusionBoxes(List<AxisAlignedBB> list) {
|
||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||
|
@ -172,13 +171,9 @@ public abstract class CableMultipart extends Multipart
|
|||
public void onNeighborBlockChange(Block block) {
|
||||
super.onNeighborBlockChange(block);
|
||||
nearByChange();
|
||||
|
||||
}
|
||||
|
||||
public void nearByChange() {
|
||||
if (network == null) {
|
||||
findAndJoinNetwork(getWorld(), getPos());
|
||||
}
|
||||
checkConnectedSides();
|
||||
for (EnumFacing direction : EnumFacing.VALUES) {
|
||||
BlockPos blockPos = getPos().offset(direction);
|
||||
|
@ -188,7 +183,6 @@ public abstract class CableMultipart extends Multipart
|
|||
part.checkConnectedSides();
|
||||
}
|
||||
}
|
||||
TRPowerNet.buildEndpoint(network);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -258,18 +252,14 @@ public abstract class CableMultipart extends Multipart
|
|||
@Override
|
||||
public void update() {
|
||||
if (getWorld() != null) {
|
||||
if(lastEnergyPacket > 0)
|
||||
--lastEnergyPacket;
|
||||
|
||||
if (getWorld().getTotalWorldTime() % 80 == 0) {
|
||||
checkConnectedSides();
|
||||
}
|
||||
}
|
||||
if (network == null) {
|
||||
this.findAndJoinNetwork(getWorld(), getPos());
|
||||
} else {
|
||||
if (mergeWith != null) {
|
||||
getNetwork().merge(mergeWith);
|
||||
mergeWith = null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -294,7 +284,7 @@ public abstract class CableMultipart extends Multipart
|
|||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
return Material.CLOTH;
|
||||
return getCableType().material;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -307,97 +297,16 @@ public abstract class CableMultipart extends Multipart
|
|||
@Override
|
||||
public void onEntityCollided(Entity entity) {
|
||||
if (getCableType().canKill && entity instanceof EntityLivingBase) {
|
||||
if (network != null) {
|
||||
if (network.getEnergy() != 0) {
|
||||
if (ConfigTechReborn.UninsulatedElectocutionDamage) {
|
||||
if (getCableType() == EnumCableType.HV) {
|
||||
entity.setFire(1);
|
||||
}
|
||||
network.setEnergy(-1);
|
||||
entity.attackEntityFrom(new ElectrialShockSource(), 1F);
|
||||
}
|
||||
if (ConfigTechReborn.UninsulatedElectocutionSound) {
|
||||
getWorld().playSound(null, entity.posX, entity.posY,
|
||||
entity.posZ, ModSounds.shock,
|
||||
SoundCategory.BLOCKS, 0.6F, 1F);
|
||||
}
|
||||
if (ConfigTechReborn.UninsulatedElectocutionParticle) {
|
||||
getWorld().spawnParticle(EnumParticleTypes.CRIT, entity.posX, entity.posY, entity.posZ, 0,
|
||||
0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
entity.attackEntityFrom(new ElectrialShockSource(), (float) (lastEnergyPacket / 16F));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityStanding(Entity entity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(EntityPlayer player, PartMOP hit) {
|
||||
return new ItemStack(TechRebornParts.cables, 1, getCableType().ordinal());
|
||||
}
|
||||
|
||||
public final void findAndJoinNetwork(World world, BlockPos pos) {
|
||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||
CableMultipart cableMultipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
|
||||
if (cableMultipart != null && cableMultipart.getCableType() == getCableType()) {
|
||||
TRPowerNet net = cableMultipart.getNetwork();
|
||||
if (net != null) {
|
||||
network = net;
|
||||
network.addElement(this);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (network == null) {
|
||||
network = new TRPowerNet(getCableType());
|
||||
network.addElement(this);
|
||||
}
|
||||
network.endpoints.clear();
|
||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||
TileEntity te = getNeighbourTile(dir);
|
||||
if (te != null && te instanceof IEnergyInterfaceTile) {
|
||||
network.addConnection((IEnergyInterfaceTile) te, dir.getOpposite());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public final TRPowerNet getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
public final void setNetwork(TRPowerNet n) {
|
||||
if (n == null) {
|
||||
} else {
|
||||
network = n;
|
||||
network.addElement(this);
|
||||
}
|
||||
}
|
||||
|
||||
public final void removeFromNetwork() {
|
||||
if (network == null) {
|
||||
} else
|
||||
network.removeElement(this);
|
||||
}
|
||||
|
||||
public final void rebuildNetwork() {
|
||||
this.removeFromNetwork();
|
||||
this.resetNetwork();
|
||||
this.findAndJoinNetwork(getWorld(), getPos());
|
||||
}
|
||||
|
||||
public final void resetNetwork() {
|
||||
if (network != null) {
|
||||
network.removeElement(this);
|
||||
}
|
||||
|
||||
network = null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addInfo(List<String> info) {
|
||||
info.add(TextFormatting.GREEN + "EU Transfer: " +
|
||||
|
@ -416,4 +325,35 @@ public abstract class CableMultipart extends Multipart
|
|||
public boolean canRenderInLayer(BlockRenderLayer layer) {
|
||||
return layer == BlockRenderLayer.CUTOUT;
|
||||
}
|
||||
|
||||
@Override
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
|
||||
tag.setString("CableType", cableType.name());
|
||||
return tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound tag) {
|
||||
if(tag.hasKey("CableType")) {
|
||||
cableType = EnumCableType.valueOf(tag.getString("CableType"));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeUpdatePacket(PacketBuffer buf) {
|
||||
super.writeUpdatePacket(buf);
|
||||
buf.writeInt(cableType.ordinal());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readUpdatePacket(PacketBuffer buf) {
|
||||
super.readUpdatePacket(buf);
|
||||
cableType = EnumCableType.values()[buf.readInt()];
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return cableType;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,44 +1,37 @@
|
|||
package techreborn.parts.powerCables;
|
||||
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.util.IStringSerializable;
|
||||
import reborncore.api.power.EnumPowerTier;
|
||||
import techreborn.parts.powerCables.types.CopperCable;
|
||||
import techreborn.parts.powerCables.types.GlassFiberCable;
|
||||
import techreborn.parts.powerCables.types.GoldCable;
|
||||
import techreborn.parts.powerCables.types.HVCable;
|
||||
import techreborn.parts.powerCables.types.InsulatedCopperCable;
|
||||
import techreborn.parts.powerCables.types.InsulatedGoldCable;
|
||||
import techreborn.parts.powerCables.types.InsulatedHVCable;
|
||||
import techreborn.parts.powerCables.types.TinCable;
|
||||
|
||||
public enum EnumCableType implements IStringSerializable
|
||||
{
|
||||
COPPER("copper", "techreborn:blocks/cables/copper_cable", 128, 12.0, true, EnumPowerTier.LOW, CopperCable.class),
|
||||
TIN("tin", "techreborn:blocks/cables/tin_cable", 32, 12.0, true, EnumPowerTier.MEDIUM, TinCable.class),
|
||||
GOLD("gold", "techreborn:blocks/cables/gold_cable", 512, 12.0, true, EnumPowerTier.MEDIUM, GoldCable.class),
|
||||
HV("hv", "techreborn:blocks/cables/hv_cable", 2048, 12.0, true, EnumPowerTier.HIGH, HVCable.class),
|
||||
GLASSFIBER("glassfiber", "techreborn:blocks/cables/glass_fiber_cable", 8192, 12.0, false, EnumPowerTier.HIGH, GlassFiberCable.class),
|
||||
ICOPPER("insulatedcopper", "techreborn:blocks/cables/copper_insulated_cable", 128, 10.0, false, EnumPowerTier.LOW, InsulatedCopperCable.class),
|
||||
IGOLD("insulatedgold", "techreborn:blocks/cables/gold_insulated_cable", 512, 10.0, false, EnumPowerTier.MEDIUM, InsulatedGoldCable.class),
|
||||
IHV("insulatedhv", "techreborn:blocks/cables/hv_insulated_cable", 2048, 10.0, false, EnumPowerTier.HIGH, InsulatedHVCable.class);
|
||||
COPPER("copper", "techreborn:blocks/cables/copper_cable", Material.IRON, 128, 12.0, true, EnumPowerTier.LOW),
|
||||
TIN("tin", "techreborn:blocks/cables/tin_cable", Material.IRON, 32, 12.0, true, EnumPowerTier.MEDIUM),
|
||||
GOLD("gold", "techreborn:blocks/cables/gold_cable", Material.IRON, 512, 12.0, true, EnumPowerTier.MEDIUM),
|
||||
HV("hv", "techreborn:blocks/cables/hv_cable", Material.IRON, 2048, 12.0, true, EnumPowerTier.HIGH),
|
||||
GLASSFIBER("glassfiber", "techreborn:blocks/cables/glass_fiber_cable", Material.GLASS, 8192, 12.0, false, EnumPowerTier.HIGH),
|
||||
ICOPPER("insulatedcopper", "techreborn:blocks/cables/copper_insulated_cable", Material.CLOTH, 128, 10.0, false, EnumPowerTier.LOW),
|
||||
IGOLD("insulatedgold", "techreborn:blocks/cables/gold_insulated_cable", Material.CLOTH, 512, 10.0, false, EnumPowerTier.MEDIUM),
|
||||
IHV("insulatedhv", "techreborn:blocks/cables/hv_insulated_cable", Material.CLOTH, 2048, 10.0, false, EnumPowerTier.HIGH);
|
||||
|
||||
public Material material;
|
||||
public String textureName = "minecraft:blocks/iron_block";
|
||||
public int transferRate = 128;
|
||||
public double cableThickness = 3.0;
|
||||
public boolean canKill = false;
|
||||
public Class<? extends CableMultipart> cableClass;
|
||||
public EnumPowerTier tier;
|
||||
private String friendlyName;
|
||||
|
||||
EnumCableType(String friendlyName, String textureName, int transferRate, double cableThickness, boolean canKill,
|
||||
EnumPowerTier tier, Class<? extends CableMultipart> cableClass)
|
||||
EnumCableType(String friendlyName, String textureName, Material material, int transferRate, double cableThickness, boolean canKill,
|
||||
EnumPowerTier tier)
|
||||
{
|
||||
this.friendlyName = friendlyName;
|
||||
this.textureName = textureName;
|
||||
this.material = material;
|
||||
this.transferRate = transferRate;
|
||||
this.cableThickness = cableThickness / 2;
|
||||
this.canKill = canKill;
|
||||
this.cableClass = cableClass;
|
||||
this.tier = tier;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,17 +40,8 @@ public class ItemCables extends ItemMultiPart implements ITexturedItem
|
|||
}
|
||||
|
||||
@Override
|
||||
public IMultipart createPart(World world, BlockPos pos, EnumFacing side, Vec3d hit, ItemStack stack,
|
||||
EntityPlayer player)
|
||||
{
|
||||
try
|
||||
{
|
||||
return TechRebornParts.multipartHashMap.get(EnumCableType.values()[stack.getItemDamage()]).newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
public IMultipart createPart(World world, BlockPos pos, EnumFacing side, Vec3d hit, ItemStack stack, EntityPlayer player) {
|
||||
return new CableMultipart(EnumCableType.values()[stack.getItemDamage()]);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -1,16 +0,0 @@
|
|||
package techreborn.parts.powerCables.types;
|
||||
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class CopperCable extends CableMultipart
|
||||
{
|
||||
@Override
|
||||
public EnumCableType getCableType()
|
||||
{
|
||||
return EnumCableType.COPPER;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package techreborn.parts.powerCables.types;
|
||||
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class GlassFiberCable extends CableMultipart
|
||||
{
|
||||
@Override
|
||||
public EnumCableType getCableType()
|
||||
{
|
||||
return EnumCableType.GLASSFIBER;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package techreborn.parts.powerCables.types;
|
||||
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class GoldCable extends CableMultipart
|
||||
{
|
||||
@Override
|
||||
public EnumCableType getCableType()
|
||||
{
|
||||
return EnumCableType.GOLD;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package techreborn.parts.powerCables.types;
|
||||
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class HVCable extends CableMultipart
|
||||
{
|
||||
@Override
|
||||
public EnumCableType getCableType()
|
||||
{
|
||||
return EnumCableType.HV;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package techreborn.parts.powerCables.types;
|
||||
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class InsulatedCopperCable extends CableMultipart
|
||||
{
|
||||
@Override
|
||||
public EnumCableType getCableType()
|
||||
{
|
||||
return EnumCableType.ICOPPER;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package techreborn.parts.powerCables.types;
|
||||
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class InsulatedGoldCable extends CableMultipart
|
||||
{
|
||||
@Override
|
||||
public EnumCableType getCableType()
|
||||
{
|
||||
return EnumCableType.IGOLD;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package techreborn.parts.powerCables.types;
|
||||
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class InsulatedHVCable extends CableMultipart
|
||||
{
|
||||
@Override
|
||||
public EnumCableType getCableType()
|
||||
{
|
||||
return EnumCableType.IHV;
|
||||
}
|
||||
}
|
|
@ -1,16 +0,0 @@
|
|||
package techreborn.parts.powerCables.types;
|
||||
|
||||
import techreborn.parts.powerCables.CableMultipart;
|
||||
import techreborn.parts.powerCables.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class TinCable extends CableMultipart
|
||||
{
|
||||
@Override
|
||||
public EnumCableType getCableType()
|
||||
{
|
||||
return EnumCableType.TIN;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue