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());
}
}
}
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);
}
}
}
}
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);
}
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));
}
}
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;
}
}
}
Aggregations