Added walia support for the cables

This commit is contained in:
modmuss50 2016-03-07 20:33:08 +00:00
parent b8de296817
commit 67526480ad
37 changed files with 209 additions and 55 deletions

View file

@ -24,7 +24,7 @@ import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.init.ModBlocks;
/**
* Created by mark on 20/02/2016.
* Created by modmuss50 on 20/02/2016.
*/
public class BlockRubberLeaves extends BlockLeaves implements ITexturedBlock, IOpaqueBlock {

View file

@ -24,7 +24,7 @@ import techreborn.items.ItemParts;
import techreborn.items.tools.ItemTreeTap;
/**
* Created by mark on 19/02/2016.
* Created by modmuss50 on 19/02/2016.
*/
public class BlockRubberLog extends Block implements ITexturedBlock {

View file

@ -9,7 +9,7 @@ import reborncore.RebornCore;
import techreborn.client.TechRebornCreativeTabMisc;
/**
* Created by Mark on 20/02/2016.
* Created by modmuss50 on 20/02/2016.
*/
public class BlockRubberPlank extends Block implements ITexturedBlock {

View file

@ -14,7 +14,7 @@ import techreborn.client.TechRebornCreativeTabMisc;
import techreborn.world.RubberTreeGenerator;
/**
* Created by Mark on 20/02/2016.
* Created by modmuss50 on 20/02/2016.
*/
public class BlockRubberSapling extends BlockSapling {

View file

@ -13,7 +13,7 @@ import techreborn.client.TechRebornCreativeTab;
import techreborn.tiles.generator.TileSolarPanel;
/**
* Created by mark on 25/02/2016.
* Created by modmuss50 on 25/02/2016.
*/
public class BlockSolarPanel extends BaseTileBlock implements ITexturedBlock {

View file

@ -8,7 +8,7 @@ import techreborn.client.TechRebornCreativeTab;
import techreborn.tiles.generator.TileWaterMill;
/**
* Created by mark on 25/02/2016.
* Created by modmuss50 on 25/02/2016.
*/
public class BlockWaterMill extends BaseTileBlock {

View file

@ -8,7 +8,7 @@ import techreborn.client.TechRebornCreativeTab;
import techreborn.tiles.generator.TileWindMill;
/**
* Created by mark on 25/02/2016.
* Created by modmuss50 on 25/02/2016.
*/
public class BlockWindMill extends BaseTileBlock {

View file

@ -8,7 +8,7 @@ import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
import techreborn.compat.ICompatModule;
/**
* Created by Mark on 05/03/2016.
* Created by modmuss50 on 05/03/2016.
*/
public class ClientPartLoader implements ICompatModule {

View file

@ -12,7 +12,7 @@ import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 04/03/2016.
* Created by modmuss50 on 04/03/2016.
*/
public class ClientPartModelBakery {

View file

@ -15,6 +15,7 @@ import techreborn.compat.waila.CompatModuleWaila;
import techreborn.config.ConfigTechReborn;
import techreborn.parts.StandalonePartCompact;
import techreborn.parts.TechRebornParts;
import techreborn.parts.walia.WailaMcMultiPartCompact;
public class CompatManager {
@ -47,6 +48,7 @@ public class CompatManager {
registerCompact(TechRebornParts.class, "mcmultipart");
registerCompact(ClientPartLoader.class, "mcmultipart", "@client");
registerCompact(StandalonePartCompact.class, "!mcmultipart");
registerCompact(WailaMcMultiPartCompact.class, "mcmultipart", "Waila");
}
public void registerCompact(Class<? extends ICompatModule> moduleClass, Object... objs) {

View file

@ -7,7 +7,7 @@ import reborncore.RebornCore;
import techreborn.client.TechRebornCreativeTabMisc;
/**
* Created by Mark on 20/02/2016.
* Created by modmuss50 on 20/02/2016.
*/
public class ItemBlockRubberSapling extends ItemBlock implements ITexturedItem {

View file

@ -3,7 +3,7 @@ package techreborn.items;
import net.minecraft.item.Item;
/**
* Created by Mark on 19/02/2016.
* Created by modmuss50 on 19/02/2016.
*/
public class ItemMissingRecipe extends Item {
}

View file

@ -25,7 +25,7 @@ import java.util.List;
import java.util.Random;
/**
* Created by mark on 26/02/2016.
* Created by modmuss50 on 26/02/2016.
*/
public class ItemWrench extends ItemTR implements ITexturedItem {

View file

@ -25,15 +25,16 @@ import net.minecraftforge.common.property.Properties;
import reborncore.api.power.IEnergyInterfaceTile;
import reborncore.common.misc.Functions;
import reborncore.common.misc.vecmath.Vecs3dCube;
import techreborn.parts.walia.IPartWaliaProvider;
import techreborn.power.TRPowerNet;
import techreborn.utils.damageSources.ElectrialShockSource;
import java.util.*;
/**
* Created by mark on 02/03/2016.
* Created by modmuss50 on 02/03/2016.
*/
public abstract class CableMultipart extends Multipart implements IOccludingPart, ISlottedPart, ITickable, ICableType, ICollidableMultipart {
public abstract class CableMultipart extends Multipart implements IOccludingPart, ISlottedPart, ITickable, ICableType, ICollidableMultipart, IPartWaliaProvider {
public Vecs3dCube[] boundingBoxes = new Vecs3dCube[14];
public float center = 0.6F;
@ -148,7 +149,7 @@ public abstract class CableMultipart extends Multipart implements IOccludingPart
}
}
if(container == null){
if (container == null) {
return null;
}
ISlottedPart part = container.getPartInSlot(PartSlot.CENTER);
@ -227,8 +228,8 @@ public abstract class CableMultipart extends Multipart implements IOccludingPart
@Override
public void update() {
if(getWorld() != null){
if(getWorld().getTotalWorldTime() % 80 == 0){
if (getWorld() != null) {
if (getWorld().getTotalWorldTime() % 80 == 0) {
checkConnectedSides();
}
}
@ -258,11 +259,11 @@ public abstract class CableMultipart extends Multipart implements IOccludingPart
},
new IUnlistedProperty[]{
DOWN,
UP,
NORTH,
SOUTH,
WEST,
EAST});
UP,
NORTH,
SOUTH,
WEST,
EAST});
}
@ -290,10 +291,10 @@ public abstract class CableMultipart extends Multipart implements IOccludingPart
@Override
public void onEntityCollided(Entity entity) {
if(getCableType().canKill && entity instanceof EntityLivingBase){
if (getCableType().canKill && entity instanceof EntityLivingBase) {
entity.attackEntityFrom(new ElectrialShockSource(), 1F);
getWorld().playSoundAtEntity(entity, "techreborn:cable_shock", 0.6F, 1F);
getWorld().spawnParticle(EnumParticleTypes.CRIT, entity.posX, entity.posY, entity.posZ, 0, 0,0);
getWorld().spawnParticle(EnumParticleTypes.CRIT, entity.posX, entity.posY, entity.posZ, 0, 0, 0);
}
}
@ -313,17 +314,17 @@ public abstract class CableMultipart extends Multipart implements IOccludingPart
network = new TRPowerNet();
network.setIOLimit(this.getCableType().transferRate);
network.addElement(this);
for(EnumFacing dir : EnumFacing.VALUES){
for (EnumFacing dir : EnumFacing.VALUES) {
CableMultipart cableMultipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
if(cableMultipart != null && cableMultipart.getCableType() == getCableType()){
if (cableMultipart != null && cableMultipart.getCableType() == getCableType()) {
TRPowerNet net = cableMultipart.getNetwork();
if(net != null){
if (net != null) {
net.merge(network);
}
}
TileEntity te = getNeighbourTile(dir);
if(te != null && te instanceof IEnergyInterfaceTile){
if(((IEnergyInterfaceTile) te).canAcceptEnergy(dir) || ((IEnergyInterfaceTile) te).canProvideEnergy(dir)){
if (te != null && te instanceof IEnergyInterfaceTile) {
if (((IEnergyInterfaceTile) te).canAcceptEnergy(dir) || ((IEnergyInterfaceTile) te).canProvideEnergy(dir)) {
network.addConnection((IEnergyInterfaceTile) te, dir.getOpposite());
}
}
@ -358,4 +359,11 @@ public abstract class CableMultipart extends Multipart implements IOccludingPart
network = null;
}
@Override
public void addInfo(List<String> info) {
info.add(EnumChatFormatting.GREEN + "EU Transfer: " + EnumChatFormatting.LIGHT_PURPLE + getCableType().transferRate);
if (getCableType().canKill) {
info.add(EnumChatFormatting.RED + "Damages entity's!");
}
}
}

View file

@ -15,7 +15,7 @@ public enum EnumCableType implements IStringSerializable {
private String friendlyName;
public String textureName = "minecraft:blocks/iron_block";
public int transferRate= 128;
public int transferRate = 128;
public double cableThickness = 3.0;
public boolean canKill = false;
public Class<? extends CableMultipart> cableClass;
@ -24,7 +24,7 @@ public enum EnumCableType implements IStringSerializable {
this.friendlyName = friendlyName;
this.textureName = textureName;
this.transferRate = transferRate;
this.cableThickness = cableThickness /2;
this.cableThickness = cableThickness / 2;
this.canKill = canKill;
this.cableClass = cableClass;
}

View file

@ -1,7 +1,7 @@
package techreborn.parts;
/**
* Created by Mark on 05/03/2016.
* Created by modmuss50 on 05/03/2016.
*/
public interface ICableType {

View file

@ -9,6 +9,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.Vec3;
import net.minecraft.world.World;
@ -16,11 +17,10 @@ import reborncore.RebornCore;
import techreborn.client.TechRebornCreativeTab;
import techreborn.lib.ModInfo;
import java.security.InvalidParameterException;
import java.util.List;
/**
* Created by Mark on 27/02/2016.
* Created by modmuss50 on 27/02/2016.
*/
public class ItemCables extends ItemMultiPart implements ITexturedItem {
@ -76,4 +76,13 @@ public class ItemCables extends ItemMultiPart implements ITexturedItem {
public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int useRemaining) {
return new ModelResourceLocation(ModInfo.MOD_ID + ":" + getUnlocalizedName(stack).substring(5), "inventory");
}
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
EnumCableType type = EnumCableType.values()[stack.getItemDamage()];
tooltip.add(EnumChatFormatting.GREEN + "EU Transfer: " + EnumChatFormatting.LIGHT_PURPLE + type.transferRate);
if (type.canKill) {
tooltip.add(EnumChatFormatting.RED + "Damages entity's!");
}
}
}

View file

@ -5,9 +5,9 @@ import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumChatFormatting;
import reborncore.RebornCore;
import techreborn.client.TechRebornCreativeTab;
import techreborn.items.ItemTR;
import techreborn.items.ItemTextureBase;
import techreborn.lib.ModInfo;
@ -15,7 +15,7 @@ import java.security.InvalidParameterException;
import java.util.List;
/**
* Created by Mark on 06/03/2016.
* Created by modmuss50 on 06/03/2016.
*/
public class ItemStandaloneCables extends ItemTextureBase {
@ -24,7 +24,7 @@ public class ItemStandaloneCables extends ItemTextureBase {
public static ItemStack getCableByName(String name, int count) {
for (int i = 0; i < EnumCableType.values().length; i++) {
if (EnumCableType.values()[i].getName().equalsIgnoreCase(name)) {
return new ItemStack(mcPartCable != null? mcPartCable : StandalonePartCompact.itemStandaloneCable, count, i);
return new ItemStack(mcPartCable != null ? mcPartCable : StandalonePartCompact.itemStandaloneCable, count, i);
}
}
throw new InvalidParameterException("The cable " + name + " could not be found.");
@ -74,4 +74,13 @@ public class ItemStandaloneCables extends ItemTextureBase {
public ModelResourceLocation getModel(ItemStack stack, EntityPlayer player, int useRemaining) {
return new ModelResourceLocation(ModInfo.MOD_ID + ":" + getUnlocalizedName(stack).substring(5), "inventory");
}
@Override
public void addInformation(ItemStack stack, EntityPlayer playerIn, List<String> tooltip, boolean advanced) {
EnumCableType type = EnumCableType.values()[stack.getItemDamage()];
tooltip.add(EnumChatFormatting.GREEN + "EU Transfer: " + EnumChatFormatting.LIGHT_PURPLE + type.transferRate);
if (type.canKill) {
tooltip.add(EnumChatFormatting.RED + "Damages entity's!");
}
}
}

View file

@ -8,7 +8,7 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
import techreborn.compat.ICompatModule;
/**
* Created by Mark on 06/03/2016.
* Created by modmuss50 on 06/03/2016.
*/
public class StandalonePartCompact implements ICompatModule {

View file

@ -10,12 +10,11 @@ import net.minecraftforge.fml.common.registry.GameRegistry;
import techreborn.compat.ICompatModule;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.HashMap;
/**
* Created by mark on 02/03/2016.
* Created by modmuss50 on 02/03/2016.
*/
public class TechRebornParts implements ICompatModule {
@ -31,7 +30,7 @@ public class TechRebornParts implements ICompatModule {
@Override
public void init(FMLInitializationEvent event) {
for(EnumCableType cableType : EnumCableType.values()){
for (EnumCableType cableType : EnumCableType.values()) {
multipartHashMap.put(cableType, cableType.cableClass);
MultipartRegistry.registerPart(cableType.cableClass, "techreborn:cable." + cableType.name());
}

View file

@ -4,7 +4,7 @@ import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 05/03/2016.
* Created by modmuss50 on 05/03/2016.
*/
public class CopperCable extends CableMultipart {
@Override

View file

@ -4,7 +4,7 @@ import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 05/03/2016.
* Created by modmuss50 on 05/03/2016.
*/
public class GlassFiberCable extends CableMultipart {
@Override

View file

@ -4,7 +4,7 @@ import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 05/03/2016.
* Created by modmuss50 on 05/03/2016.
*/
public class GoldCable extends CableMultipart {
@Override

View file

@ -4,7 +4,7 @@ import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 05/03/2016.
* Created by modmuss50 on 05/03/2016.
*/
public class HVCable extends CableMultipart {
@Override

View file

@ -4,7 +4,7 @@ import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 05/03/2016.
* Created by modmuss50 on 05/03/2016.
*/
public class InsulatedCopperCable extends CableMultipart {
@Override

View file

@ -4,7 +4,7 @@ import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 05/03/2016.
* Created by modmuss50 on 05/03/2016.
*/
public class InsulatedGoldCable extends CableMultipart {
@Override

View file

@ -4,7 +4,7 @@ import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 05/03/2016.
* Created by modmuss50 on 05/03/2016.
*/
public class InsulatedHVCable extends CableMultipart {
@Override

View file

@ -4,7 +4,7 @@ import techreborn.parts.CableMultipart;
import techreborn.parts.EnumCableType;
/**
* Created by Mark on 05/03/2016.
* Created by modmuss50 on 05/03/2016.
*/
public class TinCable extends CableMultipart {
@Override

View file

@ -0,0 +1,11 @@
package techreborn.parts.walia;
import java.util.List;
/**
* Created by modmuss50 on 07/03/2016.
*/
public interface IPartWaliaProvider {
void addInfo(List<String> info);
}

View file

@ -0,0 +1,37 @@
package techreborn.parts.walia;
import mcmultipart.block.TileMultipart;
import mcp.mobius.waila.api.IWailaRegistrar;
import net.minecraftforge.fml.common.event.*;
import techreborn.compat.ICompatModule;
/**
* Created by modmuss50 on 07/03/2016.
*/
public class WailaMcMultiPartCompact implements ICompatModule {
@Override
public void preInit(FMLPreInitializationEvent event) {
}
@Override
public void init(FMLInitializationEvent event) {
FMLInterModComms.sendMessage("Waila", "register", getClass().getName()
+ ".callbackRegister");
}
@Override
public void postInit(FMLPostInitializationEvent event) {
}
@Override
public void serverStarting(FMLServerStartingEvent event) {
}
public static void callbackRegister(IWailaRegistrar registrar) {
registrar.registerBodyProvider(new WaliaPartProvider(),
TileMultipart.class);
}
}

View file

@ -0,0 +1,79 @@
package techreborn.parts.walia;
import mcmultipart.block.TileMultipart;
import mcmultipart.raytrace.PartMOP;
import mcmultipart.raytrace.RayTraceUtils;
import mcp.mobius.waila.api.IWailaConfigHandler;
import mcp.mobius.waila.api.IWailaDataAccessor;
import mcp.mobius.waila.api.IWailaDataProvider;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.Vec3;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import techreborn.parts.CableMultipart;
import java.util.ArrayList;
import java.util.List;
/**
* Created by modmuss50 on 07/03/2016.
*/
public class WaliaPartProvider implements IWailaDataProvider {
@Override
public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config) {
PartMOP mop = reTrace(accessor.getWorld(), accessor.getPosition(), accessor.getPlayer());
if (mop != null) {
if (mop.partHit instanceof CableMultipart) {
return mop.partHit.getDrops().get(0);
}
}
return null;
}
@Override
public List<String> getWailaHead(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
return null;
}
@Override
public List<String> getWailaBody(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
PartMOP mop = reTrace(accessor.getWorld(), accessor.getPosition(), accessor.getPlayer());
List<String> data = new ArrayList<>();
if (mop != null) {
if (mop.partHit instanceof IPartWaliaProvider) {
((IPartWaliaProvider) mop.partHit).addInfo(data);
}
}
return data;
}
@Override
public List<String> getWailaTail(ItemStack itemStack, List<String> currenttip, IWailaDataAccessor accessor, IWailaConfigHandler config) {
return null;
}
@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos) {
return null;
}
//Stolen from https://github.com/amadornes/MCMultiPart/blob/master/src/main/java/mcmultipart/block/BlockMultipart.java
private PartMOP reTrace(World world, BlockPos pos, EntityPlayer player) {
Vec3 start = RayTraceUtils.getStart(player);
Vec3 end = RayTraceUtils.getEnd(player);
RayTraceUtils.RayTraceResultPart result = getMultipartTile(world, pos).getPartContainer().collisionRayTrace(start, end);
return result == null ? null : result.hit;
}
//Stolen from https://github.com/amadornes/MCMultiPart/blob/master/src/main/java/mcmultipart/block/BlockMultipart.java
private TileMultipart getMultipartTile(IBlockAccess world, BlockPos pos) {
TileEntity tile = world.getTileEntity(pos);
return tile instanceof TileMultipart ? (TileMultipart) tile : null;
}
}

View file

@ -7,7 +7,7 @@ import reborncore.common.powerSystem.TilePowerAcceptor;
import techreborn.blocks.generator.BlockSolarPanel;
/**
* Created by mark on 25/02/2016.
* Created by modmuss50 on 25/02/2016.
*/
public class TileSolarPanel extends TilePowerAcceptor {

View file

@ -5,7 +5,7 @@ import net.minecraft.util.EnumFacing;
import reborncore.common.powerSystem.TilePowerAcceptor;
/**
* Created by mark on 25/02/2016.
* Created by modmuss50 on 25/02/2016.
*/
public class TileWaterMill extends TilePowerAcceptor {

View file

@ -4,7 +4,7 @@ import net.minecraft.util.EnumFacing;
import reborncore.common.powerSystem.TilePowerAcceptor;
/**
* Created by mark on 25/02/2016.
* Created by modmuss50 on 25/02/2016.
*/
public class TileWindMill extends TilePowerAcceptor {

View file

@ -3,7 +3,7 @@ package techreborn.utils.damageSources;
import net.minecraft.util.DamageSource;
/**
* Created by mark on 06/03/2016.
* Created by modmuss50 on 06/03/2016.
*/
public class ElectrialShockSource extends DamageSource {
public ElectrialShockSource() {

View file

@ -3,7 +3,7 @@ package techreborn.utils.damageSources;
import net.minecraft.util.DamageSource;
/**
* Created by Mark on 05/03/2016.
* Created by modmuss50 on 05/03/2016.
*/
public class FusionDamageSource extends DamageSource {
public FusionDamageSource() {

View file

@ -11,7 +11,7 @@ import net.minecraftforge.fml.common.IWorldGenerator;
import techreborn.config.ConfigTechReborn;
/**
* Created by Mark on 19/02/2016.
* Created by modmuss50 on 19/02/2016.
*/
public class TreeGenerator implements IWorldGenerator {