Update walia, add MT and CT support back, Fix #519, update for new RC bucket thing
This commit is contained in:
parent
4fccaa1f5f
commit
b822cee9fb
39 changed files with 383 additions and 2398 deletions
|
@ -1,19 +1,8 @@
|
|||
package techreborn.parts;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.EnumSet;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import mcmultipart.MCMultiPartMod;
|
||||
import mcmultipart.microblock.IMicroblock;
|
||||
import mcmultipart.multipart.IMultipartContainer;
|
||||
import mcmultipart.multipart.INormallyOccludingPart;
|
||||
import mcmultipart.multipart.ISlottedPart;
|
||||
import mcmultipart.multipart.Multipart;
|
||||
import mcmultipart.multipart.MultipartHelper;
|
||||
import mcmultipart.multipart.PartSlot;
|
||||
import mcmultipart.multipart.*;
|
||||
import mcmultipart.raytrace.PartMOP;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
|
@ -27,13 +16,10 @@ 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.BlockRenderLayer;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.EnumParticleTypes;
|
||||
import net.minecraft.util.ITickable;
|
||||
import net.minecraft.util.ResourceLocation;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.text.TextFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.property.ExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
|
@ -44,396 +30,392 @@ import reborncore.common.misc.Functions;
|
|||
import reborncore.common.misc.vecmath.Vecs3dCube;
|
||||
import reborncore.common.util.WorldUtils;
|
||||
import techreborn.config.ConfigTechReborn;
|
||||
import techreborn.parts.walia.IPartWaliaProvider;
|
||||
import techreborn.power.TRPowerNet;
|
||||
import techreborn.utils.damageSources.ElectrialShockSource;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 02/03/2016.
|
||||
*/
|
||||
public abstract class CableMultipart extends Multipart
|
||||
implements INormallyOccludingPart, ISlottedPart, ITickable, ICableType {
|
||||
implements INormallyOccludingPart, ISlottedPart, ITickable, ICableType, IPartWaliaProvider {
|
||||
|
||||
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 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 TRPowerNet mergeWith = null;
|
||||
private TRPowerNet network;
|
||||
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 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 TRPowerNet mergeWith = null;
|
||||
private TRPowerNet network;
|
||||
|
||||
public CableMultipart() {
|
||||
connectedSides = new HashMap<>();
|
||||
refreshBounding();
|
||||
}
|
||||
public CableMultipart() {
|
||||
connectedSides = new HashMap<>();
|
||||
refreshBounding();
|
||||
}
|
||||
|
||||
public static 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;
|
||||
}
|
||||
}
|
||||
public static 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;
|
||||
}
|
||||
if (container == null) {
|
||||
return null;
|
||||
}
|
||||
ISlottedPart part = container.getPartInSlot(PartSlot.CENTER);
|
||||
if (part instanceof CableMultipart) {
|
||||
return (CableMultipart) part;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public void refreshBounding() {
|
||||
float centerFirst = center - offset;
|
||||
double w = (getCableType().cableThickness / 16) - 0.5;
|
||||
boundingBoxes[6] = new Vecs3dCube(centerFirst - w, centerFirst - w, centerFirst - w, centerFirst + w,
|
||||
centerFirst + w, centerFirst + w);
|
||||
public void refreshBounding() {
|
||||
float centerFirst = center - offset;
|
||||
double w = (getCableType().cableThickness / 16) - 0.5;
|
||||
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));
|
||||
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 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));
|
||||
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++;
|
||||
}
|
||||
}
|
||||
boundingBoxes[i] = new Vecs3dCube(xMin1, yMin1, zMin1, xMax1, yMax1, zMax1);
|
||||
i++;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addCollisionBoxes(AxisAlignedBB mask, List<AxisAlignedBB> list, Entity collidingEntity) {
|
||||
@Override
|
||||
public void addCollisionBoxes(AxisAlignedBB mask, List<AxisAlignedBB> list, Entity 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());
|
||||
}
|
||||
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());
|
||||
}
|
||||
super.addCollisionBoxes(mask, list, collidingEntity);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addSelectionBoxes(List<AxisAlignedBB> list) {
|
||||
@Override
|
||||
public void addSelectionBoxes(List<AxisAlignedBB> list) {
|
||||
|
||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||
if (connectedSides.containsKey(dir))
|
||||
list.add(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB());
|
||||
}
|
||||
list.add(boundingBoxes[6].toAABB());
|
||||
super.addSelectionBoxes(list);
|
||||
}
|
||||
for (EnumFacing dir : EnumFacing.VALUES) {
|
||||
if (connectedSides.containsKey(dir))
|
||||
list.add(boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB());
|
||||
}
|
||||
list.add(boundingBoxes[6].toAABB());
|
||||
super.addSelectionBoxes(list);
|
||||
}
|
||||
|
||||
@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 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 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 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();
|
||||
@Override
|
||||
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);
|
||||
WorldUtils.updateBlock(getWorld(), blockPos);
|
||||
CableMultipart part = getPartFromWorld(getWorld(), blockPos, direction);
|
||||
if (part != null) {
|
||||
part.checkConnectedSides();
|
||||
}
|
||||
}
|
||||
TRPowerNet.buildEndpoint(network);
|
||||
}
|
||||
public void nearByChange() {
|
||||
if (network == null) {
|
||||
findAndJoinNetwork(getWorld(), getPos());
|
||||
}
|
||||
checkConnectedSides();
|
||||
for (EnumFacing direction : EnumFacing.VALUES) {
|
||||
BlockPos blockPos = getPos().offset(direction);
|
||||
WorldUtils.updateBlock(getWorld(), blockPos);
|
||||
CableMultipart part = getPartFromWorld(getWorld(), blockPos, direction);
|
||||
if (part != null) {
|
||||
part.checkConnectedSides();
|
||||
}
|
||||
}
|
||||
TRPowerNet.buildEndpoint(network);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAdded() {
|
||||
nearByChange();
|
||||
}
|
||||
@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);
|
||||
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;
|
||||
}
|
||||
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;
|
||||
}
|
||||
}
|
||||
public boolean internalShouldConnectTo(EnumFacing dir) {
|
||||
ISlottedPart part = getContainer().getPartInSlot(PartSlot.getFaceSlot(dir));
|
||||
if (part instanceof IMicroblock.IFaceMicroblock) {
|
||||
if (!((IMicroblock.IFaceMicroblock) part).isFaceHollow()) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
// TODO 1.9 boken
|
||||
// if (!OcclusionHelper.occlusionTest(this,
|
||||
// boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB())) {
|
||||
// return false;
|
||||
// }
|
||||
if (!OcclusionHelper.occlusionTest(getContainer().getParts(), p -> p == this, boundingBoxes[Functions.getIntDirFromDirection(dir)].toAABB())) {
|
||||
return false;
|
||||
}
|
||||
|
||||
CableMultipart cableMultipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir.getOpposite());
|
||||
CableMultipart cableMultipart = getPartFromWorld(getWorld(), getPos().offset(dir), dir.getOpposite());
|
||||
|
||||
return cableMultipart != null && cableMultipart.getCableType() == getCableType();
|
||||
}
|
||||
return cableMultipart != null && cableMultipart.getCableType() == getCableType();
|
||||
}
|
||||
|
||||
public TileEntity getNeighbourTile(EnumFacing side) {
|
||||
return side != null ? getWorld().getTileEntity(getPos().offset(side)) : null;
|
||||
}
|
||||
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());
|
||||
}
|
||||
}
|
||||
}
|
||||
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 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());
|
||||
} else {
|
||||
if (mergeWith != null) {
|
||||
getNetwork().merge(network);
|
||||
mergeWith = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void update() {
|
||||
if (getWorld() != null) {
|
||||
if (getWorld().getTotalWorldTime() % 80 == 0) {
|
||||
checkConnectedSides();
|
||||
}
|
||||
}
|
||||
if (network == null) {
|
||||
this.findAndJoinNetwork(getWorld(), getPos());
|
||||
} else {
|
||||
if (mergeWith != null) {
|
||||
getNetwork().merge(network);
|
||||
mergeWith = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@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 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 String getModelPath() {
|
||||
// return "techreborn:cable";
|
||||
// }
|
||||
@Override
|
||||
public BlockStateContainer createBlockState() {
|
||||
return new ExtendedBlockState(MCMultiPartMod.multipart, new IProperty[]{TYPE},
|
||||
new IUnlistedProperty[]{DOWN, UP, NORTH, SOUTH, WEST, EAST});
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockStateContainer createBlockState() {
|
||||
return new ExtendedBlockState(MCMultiPartMod.multipart, new IProperty[] { TYPE },
|
||||
new IUnlistedProperty[] { DOWN, UP, NORTH, SOUTH, WEST, EAST });
|
||||
}
|
||||
@Override
|
||||
public float getHardness(PartMOP hit) {
|
||||
return 0.5F;
|
||||
}
|
||||
|
||||
@Override
|
||||
public float getHardness(PartMOP hit) {
|
||||
return 0.5F;
|
||||
}
|
||||
public Material getMaterial() {
|
||||
return Material.cloth;
|
||||
}
|
||||
|
||||
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 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 (entity instanceof EntityPlayer && ((EntityPlayer) entity).capabilities.isCreativeMode) {
|
||||
|
||||
@Override
|
||||
public void onEntityCollided(Entity entity) {
|
||||
if (getCableType().canKill && entity instanceof EntityLivingBase) {
|
||||
if (entity instanceof EntityPlayer && ((EntityPlayer) entity).capabilities.isCreativeMode) {
|
||||
|
||||
} else {
|
||||
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(entity.posX, entity.posY,
|
||||
// entity.posZ, ModSounds.shock,
|
||||
// SoundCategory.BLOCKS, 0.6F, 1F, false);
|
||||
}
|
||||
if (ConfigTechReborn.UninsulatedElectocutionParticle) {
|
||||
getWorld().spawnParticle(EnumParticleTypes.CRIT, entity.posX, entity.posY, entity.posZ, 0,
|
||||
0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
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(entity.posX, entity.posY,
|
||||
// entity.posZ, ModSounds.shock,
|
||||
// SoundCategory.BLOCKS, 0.6F, 1F, false);
|
||||
}
|
||||
if (ConfigTechReborn.UninsulatedElectocutionParticle) {
|
||||
getWorld().spawnParticle(EnumParticleTypes.CRIT, entity.posX, entity.posY, entity.posZ, 0,
|
||||
0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onEntityStanding(Entity entity) {
|
||||
@Override
|
||||
public void onEntityStanding(Entity entity) {
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack getPickBlock(EntityPlayer player, PartMOP hit) {
|
||||
return new ItemStack(TechRebornParts.cables, 1, getCableType().ordinal());
|
||||
}
|
||||
@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 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 TRPowerNet getNetwork() {
|
||||
return network;
|
||||
}
|
||||
|
||||
public final void setNetwork(TRPowerNet n) {
|
||||
if (n == null) {
|
||||
} else {
|
||||
network = n;
|
||||
network.addElement(this);
|
||||
}
|
||||
}
|
||||
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 removeFromNetwork() {
|
||||
if (network == null) {
|
||||
} else
|
||||
network.removeElement(this);
|
||||
}
|
||||
|
||||
public final void rebuildNetwork() {
|
||||
this.removeFromNetwork();
|
||||
this.resetNetwork();
|
||||
this.findAndJoinNetwork(getWorld(), getPos());
|
||||
}
|
||||
public final void rebuildNetwork() {
|
||||
this.removeFromNetwork();
|
||||
this.resetNetwork();
|
||||
this.findAndJoinNetwork(getWorld(), getPos());
|
||||
}
|
||||
|
||||
public final void resetNetwork() {
|
||||
if (network != null) {
|
||||
network.removeElement(this);
|
||||
}
|
||||
public final void resetNetwork() {
|
||||
if (network != null) {
|
||||
network.removeElement(this);
|
||||
}
|
||||
|
||||
network = null;
|
||||
}
|
||||
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 void addInfo(List<String> info) {
|
||||
info.add(TextFormatting.GREEN + "EU Transfer: " +
|
||||
TextFormatting.LIGHT_PURPLE + getCableType().transferRate);
|
||||
if (getCableType().canKill) {
|
||||
info.add(TextFormatting.RED + "Damages entity's!");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public ResourceLocation getModelPath() {
|
||||
return new ResourceLocation("techreborn:cable");
|
||||
}
|
||||
@Override
|
||||
public ResourceLocation getModelPath() {
|
||||
return new ResourceLocation("techreborn:cable");
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canRenderInLayer(BlockRenderLayer layer) {
|
||||
return layer == BlockRenderLayer.CUTOUT;
|
||||
}
|
||||
@Override
|
||||
public boolean canRenderInLayer(BlockRenderLayer layer) {
|
||||
return layer == BlockRenderLayer.CUTOUT;
|
||||
}
|
||||
}
|
||||
|
|
12
src/main/java/techreborn/parts/walia/IPartWaliaProvider.java
Normal file
12
src/main/java/techreborn/parts/walia/IPartWaliaProvider.java
Normal file
|
@ -0,0 +1,12 @@
|
|||
package techreborn.parts.walia;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 07/03/2016.
|
||||
*/
|
||||
public interface IPartWaliaProvider
|
||||
{
|
||||
|
||||
void addInfo(List<String> info);
|
||||
}
|
|
@ -0,0 +1,45 @@
|
|||
package techreborn.parts.walia;
|
||||
|
||||
import mcmultipart.block.TileMultipartContainer;
|
||||
import mcp.mobius.waila.api.IWailaRegistrar;
|
||||
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLInterModComms;
|
||||
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
||||
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
||||
import techreborn.compat.ICompatModule;
|
||||
|
||||
/**
|
||||
* Created by modmuss50 on 07/03/2016.
|
||||
*/
|
||||
public class WailaMcMultiPartCompact implements ICompatModule
|
||||
{
|
||||
public static void callbackRegister(IWailaRegistrar registrar)
|
||||
{
|
||||
registrar.registerBodyProvider(new WaliaPartProvider(), TileMultipartContainer.class);
|
||||
}
|
||||
|
||||
@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)
|
||||
{
|
||||
|
||||
}
|
||||
}
|
97
src/main/java/techreborn/parts/walia/WaliaPartProvider.java
Normal file
97
src/main/java/techreborn/parts/walia/WaliaPartProvider.java
Normal file
|
@ -0,0 +1,97 @@
|
|||
package techreborn.parts.walia;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import mcmultipart.block.TileMultipartContainer;
|
||||
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.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import techreborn.parts.CableMultipart;
|
||||
|
||||
/**
|
||||
* 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)
|
||||
{
|
||||
Vec3d start = RayTraceUtils.getStart(player);
|
||||
Vec3d end = RayTraceUtils.getEnd(player);
|
||||
RayTraceUtils.AdvancedRayTraceResultPart 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 TileMultipartContainer getMultipartTile(IBlockAccess world, BlockPos pos)
|
||||
{
|
||||
TileEntity tile = world.getTileEntity(pos);
|
||||
return tile instanceof TileMultipartContainer ? (TileMultipartContainer) tile : null;
|
||||
}
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue