net.minecraftforge.eventbus.api.SubscribeEvent Java Examples

The following examples show how to use net.minecraftforge.eventbus.api.SubscribeEvent. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: TileChunkLoadHook.java    From CodeChickenLib with GNU Lesser General Public License v2.1 6 votes vote down vote up
@SubscribeEvent
public void onChunkLoad(ChunkEvent.Load event) {
    IChunk chunk = event.getChunk();
    Map<BlockPos, TileEntity> tiles = null;
    if (chunk instanceof ChunkPrimerWrapper) {
        chunk = ((ChunkPrimerWrapper) chunk).func_217336_u();
    }
    if (chunk instanceof Chunk) {
        tiles = ((Chunk) chunk).getTileEntityMap();
    }
    if (chunk instanceof ChunkPrimer) {
        tiles = ((ChunkPrimer) chunk).getTileEntities();
    }
    if (tiles != null) {
        for (TileEntity tile : tiles.values()) {
            if (tile instanceof IChunkLoadTile) {
                ((IChunkLoadTile) tile).onChunkLoad();
            }
        }
    }
}
 
Example #2
Source File: StringEventHandling.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SubscribeEvent
public void entityDrops(LivingDropsEvent ev)
{
    if (!ConfigManager.SERVER.dropStringFromSheep.get())
        return;

    Entity entity = ev.getEntity();
    if (!(entity instanceof SheepEntity))
        return;

    Collection<ItemEntity> drops = ev.getDrops();
    if (drops instanceof ImmutableList)
    {
        SurvivalistMod.LOGGER.warn("WARNING: Some mod is returning an ImmutableList, replacing drops will NOT be possible.");
        return;
    }

    if (rnd.nextFloat() < 0.25f)
        drops.add(new ItemEntity(entity.getEntityWorld(), entity.getPosX(), entity.getPosY(), entity.getPosZ(), new ItemStack(Items.STRING)));
}
 
Example #3
Source File: TankSynchroniser.java    From EnderStorage with MIT License 6 votes vote down vote up
@SubscribeEvent
public void tickEnd(TickEvent.ServerTickEvent event) {
    if (event.phase == TickEvent.Phase.END && playerItemTankStates != null) {
        for (Map.Entry<UUID, PlayerItemTankCache> entry : playerItemTankStates.entrySet()) {
            entry.getValue().update();
        }
    }
}
 
Example #4
Source File: ItemBreakingTracker.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SubscribeEvent
public void onPlayerDestroyItem(PlayerDestroyItemEvent ev)
{
    if (!ConfigManager.SERVER.enableScraping.get())
        return;
    if (ev.getPlayer().world.isRemote)
        return;

    ItemStack stack = ev.getOriginal();
    if (stack.isEmpty())
        return;

    Item item = stack.getItem();

    if (!(item instanceof TieredItem))
        return;

    onItemBroken(ev.getPlayer(), stack);
}
 
Example #5
Source File: ConfigManager.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SubscribeEvent
public static void modConfig(ModConfig.ModConfigEvent event)
{
    ModConfig config = event.getConfig();
    if (config.getSpec() != SERVER_SPEC)
        return;

    Config axeLevels = SERVER.axeLevels.get();

    for (Config.Entry e : axeLevels.entrySet())
    {
        Matcher m = AXE_LEVEL_ENTRY_PATTERN.matcher(e.getKey());
        if (m.matches())
        {
            String numberPart = m.group("level");
            int levelNumber = Integer.parseInt(numberPart);
            axeLevelMap.put(levelNumber, e.getIntOrElse(1 + levelNumber));
        }
    }
}
 
Example #6
Source File: ItemBreakingTracker.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
@SubscribeEvent
public void entityJoinWorld(EntityJoinWorldEvent ev)
{
    if (!ConfigManager.SERVER.enableScraping.get())
        return;
    if (ev.getEntity().world.isRemote)
        return;

    if (ev.getEntity() instanceof PlayerEntity)
    {
        PlayerEntity player = (PlayerEntity) ev.getEntity();

        CombatTrackerIntercept interceptTracker = new CombatTrackerIntercept(player);
        ObfuscationReflectionHelper.setPrivateValue(LivingEntity.class, player, interceptTracker, "field_94063_bt");
    }
}
 
