Search in sources :

Example 1 with TileMultipartContainer

use of mcmultipart.block.TileMultipartContainer in project LogisticsPipes by RS485.

the class MCMPProxy method onDrawHighlight.

@SubscribeEvent
@SideOnly(Side.CLIENT)
public void onDrawHighlight(DrawBlockHighlightEvent event) {
    if (event instanceof DrawMultipartHighlightEvent) {
        return;
    }
    RayTraceResult hit = event.getTarget();
    if (hit.typeOfHit != RayTraceResult.Type.BLOCK) {
        return;
    }
    BlockPos pos = hit.getBlockPos();
    EntityPlayer player = event.getPlayer();
    if (player == null) {
        return;
    }
    World world = player.world;
    if (world == null) {
        return;
    }
    if (world.getBlockState(pos).getBlock() == LPBlocks.pipe) {
        Optional<TileMultipartContainer> tile = BlockMultipartContainer.getTile(world, pos);
        if (!tile.isPresent()) {
            return;
        }
        int slotID = hit.subHit;
        if (slotID < 0) {
            return;
        }
        PartInfo info = tile.get().getParts().get(MCMultiPart.slotRegistry.getValue(slotID));
        if (info == null || !(hit.hitInfo instanceof RayTraceResult)) {
            return;
        }
        hit = (RayTraceResult) hit.hitInfo;
        float partialTicks = event.getPartialTicks();
        if (!MinecraftForge.EVENT_BUS.post(new DrawMultipartHighlightEvent(event.getContext(), player, hit, slotID, partialTicks, info))) {
            GlStateManager.enableBlend();
            GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
            GlStateManager.glLineWidth(2.0F);
            GlStateManager.disableTexture2D();
            GlStateManager.depthMask(false);
            IBlockState state = info.getState();
            if (state.getMaterial() != Material.AIR && world.getWorldBorder().contains(pos)) {
                double x = player.lastTickPosX + (player.posX - player.lastTickPosX) * partialTicks;
                double y = player.lastTickPosY + (player.posY - player.lastTickPosY) * partialTicks;
                double z = player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * partialTicks;
                RenderGlobal.drawSelectionBoundingBox(info.getPart().getSelectedBoundingBox(info).grow(0.002).offset(-x, -y, -z), 0.0F, 0.0F, 0.0F, 0.4F);
            }
            GlStateManager.depthMask(true);
            GlStateManager.enableTexture2D();
            GlStateManager.disableBlend();
        }
        event.setCanceled(true);
    }
}
Also used : LPTileMultipartContainer(network.rs485.logisticspipes.proxy.mcmp.subproxy.LPTileMultipartContainer) TileMultipartContainer(mcmultipart.block.TileMultipartContainer) IBlockState(net.minecraft.block.state.IBlockState) RayTraceResult(net.minecraft.util.math.RayTraceResult) EntityPlayer(net.minecraft.entity.player.EntityPlayer) PartInfo(mcmultipart.multipart.PartInfo) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) DrawMultipartHighlightEvent(mcmultipart.api.event.DrawMultipartHighlightEvent) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 2 with TileMultipartContainer

use of mcmultipart.block.TileMultipartContainer in project LogisticsPipes by RS485.

the class LPMicroblockBlock method removedByPlayer.

