Search in sources :

Example 56 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project SecurityCraft by Geforce132.

the class SCEventHandler method onBlockBroken.

@SubscribeEvent
public void onBlockBroken(BreakEvent event) {
    if (!event.world.isRemote)
        if (event.world.getTileEntity(event.pos) != null && event.world.getTileEntity(event.pos) instanceof CustomizableSCTE) {
            CustomizableSCTE te = (CustomizableSCTE) event.world.getTileEntity(event.pos);
            for (int i = 0; i < te.getNumberOfCustomizableOptions(); i++) if (te.itemStacks[i] != null) {
                ItemStack stack = te.itemStacks[i];
                EntityItem item = new EntityItem(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ(), stack);
                event.world.spawnEntityInWorld(item);
                te.onModuleRemoved(stack, ((ItemModule) stack.getItem()).getModule());
                te.createLinkedBlockAction(EnumLinkedAction.MODULE_REMOVED, new Object[] { stack, ((ItemModule) stack.getItem()).getModule() }, te);
                if (te instanceof TileEntitySecurityCamera)
                    te.getWorld().notifyNeighborsOfStateChange(te.getPos().offset((EnumFacing) te.getWorld().getBlockState(te.getPos()).getValue(BlockSecurityCamera.FACING), -1), te.getWorld().getBlockState(te.getPos()).getBlock());
            }
        }
}
Also used : CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) TileEntitySecurityCamera(net.geforcemods.securitycraft.tileentity.TileEntitySecurityCamera) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 57 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project SecurityCraft by Geforce132.

the class SCEventHandler method onPlayerInteracted.

