Its all broke, mcmultipart support
This commit is contained in:
parent
f255137753
commit
471a945de6
18 changed files with 83 additions and 73 deletions
|
@ -1,427 +0,0 @@
|
|||
package techreborn.parts;
|
||||
|
||||
import mcmultipart.MCMultiPartMod;
|
||||
import mcmultipart.microblock.IMicroblock;
|
||||
import mcmultipart.multipart.ICollidableMultipart;
|
||||
import mcmultipart.multipart.IMultipartContainer;
|
||||
import mcmultipart.multipart.IOccludingPart;
|
||||
import mcmultipart.multipart.ISlottedPart;
|
||||
import mcmultipart.multipart.Multipart;
|
||||
import mcmultipart.multipart.MultipartHelper;
|
||||
import mcmultipart.multipart.OcclusionHelper;
|
||||
import mcmultipart.multipart.PartSlot;
|
||||
import mcmultipart.raytrace.PartMOP;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.properties.IProperty;
|
||||
import net.minecraft.block.properties.PropertyBool;
|
||||
import net.minecraft.block.properties.PropertyEnum;
|
||||
import net.minecraft.block.state.BlockState;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.AxisAlignedBB;
|
||||
import net.minecraft.util.BlockPos;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.EnumWorldBlockLayer;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.property.ExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
import net.minecraftforge.common.property.Properties;
|
||||
import reborncore.api.power.IEnergyInterfaceTile;
|
||||
import reborncore.common.misc.Functions;
|
||||
import reborncore.common.misc.vecmath.Vecs3dCube;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.parts.walia.IPartWaliaProvider;
|
||||
import techreborn.power.TRPowerNet;
|
||||
import techreborn.utils.damageSources.ElectrialShockSource;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 02/03/2016.
|
||||
*/
|
||||
public abstract class CableMultipart extends Multipart implements IOccludingPart, ISlottedPart, ITickable, ICableType, ICollidableMultipart, IPartWaliaProvider {
|
||||
|
||||
public Vecs3dCube[] boundingBoxes = new Vecs3dCube[14];
|
||||
public float center = 0.6F;
|
||||
public float offset = 0.10F;
|
||||
public Map<EnumFacing, BlockPos> connectedSides;
|
||||
public int ticks = 0;
|
||||
public ItemStack stack;
|
||||
|
||||
public static final IUnlistedProperty<Boolean> UP = Properties.toUnlisted(PropertyBool.create("up"));
|
||||
public static final IUnlistedProperty<Boolean> DOWN = Properties.toUnlisted(PropertyBool.create("down"));
|
||||
public static final IUnlistedProperty<Boolean> NORTH = Properties.toUnlisted(PropertyBool.create("north"));
|
||||
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> WEST = Properties.toUnlisted(PropertyBool.create("west"));
|
||||
public static final IProperty<EnumCableType> TYPE = PropertyEnum.create("type", EnumCableType.class);
|
||||
|
||||
public CableMultipart() {
|
||||
connectedSides = new HashMap<>();
|
||||
refreshBounding();
|
||||
}
|
||||
|
||||
public void refreshBounding() {
|
||||
float centerFirst = center - offset;
|
||||
double w = (getCableType().cableThickness / 16) - 0.5;
|
||||
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 (EnumFacing dir : EnumFacing.VALUES) {
|
||||
double xMin1 = (dir.getFrontOffsetX() < 0 ? 0.0
|
||||
: (dir.getFrontOffsetX() == 0 ? centerFirst - w : centerFirst + w));
|
||||
double xMax1 = (dir.getFrontOffsetX() > 0 ? 1.0
|
||||
: (dir.getFrontOffsetX() == 0 ? centerFirst + w : centerFirst - w));
|
||||
|
||||
double yMin1 = (dir.getFrontOffsetY() < 0 ? 0.0
|
||||
: (dir.getFrontOffsetY() == 0 ? centerFirst - w : centerFirst + w));
|
||||
double yMax1 = (dir.getFrontOffsetY() > 0 ? 1.0
|
||||
: (dir.getFrontOffsetY() == 0 ? centerFirst + w : centerFirst - w));
|
||||
|
||||
double zMin1 = (dir.getFrontOffsetZ() < 0 ? 0.0
|
||||
: (dir.getFrontOffsetZ() == 0 ? centerFirst - w : centerFirst + w));
|
||||
double zMax1 = (dir.getFrontOffsetZ() > 0 ? 1.0
|
||||
: (dir.getFrontOffsetZ() == 0 ? centerFirst + w : centerFirst - w));
|
||||
|
||||
boundingBoxes[i] = new Vecs3dCube(xMin1, yMin1, zMin1, xMax1,
|
||||
yMax1, zMax1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCollisionBoxes(AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity) {
|
||||
super.addCollisionBoxes(mask, list, collidingEntity);
|
||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||
if (connectedSides.containsKey(dir) && mask.intersectsWith(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB()))
|
||||
list.add(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB());
|
||||
}
|
||||
if (mask.intersectsWith(boundingBoxes[6].toAABB())) {
|
||||
list.add(boundingBoxes[6].toAABB());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSelectionBoxes(List<AxisAlignedBB> list) {
|
||||
super.addSelectionBoxes(list);
|
||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||
if (connectedSides.containsKey(dir))
|
||||
list.add(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB());
|
||||
}
|
||||
list.add(boundingBoxes[6].toAABB());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onRemoved() {
|
||||
super.onRemoved();
|
||||
removeFromNetwork();
|
||||
for(EnumFacing dir : EnumFacing.VALUES){
|
||||
CableMultipart multipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
|
||||
if(multipart != null){
|
||||
multipart.nearByChange();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUnloaded() {
|
||||
super.onUnloaded();
|
||||
removeFromNetwork();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addOcclusionBoxes(List<AxisAlignedBB> list) {
|
||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||
if (connectedSides.containsKey(dir))
|
||||
list.add(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB());
|
||||
}
|
||||
list.add(boundingBoxes[6].toAABB());
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNeighborBlockChange(Block block) {
|
||||
super.onNeighborBlockChange(block);
|
||||
nearByChange();
|
||||
findAndJoinNetwork(getWorld(), getPos());
|
||||
}
|
||||
|
||||
public void nearByChange() {
|
||||
checkConnectedSides();
|
||||
for (EnumFacing direction : EnumFacing.VALUES) {
|
||||
BlockPos blockPos = getPos().offset(direction);
|
||||
getWorld().markBlockForUpdate(blockPos);
|
||||
CableMultipart part = getPartFromWorld(getWorld(), blockPos, direction);
|
||||
if (part != null) {
|
||||
part.checkConnectedSides();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public CableMultipart getPartFromWorld(World world, BlockPos pos, EnumFacing side) {
|
||||
if(world == null || pos == null){
|
||||
return null;
|
||||
}
|
||||
IMultipartContainer container = MultipartHelper.getPartContainer(world, pos);
|
||||
if (side != null && container != null) {
|
||||
ISlottedPart slottedPart = container.getPartInSlot(PartSlot.getFaceSlot(side));
|
||||
if (slottedPart instanceof IMicroblock.IFaceMicroblock && !((IMicroblock.IFaceMicroblock) slottedPart).isFaceHollow()) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
if (container == null) {
|
||||
return null;
|
||||
}
|
||||
ISlottedPart part = container.getPartInSlot(PartSlot.CENTER);
|
||||
if (part instanceof CableMultipart) {
|
||||
return (CableMultipart) part;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdded() {
|
||||
nearByChange();
|
||||
}
|
||||
|
||||
public boolean shouldConnectTo(EnumFacing dir) {
|
||||
if (dir != null) {
|
||||
if (internalShouldConnectTo(dir)) {
|
||||
CableMultipart cableMultipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir);
|
||||
if (cableMultipart != null && cableMultipart.internalShouldConnectTo(dir.getOpposite())) {
|
||||
return true;
|
||||
}
|
||||
} else {
|
||||
TileEntity tile = getNeighbourTile(dir);
|
||||
|
||||
if (tile instanceof IEnergyInterfaceTile) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public boolean internalShouldConnectTo(EnumFacing dir) {
|
||||
ISlottedPart part = getContainer().getPartInSlot(PartSlot.getFaceSlot(dir));
|
||||
if (part instanceof IMicroblock.IFaceMicroblock) {
|
||||
if (!((IMicroblock.IFaceMicroblock) part).isFaceHollow()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if (!OcclusionHelper.occlusionTest(getContainer().getParts(), this, boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CableMultipart cableMultipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir.getOpposite());
|
||||
|
||||
if (cableMultipart != null && cableMultipart.getCableType() == getCableType()) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
public TileEntity getNeighbourTile(EnumFacing side) {
|
||||
return side != null ? getWorld().getTileEntity(getPos().offset(side)) : null;
|
||||
}
|
||||
|
||||
public void checkConnectedSides() {
|
||||
refreshBounding();
|
||||
connectedSides = new HashMap<>();
|
||||
for (EnumFacing dir : EnumFacing.values()) {
|
||||
int d = Functions.getIntDirFromDirection(dir);
|
||||
if (getWorld() == null) {
|
||||
return;
|
||||
}
|
||||
TileEntity te = getNeighbourTile(dir);
|
||||
if (shouldConnectTo(dir)) {
|
||||
connectedSides.put(dir, te.getPos());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public EnumSet<PartSlot> getSlotMask() {
|
||||
return EnumSet.of(PartSlot.CENTER);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void update() {
|
||||
if (getWorld() != null) {
|
||||
if (getWorld().getTotalWorldTime() % 80 == 0) {
|
||||
checkConnectedSides();
|
||||
}
|
||||
}
|
||||
if (network == null) {
|
||||
this.findAndJoinNetwork(getWorld(), getPos());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBlockState getExtendedState(IBlockState state) {
|
||||
IExtendedBlockState extendedBlockState = (IExtendedBlockState) state;
|
||||
return extendedBlockState
|
||||
.withProperty(DOWN, shouldConnectTo(EnumFacing.DOWN))
|
||||
.withProperty(UP, shouldConnectTo(EnumFacing.UP))
|
||||
.withProperty(NORTH, shouldConnectTo(EnumFacing.NORTH))
|
||||
.withProperty(SOUTH, shouldConnectTo(EnumFacing.SOUTH))
|
||||
.withProperty(WEST, shouldConnectTo(EnumFacing.WEST))
|
||||
.withProperty(EAST, shouldConnectTo(EnumFacing.EAST))
|
||||
.withProperty(TYPE, getCableType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockState createBlockState() {
|
||||
return new ExtendedBlockState(MCMultiPartMod.multipart,
|
||||
new IProperty[]{
|
||||
TYPE
|
||||
},
|
||||
new IUnlistedProperty[]{
|
||||
DOWN,
|
||||
UP,
|
||||
NORTH,
|
||||
SOUTH,
|
||||
WEST,
|
||||
EAST});
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String getModelPath() {
|
||||
return "techreborn:cable";
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHardness(PartMOP hit) {
|
||||
return 0.5F;
|
||||
}
|
||||
|
||||
public Material getMaterial() {
|
||||
return Material.cloth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<ItemStack> getDrops() {
|
||||
List<ItemStack> list = new ArrayList<>();
|
||||
list.add(new ItemStack(TechRebornParts.cables, 1, getCableType().ordinal()));
|
||||
return list;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void onEntityCollided(Entity entity) {
|
||||
if (getCableType().canKill && entity instanceof EntityLivingBase) {
|
||||
if(ConfigTechReborn.UninsulatedElectocutionDamage){
|
||||
entity.attackEntityFrom(new ElectrialShockSource(), 1F);
|
||||
}
|
||||
if(ConfigTechReborn.UninsulatedElectocutionSound){
|
||||
getWorld().playSoundAtEntity(entity, "techreborn:cable_shock", 0.6F, 1F);
|
||||
}
|
||||
if(ConfigTechReborn.UninsulatedElectocutionParticle){
|
||||
getWorld().spawnParticle(EnumParticleTypes.CRIT, entity.posX, entity.posY, entity.posZ, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityStanding(Entity entity) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(EntityPlayer player, PartMOP hit) {
|
||||
return new ItemStack(TechRebornParts.cables, 1, getCableType().ordinal());
|
||||
}
|
||||
|
||||
private TRPowerNet network;
|
||||
|
||||
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(EnumChatFormatting.GREEN + "EU Transfer: " + EnumChatFormatting.LIGHT_PURPLE + getCableType().transferRate);
|
||||
if (getCableType().canKill) {
|
||||
info.add(EnumChatFormatting.RED + "Damages entity's!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRenderInLayer(EnumWorldBlockLayer layer) {
|
||||
return layer == EnumWorldBlockLayer.CUTOUT;
|
||||
}
|
||||
}
|
|
@ -1,35 +0,0 @@
|
|||
package techreborn.client.render.parts;
|
||||
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraftforge.client.event.ModelBakeEvent;
|
||||
import net.minecraftforge.client.event.TextureStitchEvent;
|
||||
import net.minecraftforge.fml.common.eventhandler.EventPriority;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 04/03/2016.
|
||||
*/
|
||||
public class ClientPartModelBakery {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@SubscribeEvent(priority = EventPriority.LOWEST)
|
||||
public void onModelBake(ModelBakeEvent event){
|
||||
for(EnumCableType type : EnumCableType.values()){
|
||||
event.modelRegistry.putObject(new ModelResourceLocation("techreborn:cable#type=" + type.getName().toLowerCase()), new RenderCablePart(type));
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void textureStichEvent(TextureStitchEvent event){
|
||||
for(EnumCableType type : EnumCableType.values()){
|
||||
event.map.registerSprite(new ResourceLocation(type.textureName));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -1,89 +0,0 @@
|
|||
package techreborn.parts;
|
||||
|
||||
import mcmultipart.item.ItemMultiPart;
|
||||
import mcmultipart.multipart.IMultipart;
|
||||
import me.modmuss50.jsonDestroyer.api.ITexturedItem;
|
||||
import net.minecraft.client.resources.model.ModelResourceLocation;
|
||||
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.BlockPos;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.Vec3;
|
||||
import net.minecraft.world.World;
|
||||
import reborncore.RebornCore;
|
||||
import techreborn.client.TechRebornCreativeTab;
|
||||
import techreborn.lib.ModInfo;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 27/02/2016.
|
||||
*/
|
||||
public class ItemCables extends ItemMultiPart implements ITexturedItem {
|
||||
|
||||
public ItemCables() {
|
||||
setCreativeTab(TechRebornCreativeTab.instance);
|
||||
setHasSubtypes(true);
|
||||
setUnlocalizedName("techreborn.cable");
|
||||
setNoRepair();
|
||||
RebornCore.jsonDestroyer.registerObject(this);
|
||||
ItemStandaloneCables.mcPartCable = this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IMultipart createPart(World world, BlockPos pos, EnumFacing side, Vec3 hit, ItemStack stack, EntityPlayer player) {
|
||||
try {
|
||||
return TechRebornParts.multipartHashMap.get(EnumCableType.values()[stack.getItemDamage()]).newInstance();
|
||||
} catch (InstantiationException | IllegalAccessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
// gets Unlocalized Name depending on meta data
|
||||
public String getUnlocalizedName(ItemStack itemStack) {
|
||||
int meta = itemStack.getItemDamage();
|
||||
if (meta < 0 || meta >= EnumCableType.values().length) {
|
||||
meta = 0;
|
||||
}
|
||||
|
||||
return super.getUnlocalizedName() + "." + EnumCableType.values()[meta];
|
||||
}
|
||||
|
||||
// Adds Dusts SubItems To Creative Tab
|
||||
public void getSubItems(Item item, CreativeTabs creativeTabs, List list) {
|
||||
for (int meta = 0; meta < EnumCableType.values().length; ++meta) {
|
||||
list.add(new ItemStack(item, 1, meta));
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getTextureName(int damage) {
|
||||
return ModInfo.MOD_ID + ":items/cables/" + EnumCableType.values()[damage];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getMaxMeta() {
|
||||
return EnumCableType.values().length;
|
||||
}
|
||||
|
||||
@Override
|
||||
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!");
|
||||
}
|
||||
tooltip.add(EnumChatFormatting.GREEN + "Tier: " + EnumChatFormatting.LIGHT_PURPLE + type.tier);
|
||||
}
|
||||
}
|
|
@ -1,119 +0,0 @@
|
|||
package techreborn.client.render.parts;
|
||||
|
||||
import mcmultipart.client.multipart.ISmartMultipartModel;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.renderer.block.model.BakedQuad;
|
||||
import net.minecraft.client.renderer.block.model.BlockFaceUV;
|
||||
import net.minecraft.client.renderer.block.model.BlockPartFace;
|
||||
import net.minecraft.client.renderer.block.model.FaceBakery;
|
||||
import net.minecraft.client.renderer.block.model.ItemCameraTransforms;
|
||||
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
|
||||
import net.minecraft.client.resources.model.IBakedModel;
|
||||
import net.minecraft.client.resources.model.ModelRotation;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import org.lwjgl.util.vector.Vector3f;
|
||||
import reborncore.common.misc.vecmath.Vecs3dCube;
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
public class RenderCablePart implements ISmartMultipartModel {
|
||||
|
||||
private FaceBakery faceBakery = new FaceBakery();
|
||||
|
||||
private TextureAtlasSprite texture;
|
||||
|
||||
EnumCableType type;
|
||||
|
||||
IExtendedBlockState state;
|
||||
|
||||
public RenderCablePart(IExtendedBlockState state, EnumCableType type) {
|
||||
this(type);
|
||||
this.state = state;
|
||||
}
|
||||
|
||||
public RenderCablePart(EnumCableType type) {
|
||||
texture = Minecraft.getMinecraft().getTextureMapBlocks().getAtlasSprite(type.textureName);
|
||||
this.type = type;
|
||||
}
|
||||
|
||||
@Override
|
||||
public IBakedModel handlePartState(IBlockState state) {
|
||||
return new RenderCablePart((IExtendedBlockState) state, type);
|
||||
}
|
||||
|
||||
public void addCubeToList(Vecs3dCube cube, ArrayList<BakedQuad> list, BlockPartFace face, ModelRotation modelRotation, TextureAtlasSprite cubeTexture) {
|
||||
list.add(faceBakery.makeBakedQuad(new Vector3f((float) cube.getMinX(), (float) cube.getMinY(), (float) cube.getMinZ()), new Vector3f((float) cube.getMaxX(), (float) cube.getMinY(), (float) cube.getMaxZ()), face, cubeTexture, EnumFacing.DOWN, modelRotation, null, true, true));//down
|
||||
list.add(faceBakery.makeBakedQuad(new Vector3f((float) cube.getMinX(), (float) cube.getMaxY(), (float) cube.getMinZ()), new Vector3f((float) cube.getMaxX(), (float) cube.getMaxY(), (float) cube.getMaxZ()), face, cubeTexture, EnumFacing.UP, modelRotation, null, true, true));//up
|
||||
list.add(faceBakery.makeBakedQuad(new Vector3f((float) cube.getMinX(), (float) cube.getMinY(), (float) cube.getMinZ()), new Vector3f((float) cube.getMaxX(), (float) cube.getMaxY(), (float) cube.getMaxZ()), face, cubeTexture, EnumFacing.NORTH, modelRotation, null, true, true));//north
|
||||
list.add(faceBakery.makeBakedQuad(new Vector3f((float) cube.getMinX(), (float) cube.getMinY(), (float) cube.getMaxZ()), new Vector3f((float) cube.getMaxX(), (float) cube.getMaxY(), (float) cube.getMaxZ()), face, cubeTexture, EnumFacing.SOUTH, modelRotation, null, true, true));//south
|
||||
list.add(faceBakery.makeBakedQuad(new Vector3f((float) cube.getMaxX(), (float) cube.getMinY(), (float) cube.getMinZ()), new Vector3f((float) cube.getMaxX(), (float) cube.getMaxY(), (float) cube.getMaxZ()), face, cubeTexture, EnumFacing.EAST, modelRotation, null, true, true));//east
|
||||
list.add(faceBakery.makeBakedQuad(new Vector3f((float) cube.getMinX(), (float) cube.getMinY(), (float) cube.getMinZ()), new Vector3f((float) cube.getMinX(), (float) cube.getMaxY(), (float) cube.getMaxZ()), face, cubeTexture, EnumFacing.WEST, modelRotation, null, true, true));//west
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getFaceQuads(EnumFacing p_177551_1_) {
|
||||
return Collections.emptyList();
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<BakedQuad> getGeneralQuads() {
|
||||
ArrayList<BakedQuad> list = new ArrayList<BakedQuad>();
|
||||
BlockFaceUV uv = new BlockFaceUV(new float[]{0.0F, 0.0F, 16.0F, 16.0F}, 0);
|
||||
BlockPartFace face = new BlockPartFace(null, 0, "", uv);
|
||||
double thickness = type.cableThickness;
|
||||
double lastThickness = 16 - thickness;
|
||||
addCubeToList(new Vecs3dCube(thickness, thickness, thickness, lastThickness, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture);
|
||||
if (state != null) {
|
||||
if (state.getValue(CableMultipart.UP)) {
|
||||
addCubeToList(new Vecs3dCube(thickness, lastThickness, thickness, lastThickness, 16.0, lastThickness), list, face, ModelRotation.X0_Y0, texture);
|
||||
}
|
||||
if (state.getValue(CableMultipart.DOWN)) {
|
||||
addCubeToList(new Vecs3dCube(thickness, 0.0, thickness, lastThickness, thickness, lastThickness), list, face, ModelRotation.X0_Y0, texture);
|
||||
}
|
||||
if (state.getValue(CableMultipart.NORTH)) {
|
||||
addCubeToList(new Vecs3dCube(thickness, thickness, 0.0, lastThickness, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture);
|
||||
}
|
||||
if (state.getValue(CableMultipart.SOUTH)) {
|
||||
addCubeToList(new Vecs3dCube(thickness, thickness, thickness, lastThickness, lastThickness, 16.0), list, face, ModelRotation.X0_Y0, texture);
|
||||
}
|
||||
if (state.getValue(CableMultipart.EAST)) {
|
||||
addCubeToList(new Vecs3dCube(thickness, thickness, thickness, 16.0, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture);
|
||||
}
|
||||
if (state.getValue(CableMultipart.WEST)) {
|
||||
addCubeToList(new Vecs3dCube(0.0, thickness, thickness, lastThickness, lastThickness, lastThickness), list, face, ModelRotation.X0_Y0, texture);
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isAmbientOcclusion() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isGui3d() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isBuiltInRenderer() {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TextureAtlasSprite getParticleTexture() {
|
||||
return texture;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemCameraTransforms getItemCameraTransforms() {
|
||||
return ItemCameraTransforms.DEFAULT;
|
||||
}
|
||||
}
|
|
@ -1,236 +0,0 @@
|
|||
package techreborn.power;
|
||||
|
||||
import net.minecraft.entity.item.EntityTNTPrimed;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraftforge.common.MinecraftForge;
|
||||
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
||||
import reborncore.api.power.IEnergyInterfaceTile;
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class TRPowerNet {
|
||||
int tick = 0;
|
||||
private ArrayList<CableMultipart> cables = new ArrayList();
|
||||
public ArrayList<EnergyHandler> endpoints = new ArrayList();
|
||||
private int energy = 0;
|
||||
EnumCableType cableType;
|
||||
|
||||
public TRPowerNet(EnumCableType cableType) {
|
||||
this.cableType = cableType;
|
||||
MinecraftForge.EVENT_BUS.register(this);
|
||||
}
|
||||
|
||||
public int getIOLimit() {
|
||||
return cableType.transferRate;
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void tick(PowerTickEvent evt) {
|
||||
if (tick < 20) {
|
||||
tick++;
|
||||
return;
|
||||
}
|
||||
if (tick % 80 == 0) {
|
||||
List<CableMultipart> oldCables = new ArrayList<>();
|
||||
for (CableMultipart cableMultipart : cables) {
|
||||
if (cableMultipart.getWorld() == null || cableMultipart.getPos() == null) {
|
||||
oldCables.add(cableMultipart);
|
||||
}
|
||||
CableMultipart mp = cableMultipart.getPartFromWorld(cableMultipart.getWorld(), cableMultipart.getPos(), null);
|
||||
if (mp == null) {
|
||||
oldCables.add(cableMultipart);
|
||||
}
|
||||
}
|
||||
cables.removeAll(oldCables);
|
||||
}
|
||||
if (!cables.isEmpty()) {
|
||||
ArrayList<EnergyHandler> collectibles = new ArrayList();
|
||||
ArrayList<EnergyHandler> insertibles = new ArrayList();
|
||||
for (int i = 0; i < endpoints.size(); i++) {
|
||||
EnergyHandler ei = endpoints.get(i);
|
||||
if (ei.isCollectible()) {
|
||||
collectibles.add(ei);
|
||||
}
|
||||
if (ei.isInsertible()) {
|
||||
insertibles.add(ei);
|
||||
}
|
||||
}
|
||||
|
||||
for (EnergyHandler handler : collectibles) {
|
||||
energy += handler.collectEnergy(cableType.transferRate);
|
||||
}
|
||||
|
||||
for (EnergyHandler handler : insertibles) {
|
||||
energy -= handler.addEnergy(Math.min(energy, cableType.transferRate));
|
||||
}
|
||||
} else {
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
}
|
||||
tick++;
|
||||
}
|
||||
|
||||
public void addElement(CableMultipart te) {
|
||||
if (!cables.contains(te)) {
|
||||
cables.add(te);
|
||||
}
|
||||
}
|
||||
|
||||
public void removeElement(CableMultipart te) {
|
||||
cables.remove(te);
|
||||
this.rebuild();
|
||||
}
|
||||
|
||||
private void rebuild() {
|
||||
for (int i = 0; i < cables.size(); i++) {
|
||||
CableMultipart te = cables.get(i);
|
||||
te.setNetwork(null);
|
||||
te.findAndJoinNetwork(te.getWorld(), te.getPos());
|
||||
}
|
||||
this.clear(true);
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
}
|
||||
|
||||
public void addConnection(IEnergyInterfaceTile ih, EnumFacing dir) {
|
||||
if (ih instanceof CableMultipart)
|
||||
return;
|
||||
EnergyHandler has = this.getHandleFrom(ih);
|
||||
if (has == null) {
|
||||
endpoints.add(new EnergyHandler(ih, cableType, dir));
|
||||
} else {
|
||||
has.side = dir;
|
||||
}
|
||||
}
|
||||
|
||||
public void merge(TRPowerNet n) {
|
||||
if (n != this) {
|
||||
ArrayList<CableMultipart> li = new ArrayList();
|
||||
for (int i = 0; i < n.cables.size(); i++) {
|
||||
CableMultipart wire = n.cables.get(i);
|
||||
li.add(wire);
|
||||
}
|
||||
for (int i = 0; i < n.endpoints.size(); i++) {
|
||||
EnergyHandler ei = n.endpoints.get(i);
|
||||
EnergyHandler has = this.getHandleFrom(ei.tile);
|
||||
if (has == null) {
|
||||
endpoints.add(ei);
|
||||
}
|
||||
}
|
||||
n.clear(false);
|
||||
for (int i = 0; i < li.size(); i++) {
|
||||
CableMultipart wire = li.get(i);
|
||||
wire.setNetwork(this);
|
||||
}
|
||||
MinecraftForge.EVENT_BUS.unregister(n);
|
||||
}
|
||||
}
|
||||
|
||||
private EnergyHandler getHandleFrom(IEnergyInterfaceTile tile) {
|
||||
for (int i = 0; i < endpoints.size(); i++) {
|
||||
EnergyHandler ei = endpoints.get(i);
|
||||
if (ei.contains(tile))
|
||||
return ei;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private void clear(boolean clearTiles) {
|
||||
if (clearTiles) {
|
||||
for (int i = 0; i < cables.size(); i++) {
|
||||
cables.get(i).resetNetwork();
|
||||
}
|
||||
}
|
||||
|
||||
cables.clear();
|
||||
endpoints.clear();
|
||||
energy = 0;
|
||||
|
||||
MinecraftForge.EVENT_BUS.unregister(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return cables.size() + ": " + endpoints.toString();
|
||||
}
|
||||
|
||||
public int addEnergy(int maxAdd, boolean simulate) {
|
||||
if (energy >= this.getIOLimit())
|
||||
return 0;
|
||||
maxAdd = Math.min(this.getIOLimit(), maxAdd);
|
||||
if (!simulate)
|
||||
energy += maxAdd;
|
||||
return maxAdd;
|
||||
}
|
||||
|
||||
private static class EnergyHandler {
|
||||
private final IEnergyInterfaceTile tile;
|
||||
private EnumFacing side;
|
||||
private final EnumCableType type;
|
||||
|
||||
private EnergyHandler(IEnergyInterfaceTile ih, EnumCableType type, EnumFacing dir) {
|
||||
tile = ih;
|
||||
this.type = type;
|
||||
this.side = dir;
|
||||
}
|
||||
|
||||
public boolean isInsertible() {
|
||||
return this.getTotalInsertible() > 0;
|
||||
}
|
||||
|
||||
public boolean isCollectible() {
|
||||
return this.getTotalCollectible() > 0;
|
||||
}
|
||||
|
||||
public boolean contains(IEnergyInterfaceTile tile) {
|
||||
return tile == this.tile;
|
||||
}
|
||||
|
||||
public int collectEnergy(int max) {
|
||||
int total = 0;
|
||||
if (tile.canProvideEnergy(EnumFacing.NORTH)) {
|
||||
int collect = (int) Math.min(max, tile.getMaxOutput());
|
||||
total = (int) tile.useEnergy(collect, false);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public int addEnergy(int max) {
|
||||
int total = 0;
|
||||
if (tile.canAcceptEnergy(EnumFacing.NORTH) && max > 0) {
|
||||
if (type.tier.ordinal() > tile.getTier().ordinal()) {
|
||||
if (tile instanceof TileEntity) {
|
||||
((TileEntity) tile).getWorld().createExplosion(new EntityTNTPrimed(((TileEntity) tile).getWorld()), ((TileEntity) tile).getPos().getX(), ((TileEntity) tile).getPos().getY(), ((TileEntity) tile).getPos().getZ(), 2.5F, true);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
int add = max - total;
|
||||
total += tile.addEnergy(add, false);
|
||||
}
|
||||
return total;
|
||||
}
|
||||
|
||||
public int getTotalCollectible() {
|
||||
if (tile.canProvideEnergy(EnumFacing.NORTH)) {
|
||||
return (int) Math.min(tile.getMaxOutput(), tile.getEnergy());
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
public int getTotalInsertible() {
|
||||
int total = 0;
|
||||
if (tile.canAcceptEnergy(EnumFacing.NORTH)) {
|
||||
total += tile.addEnergy(type.transferRate, true);
|
||||
}
|
||||
|
||||
return total;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return tile + " @ " + side;
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1,50 +0,0 @@
|
|||
package techreborn.parts;
|
||||
|
||||
import mcmultipart.multipart.MultipartRegistry;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
||||
import net.minecraftforge.fml.common.registry.GameRegistry;
|
||||
import techreborn.compat.ICompatModule;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
import java.util.HashMap;
|
||||
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 02/03/2016.
|
||||
*/
|
||||
public class TechRebornParts implements ICompatModule {
|
||||
|
||||
@Nullable
|
||||
public static Item cables;
|
||||
|
||||
public static HashMap<EnumCableType, Class<? extends CableMultipart>> multipartHashMap = new HashMap<>();
|
||||
|
||||
@Override
|
||||
public void preInit(FMLPreInitializationEvent event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void init(FMLInitializationEvent event) {
|
||||
for (EnumCableType cableType : EnumCableType.values()) {
|
||||
multipartHashMap.put(cableType, cableType.cableClass);
|
||||
MultipartRegistry.registerPart(cableType.cableClass, "techreborn:cable." + cableType.name());
|
||||
}
|
||||
cables = new ItemCables();
|
||||
GameRegistry.registerItem(cables, "cables");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void postInit(FMLPostInitializationEvent event) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void serverStarting(FMLServerStartingEvent event) {
|
||||
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package techreborn.parts.types;
|
||||
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class CopperCable extends CableMultipart {
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return EnumCableType.COPPER;
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package techreborn.parts.types;
|
||||
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class GlassFiberCable extends CableMultipart {
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return EnumCableType.GLASSFIBER;
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package techreborn.parts.types;
|
||||
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class GoldCable extends CableMultipart {
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return EnumCableType.GOLD;
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package techreborn.parts.types;
|
||||
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class HVCable extends CableMultipart {
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return EnumCableType.HV;
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package techreborn.parts.types;
|
||||
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class InsulatedCopperCable extends CableMultipart {
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return EnumCableType.ICOPPER;
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package techreborn.parts.types;
|
||||
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class InsulatedGoldCable extends CableMultipart {
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return EnumCableType.IGOLD;
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package techreborn.parts.types;
|
||||
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class InsulatedHVCable extends CableMultipart {
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return EnumCableType.IHV;
|
||||
}
|
||||
}
|
|
@ -1,14 +0,0 @@
|
|||
package techreborn.parts.types;
|
||||
|
||||
import techreborn.parts.CableMultipart;
|
||||
import techreborn.parts.EnumCableType;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 05/03/2016.
|
||||
*/
|
||||
public class TinCable extends CableMultipart {
|
||||
@Override
|
||||
public EnumCableType getCableType() {
|
||||
return EnumCableType.COPPER;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue