Search in sources :

Example 1 with IPartInfo

use of mcmultipart.api.container.IPartInfo in project Charset by CharsetMC.

the class WireHighlightHandler method drawWireHighlight.

@SubscribeEvent
public void drawWireHighlight(DrawBlockHighlightEvent event) {
    if (event.getTarget() != null && event.getTarget().typeOfHit == RayTraceResult.Type.BLOCK) {
        Wire wire;
        BlockPos pos = event.getTarget().getBlockPos();
        if (event.getTarget().hitInfo instanceof IPartInfo) {
            wire = WireUtils.getAnyWire(((IPartInfo) event.getTarget().hitInfo).getTile().getTileEntity());
        } else {
            wire = WireUtils.getAnyWire(event.getPlayer().getEntityWorld(), pos);
        }
        if (wire != null) {
            event.setCanceled(true);
            int lineMaskCenter = 0xFFF;
            EnumFacing[] faces = WireUtils.getConnectionsForRender(wire.getLocation());
            GlStateManager.pushMatrix();
            GlStateManager.translate(pos.getX(), pos.getY(), pos.getZ());
            for (int i = 0; i < faces.length; i++) {
                EnumFacing face = faces[i];
                if (wire.connectsAny(face)) {
                    int lineMask = 0xfff;
                    lineMask &= ~RenderUtils.getSelectionMask(face.getOpposite());
                    RenderUtils.drawSelectionBoundingBox(wire.getFactory().getSelectionBox(wire.getLocation(), i + 1), lineMask);
                    lineMaskCenter &= ~RenderUtils.getSelectionMask(face);
                }
            }
            if (lineMaskCenter != 0) {
                RenderUtils.drawSelectionBoundingBox(wire.getFactory().getSelectionBox(wire.getLocation(), 0), lineMaskCenter);
            }
            GlStateManager.popMatrix();
        }
    }
}
Also used : IPartInfo(mcmultipart.api.container.IPartInfo) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 2 with IPartInfo

use of mcmultipart.api.container.IPartInfo in project Charset by CharsetMC.

the class BlockWire method requestNeighborUpdate.

public void requestNeighborUpdate(World world, BlockPos pos, WireFace location, int connectionMask) {
    if ((connectionMask & 0xFF) != 0 && world instanceof IMultipartWorld) {
        IPartInfo info = ((IMultipartWorld) world).getPartInfo();
        info.getContainer().notifyChange(info);
    }
    for (EnumFacing facing : EnumFacing.VALUES) {
        if (world.isRemote) {
            if ((connectionMask & (1 << (facing.ordinal() + 8))) != 0) {
                WireUtils.getAllWires(world, pos.offset(facing)).forEach((wire) -> wire.onChanged(true));
            } else if (location != WireFace.CENTER && location.facing.getAxis() != facing.getAxis()) {
                WireUtils.getAllWires(world, pos.offset(facing).offset(location.facing)).forEach((wire) -> wire.onChanged(true));
            }
        } else {
            if ((connectionMask & (1 << (facing.ordinal() + 8))) != 0) {
                world.neighborChanged(pos.offset(facing), this, pos);
            } else if (location != WireFace.CENTER && location.facing.getAxis() != facing.getAxis()) {
                world.neighborChanged(pos.offset(facing).offset(location.facing), this, pos);
            }
        }
    }
}
Also used : IExtendedBlockState(net.minecraftforge.common.property.IExtendedBlockState) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) BlockStateContainer(net.minecraft.block.state.BlockStateContainer) IPartInfo(mcmultipart.api.container.IPartInfo) ExtendedBlockState(net.minecraftforge.common.property.ExtendedBlockState) BlockBase(pl.asie.charset.lib.block.BlockBase) IPartSlot(mcmultipart.api.slot.IPartSlot) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) IProperty(net.minecraft.block.properties.IProperty) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) Side(net.minecraftforge.fml.relauncher.Side) IMultipartWorld(mcmultipart.api.world.IMultipartWorld) IUnlistedProperty(net.minecraftforge.common.property.IUnlistedProperty) CreativeTabs(net.minecraft.creativetab.CreativeTabs) NonNullList(net.minecraft.util.NonNullList) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) EnumCenterSlot(mcmultipart.api.slot.EnumCenterSlot) IBlockAccess(net.minecraft.world.IBlockAccess) Nullable(javax.annotation.Nullable) SoundType(net.minecraft.block.SoundType) World(net.minecraft.world.World) PropertyBool(net.minecraft.block.properties.PropertyBool) EnumFacing(net.minecraft.util.EnumFacing) ITileEntityProvider(net.minecraft.block.ITileEntityProvider) BlockPos(net.minecraft.util.math.BlockPos) BlockRenderLayer(net.minecraft.util.BlockRenderLayer) IBlockState(net.minecraft.block.state.IBlockState) IMultipart(mcmultipart.api.multipart.IMultipart) List(java.util.List) Material(net.minecraft.block.material.Material) EntityLivingBase(net.minecraft.entity.EntityLivingBase) IMultipartBase(pl.asie.charset.lib.modcompat.mcmultipart.IMultipartBase) TileEntity(net.minecraft.tileentity.TileEntity) EnumFaceSlot(mcmultipart.api.slot.EnumFaceSlot) WireFace(pl.asie.charset.api.wires.WireFace) Collections(java.util.Collections) IPartInfo(mcmultipart.api.container.IPartInfo) EnumFacing(net.minecraft.util.EnumFacing) IMultipartWorld(mcmultipart.api.world.IMultipartWorld)