@SubscribeEvent
public void onPlayerInteracted(PlayerInteractEvent event) {
    if (!event.entityPlayer.worldObj.isRemote) {
        World world = event.entityPlayer.worldObj;
        TileEntity tileEntity = event.entityPlayer.worldObj.getTileEntity(event.pos);
        Block block = event.entityPlayer.worldObj.getBlockState(event.pos).getBlock();
        if (event.action != Action.RIGHT_CLICK_BLOCK)
            return;
        if (event.action == Action.RIGHT_CLICK_BLOCK && PlayerUtils.isHoldingItem(event.entityPlayer, SCContent.codebreaker) && handleCodebreaking(event)) {
            event.setCanceled(true);
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity != null && tileEntity instanceof CustomizableSCTE && PlayerUtils.isHoldingItem(event.entityPlayer, SCContent.universalBlockModifier)) {
            event.setCanceled(true);
            if (!((IOwnable) tileEntity).getOwner().isOwner(event.entityPlayer)) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, StatCollector.translateToLocal("item.universalBlockModifier.name"), StatCollector.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), EnumChatFormatting.RED);
                return;
            }
            event.entityPlayer.openGui(SecurityCraft.instance, GuiHandler.CUSTOMIZE_BLOCK, world, event.pos.getX(), event.pos.getY(), event.pos.getZ());
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity instanceof INameable && ((INameable) tileEntity).canBeNamed() && PlayerUtils.isHoldingItem(event.entityPlayer, Items.name_tag) && event.entityPlayer.getCurrentEquippedItem().hasDisplayName()) {
            event.setCanceled(true);
            for (String character : new String[] { "(", ")" }) if (event.entityPlayer.getCurrentEquippedItem().getDisplayName().contains(character)) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, "Naming", StatCollector.translateToLocal("messages.naming.error").replace("#n", event.entityPlayer.getCurrentEquippedItem().getDisplayName()).replace("#c", character), EnumChatFormatting.RED);
                return;
            }
            if (((INameable) tileEntity).getCustomName().matches(event.entityPlayer.getCurrentEquippedItem().getDisplayName())) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, "Naming", StatCollector.translateToLocal("messages.naming.alreadyMatches").replace("#n", ((INameable) tileEntity).getCustomName()), EnumChatFormatting.RED);
                return;
            }
            event.entityPlayer.getCurrentEquippedItem().stackSize--;
            ((INameable) tileEntity).setCustomName(event.entityPlayer.getCurrentEquippedItem().getDisplayName());
            return;
        }
        if (event.action == Action.RIGHT_CLICK_BLOCK && tileEntity != null && isOwnableBlock(block, tileEntity) && PlayerUtils.isHoldingItem(event.entityPlayer, SCContent.universalBlockRemover)) {
            event.setCanceled(true);
            if (!((IOwnable) tileEntity).getOwner().isOwner(event.entityPlayer)) {
                PlayerUtils.sendMessageToPlayer(event.entityPlayer, StatCollector.translateToLocal("item.universalBlockRemover.name"), StatCollector.translateToLocal("messages.notOwned").replace("#", ((TileEntityOwnable) tileEntity).getOwner().getName()), EnumChatFormatting.RED);
                return;
            }
            if (block == SCContent.laserBlock) {
                world.destroyBlock(event.pos, true);
                BlockLaserBlock.destroyAdjacentLasers(event.world, event.pos.getX(), event.pos.getY(), event.pos.getZ());
                event.entityPlayer.getCurrentEquippedItem().damageItem(1, event.entityPlayer);
            } else {
                world.destroyBlock(event.pos, true);
                world.removeTileEntity(event.pos);
                event.entityPlayer.getCurrentEquippedItem().damageItem(1, event.entityPlayer);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) CustomizableSCTE(net.geforcemods.securitycraft.api.CustomizableSCTE) INameable(net.geforcemods.securitycraft.api.INameable) Block(net.minecraft.block.Block) BlockLaserBlock(net.geforcemods.securitycraft.blocks.BlockLaserBlock) IOwnable(net.geforcemods.securitycraft.api.IOwnable) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 58 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project SecurityCraft by Geforce132.

the class SCEventHandler method onPlayerLoggedIn.

@SubscribeEvent
public void onPlayerLoggedIn(PlayerLoggedInEvent event) {
    String tipKey = getRandomTip();
    IChatComponent chatcomponenttext;
    if (tipsWithLink.containsKey(tipKey.split("\\.")[2]))
        chatcomponenttext = new ChatComponentText("[" + EnumChatFormatting.GOLD + "SecurityCraft" + EnumChatFormatting.WHITE + "] " + StatCollector.translateToLocal("messages.thanks").replace("#", SecurityCraft.getVersion()) + " " + StatCollector.translateToLocal("messages.tip") + " " + StatCollector.translateToLocal(tipKey) + " ").appendSibling(ForgeHooks.newChatWithLinks(tipsWithLink.get(tipKey.split("\\.")[2])));
    else
        chatcomponenttext = new ChatComponentText("[" + EnumChatFormatting.GOLD + "SecurityCraft" + EnumChatFormatting.WHITE + "] " + StatCollector.translateToLocal("messages.thanks").replace("#", SecurityCraft.getVersion()) + " " + StatCollector.translateToLocal("messages.tip") + " " + StatCollector.translateToLocal(tipKey));
    if (SecurityCraft.config.sayThanksMessage)
        event.player.addChatComponentMessage(chatcomponenttext);
}
Also used : IChatComponent(net.minecraft.util.IChatComponent) ChatComponentText(net.minecraft.util.ChatComponentText) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 59 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project RecurrentComplex by Ivorforce.

the class RCForgeEventHandler method onEntityCapapabilityAttach.

@SubscribeEvent
public void onEntityCapapabilityAttach(AttachCapabilitiesEvent.Entity event) {
    if (event.getEntity() instanceof EntityPlayer) {
        event.addCapability(new ResourceLocation(RecurrentComplex.MOD_ID, RCEntityInfo.CAPABILITY_KEY), new SimpleCapabilityProvider<>(RCEntityInfo.CAPABILITY));
        event.addCapability(new ResourceLocation(RecurrentComplex.MOD_ID, CapabilitySelection.CAPABILITY_KEY), new SimpleCapabilityProvider<>(CapabilitySelection.CAPABILITY));
    }
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 60 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project Bookshelf by Darkhax-Minecraft.

the class BookshelfEvents method onAnvilUpdate.

@SubscribeEvent
public void onAnvilUpdate(AnvilUpdateEvent event) {
    for (final IAnvilRecipe recipe : BookshelfRegistry.getAnvilRecipes()) {
        if (recipe.isValidRecipe(event.getLeft(), event.getRight(), event.getName())) {
            event.setCost(recipe.getExperienceCost(event.getLeft(), event.getRight(), event.getName()));
            event.setMaterialCost(recipe.getMaterialCost(event.getLeft(), event.getRight(), event.getName()));
            event.setOutput(recipe.getOutput(event.getLeft(), event.getRight(), event.getName()));
            return;
        }
    }
}
Also used : IAnvilRecipe(net.darkhax.bookshelf.crafting.IAnvilRecipe) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1135 ItemStack (net.minecraft.item.ItemStack)316 EntityPlayer (net.minecraft.entity.player.EntityPlayer)314 World (net.minecraft.world.World)196 BlockPos (net.minecraft.util.math.BlockPos)179 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)136 IBlockState (net.minecraft.block.state.IBlockState)120 ResourceLocation (net.minecraft.util.ResourceLocation)102 Entity (net.minecraft.entity.Entity)93 Block (net.minecraft.block.Block)86 EntityLivingBase (net.minecraft.entity.EntityLivingBase)84 Minecraft (net.minecraft.client.Minecraft)72 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)66 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)64 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)55 Item (net.minecraft.item.Item)53 EntityItem (net.minecraft.entity.item.EntityItem)48 TileEntity (net.minecraft.tileentity.TileEntity)46 TextComponentString (net.minecraft.util.text.TextComponentString)42 Random (java.util.Random)37