@Override
@ModDependentMethod(modId = LPConstants.mcmpModID)
public boolean removedByPlayer(@Nonnull IBlockState state, World world, @Nonnull BlockPos pos, @Nonnull EntityPlayer player, boolean willHarvest) {
    Pair<Vec3d, Vec3d> vectors = RayTraceHelper.getRayTraceVectors(player);
    RayTraceResult hit = collisionRayTrace(state, world, pos, vectors.getLeft(), vectors.getRight());
    Optional<TileMultipartContainer> tile = getTile(world, pos);
    if (hit != null && tile.isPresent() && hit.subHit >= 0) {
        if (!world.isRemote) {
            IPartSlot slot = MCMultiPart.slotRegistry.getValue(hit.subHit);
            boolean canRemove = tile.get().get(slot).map(i -> {
                if (i.getPart().canPlayerDestroy(i, player)) {
                    i.getPart().onPartHarvested(i, player);
                    if (player == null || !player.capabilities.isCreativeMode) {
                        i.getPart().getDrops(i.getPartWorld(), pos, i, 0).forEach(s -> spawnAsEntity(world, pos, s));
                    }
                    return true;
                } else {
                    return false;
                }
            }).orElse(true);
            if (canRemove)
                tile.get().removePart(slot);
        }
    }
    if (hit != null && hit.subHit == -1) {
        return super.removedByPlayer(state, world, pos, player, willHarvest);
    }
    return false;
}
Also used : Explosion(net.minecraft.world.Explosion) AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EnumHand(net.minecraft.util.EnumHand) Random(java.util.Random) IPartInfo(mcmultipart.api.container.IPartInfo) ModDependentMethod(logisticspipes.asm.ModDependentMethod) ItemStack(net.minecraft.item.ItemStack) RayTraceResult(net.minecraft.util.math.RayTraceResult) IPartSlot(mcmultipart.api.slot.IPartSlot) ParticleDigging(net.minecraft.client.particle.ParticleDigging) Block(net.minecraft.block.Block) Vec3d(net.minecraft.util.math.Vec3d) Pair(org.apache.commons.lang3.tuple.Pair) ModDependentInterface(logisticspipes.asm.ModDependentInterface) EntityLiving(net.minecraft.entity.EntityLiving) Side(net.minecraftforge.fml.relauncher.Side) IMCMPBlockAccess(network.rs485.logisticspipes.proxy.mcmp.subproxy.IMCMPBlockAccess) SideOnly(net.minecraftforge.fml.relauncher.SideOnly) LPConstants(logisticspipes.LPConstants) Nonnull(javax.annotation.Nonnull) IBlockAccess(net.minecraft.world.IBlockAccess) Entity(net.minecraft.entity.Entity) BlockContainer(net.minecraft.block.BlockContainer) BlockFaceShape(net.minecraft.block.state.BlockFaceShape) World(net.minecraft.world.World) MCMultiPart(mcmultipart.MCMultiPart) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) IMultipartContainerBlock(mcmultipart.api.container.IMultipartContainerBlock) IPlantable(net.minecraftforge.common.IPlantable) IBlockState(net.minecraft.block.state.IBlockState) SimpleServiceLocator(logisticspipes.proxy.SimpleServiceLocator) ParticleManager(net.minecraft.client.particle.ParticleManager) Material(net.minecraft.block.material.Material) EntityLivingBase(net.minecraft.entity.EntityLivingBase) TileMultipartContainer(mcmultipart.block.TileMultipartContainer) EntityPlayer(net.minecraft.entity.player.EntityPlayer) BlockMultipartContainer.getTile(mcmultipart.block.BlockMultipartContainer.getTile) Optional(java.util.Optional) EnumBlockRenderType(net.minecraft.util.EnumBlockRenderType) RayTraceHelper(mcmultipart.RayTraceHelper) TileMultipartContainer(mcmultipart.block.TileMultipartContainer) RayTraceResult(net.minecraft.util.math.RayTraceResult) IPartSlot(mcmultipart.api.slot.IPartSlot) Vec3d(net.minecraft.util.math.Vec3d) ModDependentMethod(logisticspipes.asm.ModDependentMethod)

Aggregations

TileMultipartContainer (mcmultipart.block.TileMultipartContainer)2 IBlockState (net.minecraft.block.state.IBlockState)2 EntityPlayer (net.minecraft.entity.player.EntityPlayer)2 BlockPos (net.minecraft.util.math.BlockPos)2 RayTraceResult (net.minecraft.util.math.RayTraceResult)2 World (net.minecraft.world.World)2 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)2 Optional (java.util.Optional)1 Random (java.util.Random)1 Nonnull (javax.annotation.Nonnull)1 LPConstants (logisticspipes.LPConstants)1 ModDependentInterface (logisticspipes.asm.ModDependentInterface)1 ModDependentMethod (logisticspipes.asm.ModDependentMethod)1 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)1 MCMultiPart (mcmultipart.MCMultiPart)1 RayTraceHelper (mcmultipart.RayTraceHelper)1 IMultipartContainerBlock (mcmultipart.api.container.IMultipartContainerBlock)1 IPartInfo (mcmultipart.api.container.IPartInfo)1 DrawMultipartHighlightEvent (mcmultipart.api.event.DrawMultipartHighlightEvent)1 IPartSlot (mcmultipart.api.slot.IPartSlot)1