Search in sources :

Example 1 with IExplosive

use of icbm.classic.api.caps.IExplosive in project ICBM-Classic by BuiltBrokenModding.

the class ExplosiveInit method enderBlockCoordSet.

private static boolean enderBlockCoordSet(World world, BlockPos pos, EntityPlayer entityPlayer, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    final ItemStack heldItem = entityPlayer.getHeldItem(hand);
    if (heldItem.getItem() instanceof IWorldPosItem) {
        final IWorldPosItem posItem = ((IWorldPosItem) heldItem.getItem());
        final IWorldPosition link = posItem.getLocation(heldItem);
        if (link instanceof Location) {
            TileEntity tileEntity = world.getTileEntity(pos);
            if (tileEntity.hasCapability(ICBMClassicAPI.EXPLOSIVE_CAPABILITY, facing)) {
                IExplosive explosive = tileEntity.getCapability(ICBMClassicAPI.EXPLOSIVE_CAPABILITY, facing);
                if (explosive != null) {
                    NBTTagCompound tag = new NBTTagCompound();
                    ((Location) link).writeIntNBT(tag);
                    explosive.getCustomBlastData().setTag("", tag);
                    if (!world.isRemote) {
                    // entityPlayer.sendMessage(new TextComponentString("Synced coordinate with " + this.getExplosiveName())); //TODO translate
                    }
                    return true;
                }
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) IWorldPosition(icbm.classic.api.data.IWorldPosition) IExplosive(icbm.classic.api.caps.IExplosive) ItemStack(net.minecraft.item.ItemStack) IWorldPosItem(icbm.classic.api.items.IWorldPosItem) Location(icbm.classic.lib.transform.vector.Location) ResourceLocation(net.minecraft.util.ResourceLocation)

Example 2 with IExplosive

use of icbm.classic.api.caps.IExplosive in project ICBM-Classic by BuiltBrokenModding.

the class ItemDefuser method onLeftClickEntity.

/**
 * Called when the player Left Clicks (attacks) an entity. Processed before damage is done, if
 * return value is true further processing is canceled and the entity is not attacked.
 *
 * @param itemStack The Item being used
 * @param player    The player that is attacking
 * @param entity    The entity being attacked
 * @return True to cancel the rest of the interaction.
 */
@Override
public boolean onLeftClickEntity(ItemStack itemStack, EntityPlayer player, Entity entity) {
    if (this.getEnergy(itemStack) >= ENERGY_COST) {
        if (ICBMClassicHelpers.isExplosive(entity)) {
            if (!entity.world.isRemote) {
                final IExplosive explosive = ICBMClassicHelpers.getExplosive(entity);
                if (explosive != null) {
                    if (MinecraftForge.EVENT_BUS.post(new ExplosiveDefuseEvent.ICBMExplosive(player, entity, explosive))) {
                        return false;
                    }
                    explosive.onDefuse();
                }
                entity.setDead();
            }
        } else if (entity instanceof EntityTNTPrimed) {
            if (MinecraftForge.EVENT_BUS.post(new ExplosiveDefuseEvent.TNTExplosive(player, entity))) {
                return false;
            }
            if (!entity.world.isRemote) {
                entity.world.spawnEntity(new EntityItem(entity.world, entity.posX, entity.posY, entity.posZ, new ItemStack(Blocks.TNT)));
            }
            entity.setDead();
        } else if (entity instanceof EntityBombCart) {
            if (MinecraftForge.EVENT_BUS.post(new ExplosiveDefuseEvent.ICBMBombCart(player, entity))) {
                return false;
            }
            ((EntityBombCart) entity).killMinecart(DamageSource.GENERIC);
        }
        this.discharge(itemStack, ENERGY_COST, true);
        return true;
    } else {
        player.sendMessage(new TextComponentString(LanguageUtility.getLocal("message.defuser.nopower")));
    }
    return false;
}
Also used : EntityBombCart(icbm.classic.content.entity.EntityBombCart) EntityTNTPrimed(net.minecraft.entity.item.EntityTNTPrimed) IExplosive(icbm.classic.api.caps.IExplosive) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) ExplosiveDefuseEvent(icbm.classic.api.events.ExplosiveDefuseEvent) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 3 with IExplosive

use of icbm.classic.api.caps.IExplosive in project ICBM-Classic by BuiltBrokenModding.

the class EntityGrenadeTest method getCapability_explosiveCap.

@Test
void getCapability_explosiveCap() {
    final EntityGrenade entityGrenade = new EntityGrenade(testManager.getWorld());
    // Mock cast as mockito is odd
    Mockito.when(ICBMClassicAPI.EXPLOSIVE_CAPABILITY.cast(entityGrenade.explosive)).thenReturn(entityGrenade.explosive);
    final IExplosive capability = entityGrenade.getCapability(ICBMClassicAPI.EXPLOSIVE_CAPABILITY, null);
    // Should return a capability for an entity
    Assertions.assertTrue(capability instanceof CapabilityExplosiveEntity, "Should have an explosive entity cap");
    final CapabilityExplosiveEntity cap = (CapabilityExplosiveEntity) capability;
    // Should contain the entity in question
    Assertions.assertSame(cap.entity, entityGrenade);
}
Also used : CapabilityExplosiveEntity(icbm.classic.lib.capability.ex.CapabilityExplosiveEntity) IExplosive(icbm.classic.api.caps.IExplosive) Test(org.junit.jupiter.api.Test)

Example 4 with IExplosive

use of icbm.classic.api.caps.IExplosive in project ICBM-Classic by BuiltBrokenModding.

the class ICBMCreativeTab method compareExplosives.

private int compareExplosives(ItemStack itemA, ItemStack itemB) {
    final IExplosive explosiveA = ICBMClassicHelpers.getExplosive(itemA);
    final IExplosive explosiveB = ICBMClassicHelpers.getExplosive(itemB);
    if (explosiveA != null && explosiveB != null) {
        return compareExplosives(explosiveA, explosiveB);
    }
    return 0;
}
Also used : IExplosive(icbm.classic.api.caps.IExplosive)

Example 5 with IExplosive

use of icbm.classic.api.caps.IExplosive in project ICBM-Classic by BuiltBrokenModding.

the class TileCruiseLauncher method getStatus.

/**
 * Gets the display status of the missile launcher
 *
 * @return The string to be displayed
 */
@Override
public String getStatus() {
    String color = "\u00a74";
    String status;
    if (!hasChargeToFire()) {
        status = LanguageUtility.getLocal("gui.launcherCruise.statusNoPower");
    } else if (this.getInventory().getStackInSlot(0).isEmpty()) {
        status = LanguageUtility.getLocal("gui.launcherCruise.statusEmpty");
    } else if (this.getInventory().getStackInSlot(0).getItem() != ItemReg.itemMissile) {
        status = LanguageUtility.getLocal("gui.launcherCruise.invalidMissile");
    } else {
        final IExplosive explosive = ICBMClassicHelpers.getExplosive(this.getInventory().getStackInSlot(0));
        if (explosive == null) {
            status = LanguageUtility.getLocal("gui.launcherCruise.invalidMissile");
        } else if (!hasMissile()) {
            status = LanguageUtility.getLocal("gui.launcherCruise.notCruiseMissile");
        } else if (!hasTarget()) {
            status = LanguageUtility.getLocal("gui.launcherCruise.statusInvalid");
        } else if (this.isTooClose(getTarget())) {
            status = LanguageUtility.getLocal("gui.launcherCruise.targetToClose");
        } else if (!canSpawnMissileWithNoCollision()) {
            status = LanguageUtility.getLocal("gui.launcherCruise.noRoom");
        } else {
            color = "\u00a72";
            status = LanguageUtility.getLocal("gui.launcherCruise.statusReady");
        }
    }
    return color + status;
}
Also used : TextComponentString(net.minecraft.util.text.TextComponentString) IExplosive(icbm.classic.api.caps.IExplosive)

Aggregations

IExplosive (icbm.classic.api.caps.IExplosive)7 ItemStack (net.minecraft.item.ItemStack)4 TextComponentString (net.minecraft.util.text.TextComponentString)3 IWorldPosition (icbm.classic.api.data.IWorldPosition)2 IWorldPosItem (icbm.classic.api.items.IWorldPosItem)2 Location (icbm.classic.lib.transform.vector.Location)2 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)2 ResourceLocation (net.minecraft.util.ResourceLocation)2 ExplosiveDefuseEvent (icbm.classic.api.events.ExplosiveDefuseEvent)1 EntityBombCart (icbm.classic.content.entity.EntityBombCart)1 CapabilityExplosiveEntity (icbm.classic.lib.capability.ex.CapabilityExplosiveEntity)1 CapabilityExplosiveStack (icbm.classic.lib.capability.ex.CapabilityExplosiveStack)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityTNTPrimed (net.minecraft.entity.item.EntityTNTPrimed)1 TileEntity (net.minecraft.tileentity.TileEntity)1 Test (org.junit.jupiter.api.Test)1