Search in sources :

Example 1 with TileMultipart

use of codechicken.multipart.TileMultipart in project PneumaticCraft by MineMaarten.

the class FMPPlacementListener method place.

public static boolean place(EntityPlayer player, World world) {
    MovingObjectPosition hit = RayTracer.reTrace(world, player);
    if (hit == null)
        return false;
    BlockCoord pos = new BlockCoord(hit.blockX, hit.blockY, hit.blockZ);
    ItemStack held = player.getHeldItem();
    PartPressureTube part = null;
    if (held == null)
        return false;
    Block heldBlock = Block.getBlockFromItem(held.getItem());
    if (heldBlock == Blockss.pressureTube) {
        part = new PartPressureTube();
    } else if (heldBlock == Blockss.advancedPressureTube) {
        part = new PartAdvancedPressureTube();
    }
    if (part == null)
        return false;
    if (//attempt to use block activated like normal and tell the server the right stuff
    world.isRemote && !player.isSneaking()) {
        Vector3 f = new Vector3(hit.hitVec).add(-hit.blockX, -hit.blockY, -hit.blockZ);
        Block block = world.getBlock(hit.blockX, hit.blockY, hit.blockZ);
        if (!ignoreActivate(block) && block.onBlockActivated(world, hit.blockX, hit.blockY, hit.blockZ, player, hit.sideHit, (float) f.x, (float) f.y, (float) f.z)) {
            player.swingItem();
            PacketCustom.sendToServer(new C08PacketPlayerBlockPlacement(hit.blockX, hit.blockY, hit.blockZ, hit.sideHit, player.inventory.getCurrentItem(), (float) f.x, (float) f.y, (float) f.z));
            return true;
        }
    }
    TileMultipart tile = TileMultipart.getOrConvertTile(world, pos);
    if (tile == null || !tile.canAddPart(part)) {
        pos = pos.offset(hit.sideHit);
        tile = TileMultipart.getOrConvertTile(world, pos);
        if (tile == null || !tile.canAddPart(part))
            return false;
    }
    if (!world.isRemote) {
        TileMultipart.addPart(world, pos, part);
        world.playSoundEffect(pos.x + 0.5, pos.y + 0.5, pos.z + 0.5, Blockss.pressureTube.stepSound.func_150496_b(), (Blockss.pressureTube.stepSound.getVolume() + 1.0F) / 2.0F, Blockss.pressureTube.stepSound.getPitch() * 0.8F);
        if (!player.capabilities.isCreativeMode) {
            held.stackSize--;
            if (held.stackSize == 0) {
                player.inventory.mainInventory[player.inventory.currentItem] = null;
                MinecraftForge.EVENT_BUS.post(new PlayerDestroyItemEvent(player, held));
            }
        }
    } else {
        player.swingItem();
        NetworkHandler.sendToServer(new PacketFMPPlacePart());
    }
    return true;
}
Also used : TileMultipart(codechicken.multipart.TileMultipart) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) C08PacketPlayerBlockPlacement(net.minecraft.network.play.client.C08PacketPlayerBlockPlacement) Block(net.minecraft.block.Block) Vector3(codechicken.lib.vec.Vector3) BlockCoord(codechicken.lib.vec.BlockCoord) ItemStack(net.minecraft.item.ItemStack) PlayerDestroyItemEvent(net.minecraftforge.event.entity.player.PlayerDestroyItemEvent)

Example 2 with TileMultipart

use of codechicken.multipart.TileMultipart in project PneumaticCraft by MineMaarten.

the class ModInteractionUtilImplementation method removeTube.

@Override
@Optional.Method(modid = ModIds.FMP)
public void removeTube(TileEntity te) {
    if (te instanceof TileMultipart) {
        PartPressureTube tube = FMP.getMultiPart((TileMultipart) te, PartPressureTube.class);
        if (tube != null) {
            List<ItemStack> drops = BlockPressureTube.getModuleDrops(tube.getTube());
            for (ItemStack drop : drops) {
                EntityItem entity = new EntityItem(te.getWorldObj(), te.xCoord + 0.5, te.yCoord + 0.5, te.zCoord + 0.5);
                entity.setEntityItemStack(drop);
                te.getWorldObj().spawnEntityInWorld(entity);
            }
            ((TileMultipart) te).remPart(tube);
        }
    } else {
        super.removeTube(te);
    }
}
Also used : TileMultipart(codechicken.multipart.TileMultipart) PartPressureTube(pneumaticCraft.common.thirdparty.fmp.PartPressureTube) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Aggregations

TileMultipart (codechicken.multipart.TileMultipart)2 ItemStack (net.minecraft.item.ItemStack)2 BlockCoord (codechicken.lib.vec.BlockCoord)1 Vector3 (codechicken.lib.vec.Vector3)1 Block (net.minecraft.block.Block)1 EntityItem (net.minecraft.entity.item.EntityItem)1 C08PacketPlayerBlockPlacement (net.minecraft.network.play.client.C08PacketPlayerBlockPlacement)1 MovingObjectPosition (net.minecraft.util.MovingObjectPosition)1 PlayerDestroyItemEvent (net.minecraftforge.event.entity.player.PlayerDestroyItemEvent)1 PartPressureTube (pneumaticCraft.common.thirdparty.fmp.PartPressureTube)1