Example #7
Source File: ForgeTickHook.java    From spark with GNU General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public void onTick(TickEvent e) {
    if (e.phase != TickEvent.Phase.START) {
        return;
    }

    if (e.type != this.type) {
        return;
    }

    onTick();
}
 
Example #8
Source File: TestRunner.java    From NoCubes with GNU Lesser General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
public static void runTests(FMLServerStartedEvent event) {
	final TestRepository testRepository = new TestRepository();
	final MinecraftServer server = event.getServer();
	final long fails = testRepository.tests.parallelStream()
		.filter(test -> runTestWithCatch(test, server))
		.count();
	if (fails > 0)
		log(server, new StringTextComponent(fails + " TESTS FAILED").applyTextStyle(TextFormatting.RED));
	else
		log(server, new StringTextComponent("ALL TESTS PASSED").applyTextStyle(TextFormatting.GREEN));
	if (!TestUtil.IS_CI_ENVIRONMENT.get())
		return;
	if (fails > 0)
		throw new RuntimeException("Had failed tests");
	else
		event.getServer().initiateShutdown(false);
}
 
Example #9
Source File: BleachHack.java    From bleachhack-1.14 with GNU General Public License v3.0 6 votes vote down vote up
@SubscribeEvent
  public void onTick(TickEvent.ClientTickEvent event) {
if (!(event.phase == Phase.END)) return;

try {
	ModuleManager.onUpdate();
  		ModuleManager.updateKeys();
  		
  		if (Minecraft.getInstance().player.ticksExisted % 100 == 0) {
  			fileReader.saveModules();
  			fileReader.saveSettings();
  			fileReader.saveClickGui();
  		}
  		
  		BleachQueue.nextQueue();
  	} catch (Exception e) {}
  }
 
Example #10
Source File: BleachHack.java    From bleachhack-1.14 with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public void onChatMsg(ClientChatEvent event) {
	if (event.getMessage().startsWith(".")) {
		CommandManager cmd = new CommandManager();
		cmd.callCommand(event.getMessage().substring(1));
		event.setCanceled(true);
	}
}
 
Example #11
Source File: Generator.java    From MiningGadgets with MIT License 5 votes vote down vote up
@SubscribeEvent
public static void gatherData(GatherDataEvent event) {
     if( event.includeServer() )
        registerServerProviders(event.getGenerator());

    if( event.includeClient() )
        registerClientProviders(event.getGenerator(), event);
}
 
Example #12
Source File: ModParticles.java    From MiningGadgets with MIT License 5 votes vote down vote up
@SubscribeEvent
public static void registerParticles(RegistryEvent.Register<ParticleType<?>> evt) {
    evt.getRegistry().registerAll(
            new LaserParticleType().setRegistryName("laserparticle"),
            new PlayerParticleType().setRegistryName("playerparticle"),
            new LightParticleType().setRegistryName("light_particle")
    );
}
 
Example #13
Source File: ClientEventHandler.java    From Better-Sprinting with Mozilla Public License 2.0 5 votes vote down vote up
@SubscribeEvent
public static void onGuiInitPost(GuiScreenEvent.InitGuiEvent.Post e){
	Screen gui = e.getGui();
	
	if (gui instanceof ControlsScreen){
		ControlsScreen controls = (ControlsScreen)gui;
		
		e.getWidgetList()
		 .stream()
		 .filter(btn -> btn instanceof OptionButton && ((OptionButton)btn).enumOptions == AbstractOption.AUTO_JUMP)
		 .findFirst()
		 .ifPresent(e::removeWidget);
		
		controls.children()
		        .stream()
		        .filter(widget -> widget instanceof KeyBindingList)
		        .map(widget -> ((KeyBindingList)widget).children())
		        .findFirst()
		        .ifPresent(children -> children.removeIf(entry ->
		        	(entry instanceof KeyEntry && ArrayUtils.contains(ClientModManager.keyBindings, ((KeyEntry)entry).keybinding)) ||
		        	(entry instanceof CategoryEntry && ((CategoryEntry)entry).labelText.equals(I18n.format(ClientModManager.categoryName)))
		        ));
		
		if (!openedControlsFromSprintMenu){
			e.addWidget(new GuiButton((controls.width / 2) + 5, 18, 150, "Better Sprinting", () -> mc.displayGuiScreen(new GuiSprint(mc.currentScreen))));
		}
	}
}
 
