Search in sources :

Example 11 with ModDependentMethod

use of logisticspipes.asm.ModDependentMethod in project LogisticsPipes by RS485.

the class LPMicroblockBlock method addDestroyEffects.

@Override
@SideOnly(Side.CLIENT)
@ModDependentMethod(modId = LPConstants.mcmpModID)
public boolean addDestroyEffects(World world, BlockPos pos, ParticleManager manager) {
    Pair<Vec3d, Vec3d> vectors = RayTraceHelper.getRayTraceVectors(MCMultiPart.proxy.getPlayer());
    RayTraceResult hit = collisionRayTrace(getDefaultState(), world, pos, vectors.getLeft(), vectors.getRight());
    if (hit != null && hit.subHit >= 0) {
        IPartInfo part = getTile(world, pos).get().get(MCMultiPart.slotRegistry.getValue(hit.subHit)).get();
        if (!part.getPart().addDestroyEffects(part, manager)) {
            IBlockState state = part.getPart().getActualState(part.getPartWorld(), pos, part);
            for (int i = 0; i < 4; ++i) {
                for (int j = 0; j < 4; ++j) {
                    for (int k = 0; k < 4; ++k) {
                        double xOff = (i + 0.5D) / 4.0D;
                        double yOff = (j + 0.5D) / 4.0D;
                        double zOff = (k + 0.5D) / 4.0D;
                        manager.addEffect(new ParticleDigging(world, pos.getX() + xOff, pos.getY() + yOff, pos.getZ() + zOff, xOff - 0.5D, yOff - 0.5D, zOff - 0.5D, state) {
                        }.setBlockPos(pos));
                    }
                }
            }
        }
        return true;
    }
    return false;
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IPartInfo(mcmultipart.api.container.IPartInfo) RayTraceResult(net.minecraft.util.math.RayTraceResult) ParticleDigging(net.minecraft.client.particle.ParticleDigging) Vec3d(net.minecraft.util.math.Vec3d) ModDependentMethod(logisticspipes.asm.ModDependentMethod) SideOnly(net.minecraftforge.fml.relauncher.SideOnly)

Example 12 with ModDependentMethod

use of logisticspipes.asm.ModDependentMethod in project LogisticsPipes by RS485.

the class LPMicroblockBlock method onBlockClicked.

@Override
@ModDependentMethod(modId = LPConstants.mcmpModID)
public void onBlockClicked(World world, BlockPos pos, EntityPlayer player) {
    Pair<Vec3d, Vec3d> vectors = RayTraceHelper.getRayTraceVectors(player);
    RayTraceResult hit = collisionRayTrace(getDefaultState(), world, pos, vectors.getLeft(), vectors.getRight());
    if (hit != null && hit.subHit >= 0) {
        getTile(world, pos).map(t -> t.get(MCMultiPart.slotRegistry.getValue(hit.subHit)).get()).ifPresent(i -> i.getPart().onPartClicked(i, player, (RayTraceResult) hit.hitInfo));
    }
}
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) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) ModDependentMethod(logisticspipes.asm.ModDependentMethod)

Example 13 with ModDependentMethod

use of logisticspipes.asm.ModDependentMethod 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

ModDependentMethod (logisticspipes.asm.ModDependentMethod)13 IPartInfo (mcmultipart.api.container.IPartInfo)6 ParticleDigging (net.minecraft.client.particle.ParticleDigging)6 RayTraceResult (net.minecraft.util.math.RayTraceResult)6 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)6 Nonnull (javax.annotation.Nonnull)5 IBlockState (net.minecraft.block.state.IBlockState)5 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)5 BlockPos (net.minecraft.util.math.BlockPos)5 Vec3d (net.minecraft.util.math.Vec3d)5 Optional (java.util.Optional)4 Random (java.util.Random)4 LPConstants (logisticspipes.LPConstants)4 ModDependentInterface (logisticspipes.asm.ModDependentInterface)4 SimpleServiceLocator (logisticspipes.proxy.SimpleServiceLocator)4 MCMultiPart (mcmultipart.MCMultiPart)4 RayTraceHelper (mcmultipart.RayTraceHelper)4 IMultipartContainerBlock (mcmultipart.api.container.IMultipartContainerBlock)4 IPartSlot (mcmultipart.api.slot.IPartSlot)4 BlockMultipartContainer.getTile (mcmultipart.block.BlockMultipartContainer.getTile)4