Example 3 with IPartInfo

use of mcmultipart.api.container.IPartInfo in project LogisticsPipes by RS485.

the class LPMicroblockBlock method addHitEffects.

@Override
@SideOnly(Side.CLIENT)
@ModDependentMethod(modId = LPConstants.mcmpModID)
public boolean addHitEffects(IBlockState mpState, World world, RayTraceResult hit, ParticleManager manager) {
    if (hit != null && hit.subHit >= 0) {
        BlockPos pos = hit.getBlockPos();
        IPartInfo part = getTile(world, pos).get().get(MCMultiPart.slotRegistry.getValue(hit.subHit)).get();
        if (!part.getPart().addHitEffects(part, (RayTraceResult) hit.hitInfo, manager)) {
            if (part.getPart().getRenderType(part) != EnumBlockRenderType.INVISIBLE) {
                int x = pos.getX(), y = pos.getY(), z = pos.getZ();
                AxisAlignedBB aabb = part.getPart().getBoundingBox(part);
                double pX = x + world.rand.nextDouble() * (aabb.maxX - aabb.minX - 0.2) + 0.1 + aabb.minX;
                double pY = y + world.rand.nextDouble() * (aabb.maxY - aabb.minY - 0.2) + 0.1 + aabb.minY;
                double pZ = z + world.rand.nextDouble() * (aabb.maxZ - aabb.minZ - 0.2) + 0.1 + aabb.minZ;
                switch(hit.sideHit) {
                    case DOWN:
                        pY = y + aabb.minY - 0.1;
                        break;
                    case UP:
                        pY = y + aabb.maxY + 0.1;
                        break;
                    case NORTH:
                        pZ = z + aabb.minZ - 0.1;
                        break;
                    case SOUTH:
                        pZ = z + aabb.maxZ + 0.1;
                        break;
                    case WEST:
                        pX = x + aabb.minX - 0.1;
                        break;
                    case EAST:
                        pX = x + aabb.maxX + 0.1;
                        break;
                }
                manager.addEffect(new ParticleDigging(world, pX, pY, pZ, 0.0D, 0.0D, 0.0D, part.getPart().getActualState(part.getPartWorld(), pos, part)) {
                }.setBlockPos(pos).multiplyVelocity(0.2F).multipleParticleScaleBy(0.6F));
            }
        }
        return true;
    }
    return false;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IPartInfo(mcmultipart.api.container.IPartInfo) RayTraceResult(net.minecraft.util.math.RayTraceResult) BlockPos(net.minecraft.util.math.BlockPos) ParticleDigging(net.minecraft.client.particle.ParticleDigging) ModDependentMethod(logisticspipes.asm.ModDependentMethod) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 4 with IPartInfo

use of mcmultipart.api.container.IPartInfo in project Charset by CharsetMC.

the class WireUtils method getAllWires.

public static Collection<Wire> getAllWires(IBlockAccess access, BlockPos pos) {
    Optional<IMultipartContainer> containerOpt = MultipartHelper.getContainer(access, pos);
    if (containerOpt.isPresent()) {
        IMultipartContainer container = containerOpt.get();
        Collection<Wire> wires = new ArrayList<>();
        for (IPartInfo partInfo : container.getParts().values()) {
            if (partInfo.getTile() instanceof TileWire) {
                wires.add(((TileWire) partInfo.getTile()).wire);
            }
        }
        return wires;
    } else {
        TileEntity tile = access.getTileEntity(pos);
        if (tile instanceof TileWire) {
            return Collections.singleton(((TileWire) tile).wire);
        } else {
            return Collections.emptySet();
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IMultipartContainer(mcmultipart.api.container.IMultipartContainer) IPartInfo(mcmultipart.api.container.IPartInfo) ArrayList(java.util.ArrayList)

Example 5 with IPartInfo

use of mcmultipart.api.container.IPartInfo in project Charset by CharsetMC.

the class ItemWrench method tryRotateMultipart.

@net.minecraftforge.fml.common.Optional.Method(modid = "mcmultipart")
public EnumActionResult tryRotateMultipart(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing targetFacing) {
    Optional<IMultipartContainer> uio = MultipartHelper.getContainer(worldIn, pos);
    if (uio.isPresent()) {
        IMultipartContainer ui = uio.get();
        Vec3d start = RayTraceUtils.getStart(playerIn);
        Vec3d end = RayTraceUtils.getEnd(playerIn);
        double dist = Double.POSITIVE_INFINITY;
        IPartInfo part = null;
        for (IPartInfo p : ui.getParts().values()) {
            RayTraceResult pResult = p.getPart().collisionRayTrace(p, start, end);
            if (pResult != null && pResult.hitVec != null) {
                double d = pResult.hitVec.squareDistanceTo(start);
                if (d <= dist) {
                    dist = d;
                    part = p;
                }
            }
        }
        if (part != null) {
            // TODO return ... ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
            return EnumActionResult.FAIL;
        } else {
            return EnumActionResult.FAIL;
        }
    } else {
        return EnumActionResult.PASS;
    }
}
Also used : IMultipartContainer(mcmultipart.api.container.IMultipartContainer) IPartInfo(mcmultipart.api.container.IPartInfo) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d)

Aggregations

IPartInfo (mcmultipart.api.container.IPartInfo)6 RayTraceResult (net.minecraft.util.math.RayTraceResult)4 BlockPos (net.minecraft.util.math.BlockPos)3 Vec3d (net.minecraft.util.math.Vec3d)3 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)3 ModDependentMethod (logisticspipes.asm.ModDependentMethod)2 IMultipartContainer (mcmultipart.api.container.IMultipartContainer)2 IBlockState (net.minecraft.block.state.IBlockState)2 ParticleDigging (net.minecraft.client.particle.ParticleDigging)2 TileEntity (net.minecraft.tileentity.TileEntity)2 EnumFacing (net.minecraft.util.EnumFacing)2 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)2 ArrayList (java.util.ArrayList)1 Collections (java.util.Collections)1 List (java.util.List)1 Nullable (javax.annotation.Nullable)1 IMultipart (mcmultipart.api.multipart.IMultipart)1 EnumCenterSlot (mcmultipart.api.slot.EnumCenterSlot)1 EnumFaceSlot (mcmultipart.api.slot.EnumFaceSlot)1 IPartSlot (mcmultipart.api.slot.IPartSlot)1