Example #14
Source File: ItemBreakingTracker.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SubscribeEvent
public void onLivingHurt(LivingHurtEvent ev)
{
    if (!ConfigManager.SERVER.enableScraping.get())
        return;
    if (ev.getEntity().world.isRemote)
        return;

    if (ev.getEntity() instanceof PlayerEntity)
    {
        PlayerEntity player = (PlayerEntity) ev.getEntityLiving();

        ItemBreakingTracker.get(player).ifPresent(ItemBreakingTracker::before);
    }
}
 
Example #15
Source File: Events.java    From XRay-Mod with GNU General Public License v3.0 5 votes vote down vote up
@SubscribeEvent
public static void onWorldRenderLast( RenderWorldLastEvent event ) // Called when drawing the world.
{
	if ( Controller.isXRayActive() && XRay.mc.player != null )
	{
		// this is a world pos of the player
		Render.renderBlocks(event);
	}
}
 
Example #16
Source File: CCRenderEventHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@OnlyIn (Dist.CLIENT)
@SubscribeEvent (priority = EventPriority.LOW)
public void onBlockHighlight(DrawHighlightEvent.HighlightBlock event) {
    //We have found a CuboidRayTraceResult, Lets render it properly..
    BlockRayTraceResult hit = event.getTarget();
    if (hit instanceof CuboidRayTraceResult) {
        CuboidRayTraceResult cuboidHit = (CuboidRayTraceResult) hit;
        event.setCanceled(true);
        Matrix4 mat = new Matrix4(event.getMatrix());
        mat.translate(cuboidHit.getPos());
        RenderUtils.bufferHitbox(mat, event.getBuffers(), event.getInfo(), cuboidHit.cuboid6);
    }
}
 
Example #17
Source File: ClientEventHandler.java    From Better-Sprinting with Mozilla Public License 2.0 5 votes vote down vote up
@SubscribeEvent
public static void onPlayerJoinWorld(EntityJoinWorldEvent e){
	if (stopCheckingNewServer || e.getEntity() != mc.player){
		return;
	}
	
	stopCheckingNewServer = true;
	
	if (!mc.isIntegratedServerRunning() && mc.getCurrentServerData() != null && !ClientSettings.disableMod.get()){
		PacketPipeline.sendToServer(ClientNetwork.writeModNotification(10));
	}
}
 
Example #18
Source File: TankSynchroniser.java    From EnderStorage with MIT License 5 votes vote down vote up
@SubscribeEvent
public void tickEnd(TickEvent.ClientTickEvent event) {
    if (event.phase == TickEvent.Phase.END) {
        if (ClientUtils.inWorld() && clientState != null) {
            clientState.update();
        }
    }
}
 
Example #19
Source File: TankSynchroniser.java    From EnderStorage with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onWorldLoad(WorldEvent.Load event) {
    if (event.getWorld().isRemote()) {
        clientState = new PlayerItemTankCache();
    } else if (playerItemTankStates == null) {
        playerItemTankStates = new HashMap<>();
    }
}
 
Example #20
Source File: ModContent.java    From EnderStorage with MIT License 5 votes vote down vote up
@SubscribeEvent
public static void onRegisterBlocks(RegistryEvent.Register<Block> event) {
    IForgeRegistry<Block> registry = event.getRegistry();

    Block.Properties properties = Block.Properties.create(Material.ROCK)//
            .hardnessAndResistance(20, 100);
    registry.register(new BlockEnderChest(properties).setRegistryName("ender_chest"));
    registry.register(new BlockEnderTank(properties).setRegistryName("ender_tank"));
}
 
Example #21
Source File: IntegrityCheck.java    From Better-Sprinting with Mozilla Public License 2.0 5 votes vote down vote up
@SubscribeEvent
public void onPlayerTick(ClientTickEvent e){
	if (e.phase == Phase.END && mc.player != null && mc.player.ticksExisted > 1){
		if (!LivingUpdate.checkIntegrity()){
			mc.player.sendMessage(new StringTextComponent(ClientModManager.chatPrefix + I18n.format("bs.game.integrity")));
		}
		
		unregister();
	}
}
 
Example #22
Source File: ChoppingBlock.java    From Survivalist with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
@SubscribeEvent
public static void interactEvent(PlayerInteractEvent.LeftClickBlock event)
{
    PlayerEntity player = event.getPlayer();
    World world = player.world;
    BlockPos pos = event.getPos();
    BlockState state = world.getBlockState(pos);
    Block block = state.getBlock();
    if (block instanceof ChoppingBlock)
    {
        if (((ChoppingBlock) block).interceptClick(world, pos, state, player))
            event.setCanceled(true);
    }
}
 
