Search in sources :

Example 1 with ModDependentMethod

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

the class LPMicroblockBlock method onBlockActivated.

@Override
@ModDependentMethod(modId = LPConstants.mcmpModID)
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    Pair<Vec3d, Vec3d> vectors = RayTraceHelper.getRayTraceVectors(player);
    RayTraceResult hit = collisionRayTrace(getDefaultState(), world, pos, vectors.getLeft(), vectors.getRight());
    if (hit != null && hit.subHit >= 0) {
        return getTile(world, pos).map(t -> t.get(MCMultiPart.slotRegistry.getValue(hit.subHit)).get()).map(i -> i.getPart().onPartActivated(i, player, hand, (RayTraceResult) hit.hitInfo)).orElse(false);
    }
    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) RayTraceResult(net.minecraft.util.math.RayTraceResult) Vec3d(net.minecraft.util.math.Vec3d) ModDependentMethod(logisticspipes.asm.ModDependentMethod)

Example 2 with ModDependentMethod

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

the class LPMicroblockBlock method getPlayerRelativeBlockHardness.

@Override
@ModDependentMethod(modId = LPConstants.mcmpModID)
public float getPlayerRelativeBlockHardness(IBlockState state, @Nonnull EntityPlayer player, @Nonnull World world, @Nonnull BlockPos pos) {
    Pair<Vec3d, Vec3d> vectors = RayTraceHelper.getRayTraceVectors(player);
    RayTraceResult hit = collisionRayTrace(getDefaultState(), world, pos, vectors.getLeft(), vectors.getRight());
    if (hit != null && hit.subHit >= 0) {
        return getTile(world, pos).map(t -> t.get(MCMultiPart.slotRegistry.getValue(hit.subHit)).get()).map(i -> i.getPart().getPlayerRelativePartHardness(i, (RayTraceResult) hit.hitInfo, player)).orElse(0F);
    }
    if (hit != null) {
        return super.getPlayerRelativeBlockHardness(state, player, world, pos);
    }
    return 0;
}
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 3 with ModDependentMethod

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

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

the class LPMicroblockTileEntity method writeToNBT.

@Nonnull
@Override
@ModDependentMethod(modId = LPConstants.mcmpModID)
public NBTTagCompound writeToNBT(NBTTagCompound tag) {
    tag = super.writeToNBT(tag);
    NBTTagCompound multiPartTag = new NBTTagCompound();
    if (this.getMultipartContainer() != null)
        multiPartTag = this.getMultipartContainer().writeToNBT(multiPartTag);
    tag.setTag("MCMultiPartData", multiPartTag);
    return tag;
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Nonnull(javax.annotation.Nonnull) ModDependentMethod(logisticspipes.asm.ModDependentMethod)

Example 5 with ModDependentMethod

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

the class LPMicroblockTileEntity method getUpdatePacket.

@Override
@ModDependentMethod(modId = LPConstants.mcmpModID)
public SPacketUpdateTileEntity getUpdatePacket() {
    NBTTagCompound nbt = new NBTTagCompound();
    if (this.getMultipartContainer() != null) {
        SPacketUpdateTileEntity packet = this.getMultipartContainer().getUpdatePacket();
        nbt = ReflectionHelper.getPrivateField(SPacketUpdateTileEntity.class, packet, "nbt", "field_148860_e");
    }
    SPacketUpdateTileEntity superPacket = super.getUpdatePacket();
    if (superPacket != null) {
        nbt.setTag("LogisticsPipes:SuperUpdatePacket", superPacket.getNbtCompound());
    }
    return new SPacketUpdateTileEntity(this.getPartPos(), 0, nbt);
}
Also used : NBTTagCompound(net.minecraft.nbt.NBTTagCompound) SPacketUpdateTileEntity(net.minecraft.network.play.server.SPacketUpdateTileEntity) 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