Example #23
Source File: DataGenerators.java    From EnderStorage with MIT License 5 votes vote down vote up
@SubscribeEvent
public static void gatherDataGenerators(GatherDataEvent event) {
    DataGenerator gen = event.getGenerator();
    ExistingFileHelper files = event.getExistingFileHelper();
    if (event.includeClient()) {
        gen.addProvider(new BlockStates(gen, files));
        gen.addProvider(new ItemModels(gen, files));
    }
}
 
Example #24
Source File: PacketCustomChannelBuilder.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public void onClientPayload(NetworkEvent.LoginPayloadEvent event) {
    PacketCustom packet = new PacketCustom(event.getPayload());
    NetworkEvent.Context ctx = event.getSource().get();
    INetHandler netHandler = ctx.getNetworkManager().getNetHandler();
    ctx.setPacketHandled(true);
    if (netHandler instanceof ClientLoginNetHandler) {
        ClientLoginNetHandler nh = (ClientLoginNetHandler) netHandler;
        packetHandler.handleLoginPacket(packet, Minecraft.getInstance(), nh, ctx);
        //For _some_ reason sending this response packet in FML is private. So just spoof the packet :D
        ctx.getPacketDispatcher().sendPacket(new ResourceLocation("fml:handshake"), new PacketBuffer(Unpooled.buffer().writeByte(99)));
    }
}
 
Example #25
Source File: PacketCustomChannelBuilder.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public void onGatherLoginPayloads(NetworkEvent.GatherLoginPayloadsEvent event) {
    packetHandler.gatherLoginPackets((ctx, packetSupplier) -> {
        PacketCustom packet = packetSupplier.get();
        event.add(packet.toPacketBuffer(), packet.getChannel(), ctx);
    });
}
 
Example #26
Source File: ServerEventHandler.java    From Better-Sprinting with Mozilla Public License 2.0 5 votes vote down vote up
@SubscribeEvent
public static void onServerStarting(FMLServerStartingEvent e){
	ServerCommandConfig.register(e.getCommandDispatcher());
}
 
Example #27
Source File: PacketCustomChannelBuilder.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public void onClientPayload(NetworkEvent.ServerCustomPayloadEvent event) {
    if (event instanceof NetworkEvent.ServerCustomPayloadLoginEvent) {
        return;
    }
    PacketCustom packet = new PacketCustom(event.getPayload());
    NetworkEvent.Context ctx = event.getSource().get();
    INetHandler netHandler = ctx.getNetworkManager().getNetHandler();
    ctx.setPacketHandled(true);
    if (netHandler instanceof ClientPlayNetHandler) {
        ClientPlayNetHandler nh = (ClientPlayNetHandler) netHandler;
        ctx.enqueueWork(() -> packetHandler.handlePacket(packet, Minecraft.getInstance(), nh));
    }
}
 
Example #28
Source File: ConfigSyncManager.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public static void onClientDisconnected(ClientPlayerNetworkEvent.LoggedOutEvent event) {
    for (Map.Entry<ResourceLocation, SyncState> entry : clientRollbackMap.entrySet()) {
        logger.log(Level.INFO, "Client disconnect, rolling back config for {}.", entry.getKey());
        entry.getValue().revert(syncMap.get(entry.getKey()));
    }
    clientRollbackMap.clear();
}
 
Example #29
Source File: EnderStorage.java    From EnderStorage with MIT License 5 votes vote down vote up
@SubscribeEvent
public void onServerStarting(FMLServerStartingEvent event) {
}
 
Example #30
Source File: ExceptionMessageEventHandler.java    From CodeChickenLib with GNU Lesser General Public License v2.1 5 votes vote down vote up
@SubscribeEvent
public static void clientTick(TickEvent.ClientTickEvent event) {
    if (event.phase == TickEvent.Phase.END) {
        //Clear the known exceptions every 5 seconds.
        long time = System.nanoTime();
        if (TimeUnit.NANOSECONDS.toSeconds(time - lastExceptionClear) > 5) {
            lastExceptionClear = time;
            exceptionMessageCache.clear();
        }
    }
}