Java Code Examples for net.minecraftforge.common.MinecraftForge

The following are top voted examples for showing how to use net.minecraftforge.common.MinecraftForge. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: PAYDAY   File: PAYDAY.java   View source code 7 votes vote down vote up
@EventHandler
public void init(FMLInitializationEvent evt) {
	INSTANCE.registerMessage(LobbyPlayerOpenedGuiPacketHandler.class, LobbyPlayerOpenedGuiPacket.class, 0,
			Side.SERVER);

	INSTANCE.registerMessage(LobbyBeginGamePacketHandler.class, LobbyBeginGamePacket.class, 1, Side.SERVER);
	INSTANCE.registerMessage(PacketSyncPlayerPropertiesClientHandler.class, PacketSyncPlayerPropertiesClient.class,
			2, Side.CLIENT);
	INSTANCE.registerMessage(PacketSyncPlayerPropertiesServerHandler.class, PacketSyncPlayerPropertiesServer.class,
			3, Side.SERVER);

	INSTANCE.registerMessage(PacketSyncTileEntityServerHandler.class, PacketSyncTileEntityServer.class, 4,
			Side.SERVER);
	INSTANCE.registerMessage(PacketSyncTileEntityClientHandler.class, PacketSyncTileEntityClient.class, 5,
			Side.CLIENT);

	NetworkRegistry.INSTANCE.registerGuiHandler(PAYDAY.instance, new MGuiHandler());
	GameRegistry.registerBlock(lobbyBlock, "Lobby");
	GameRegistry.registerTileEntity(LobbyTileEntity.class, "lobby_tile_entity");

	FMLCommonHandler.instance().bus().register(eventHandler);
	MinecraftForge.EVENT_BUS.register(eventHandler);
}
 
Example 2
Project: FirstAid   File: FirstAid.java   View source code 6 votes vote down vote up
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent pre) {
    logger = pre.getModLog();
    logger.debug("FirstAid starting");
    creativeTab = new CreativeTabs(FirstAid.MODID) {
        @Nonnull
        @Override
        public ItemStack getTabIconItem() {
            return new ItemStack(FirstAidItems.BANDAGE);
        }
    };

    MinecraftForge.EVENT_BUS.register(EventHandler.class);
    FirstAidItems.init();
    proxy.init();
    //Setup API
    RegistryManager.setupRegistries();
    checkEarlyExit();
}
 
Example 3
Project: CustomWorldGen   File: DeferredBiomeDecorator.java   View source code 6 votes vote down vote up
public void fireCreateEventAndReplace(Biome biome)
{
    // Copy any configuration from us to the real instance.
    wrapped.bigMushroomsPerChunk = bigMushroomsPerChunk;
    wrapped.cactiPerChunk = cactiPerChunk;
    wrapped.clayPerChunk = clayPerChunk;
    wrapped.deadBushPerChunk = deadBushPerChunk;
    wrapped.flowersPerChunk = flowersPerChunk;
    wrapped.generateLakes = generateLakes;
    wrapped.grassPerChunk = grassPerChunk;
    wrapped.mushroomsPerChunk = mushroomsPerChunk;
    wrapped.reedsPerChunk = reedsPerChunk;
    wrapped.sandPerChunk = sandPerChunk;
    wrapped.sandPerChunk2 = sandPerChunk2;
    wrapped.treesPerChunk = treesPerChunk;
    wrapped.waterlilyPerChunk = waterlilyPerChunk;

    BiomeEvent.CreateDecorator event = new BiomeEvent.CreateDecorator(biome, wrapped);
    MinecraftForge.TERRAIN_GEN_BUS.post(event);
    biome.theBiomeDecorator = event.getNewBiomeDecorator();
}
 
Example 4
Project: ExPetrum   File: ExPBiomeDecorator.java   View source code 6 votes vote down vote up
public void coralPassGenerate(World worldIn, Random rand, Biome biome, BlockPos pos)
{
	if (!BiomeDictionary.areSimilar(biome, Biomes.OCEAN))
	{
		return;
	}
	
	int x = rand.nextInt(16) + 8;
	int z = rand.nextInt(16) + 8;
	BlockPos at = worldIn.getHeight(pos.add(x, 0, z));
	EventGenCoral event = new EventGenCoral(worldIn, at, rand, genCoral);
	if (MinecraftForge.TERRAIN_GEN_BUS.post(event))
	{
		return;
	}
	
	event.generator.generate(worldIn, rand, at);
}
 
Example 5
Project: ExPetrum   File: ExPBiomeDecorator.java   View source code 6 votes vote down vote up
public void cropsPassGenerate(World worldIn, Random rand, Biome biome, BlockPos pos)
{
	if (!(biome instanceof ExPBiome))
	{
		return;
	}
	
	int x = rand.nextInt(16) + 8;
	int z = rand.nextInt(16) + 8;
	BlockPos at = worldIn.getHeight(pos.add(x, 0, z));
	
	WorldGenerator cropsGen = new CropGenerator((ExPBiome) biome);
	EventGenVegetation event = new EventGenVegetation(worldIn, at, rand, cropsGen, Type.WILD_CROP);
	if (MinecraftForge.TERRAIN_GEN_BUS.post(event))
	{
		return;
	}
	
	event.generator.generate(worldIn, rand, at);
}
 
Example 6
Project: TFCPrimitiveTech   File: EntityProjectileHardStone.java   View source code 6 votes vote down vote up
@Override
public void onCollideWithPlayer(EntityPlayer player)
{
	if (!this.worldObj.isRemote)
	{
		NBTTagCompound nbt = new NBTTagCompound();
		this.writeToNBT(nbt);

		boolean inground = nbt.hasKey("inGround") && nbt.getByte("inGround") == 1;
		if(inground)
		{
			boolean flag = this.canBePickedUp == 1 || (this.canBePickedUp == 2 && player.capabilities.isCreativeMode);

			EntityItem ei = new EntityItem(this.worldObj, this.posX, this.posY, this.posZ, new ItemStack(this.pickupItem, 1, 0));

			if (this.canBePickedUp == 1)
			{
				EntityItemPickupEvent event = new EntityItemPickupEvent(player, ei);

				if (MinecraftForge.EVENT_BUS.post(event))
					return;
			}

			ItemStack itemstack = ei.getEntityItem();
			if (itemstack.stackSize <= 0)
				flag = true;
			else if (this.canBePickedUp == 1 && !player.inventory.addItemStackToInventory(itemstack))
				flag = false;

			if (flag)
			{
				this.playSound("random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
				player.onItemPickup(this, 1);
				this.setDead();
			}
		}
	}
}
 
Example 7
Project: ObsidianSuite   File: ObsidianAnimator.java   View source code 6 votes vote down vote up
@Mod.EventHandler
public void init(FMLInitializationEvent event)
{		
	FMLInterModComms.sendRuntimeMessage(MODID, "VersionChecker", "addVersionCheck", VERSION_LINK);
	
	instance = this;		
	proxy.init();
       
       EventHandler eventHandler = new EventHandler();
       MinecraftForge.EVENT_BUS.register(eventHandler);
	
       if(FMLCommonHandler.instance().getEffectiveSide().isClient())
           FMLCommonHandler.instance().bus().register(eventHandler);
       
       //Minecraft.getMinecraft().gameSettings.showInventoryAchievementHint = false;
       Minecraft.getMinecraft().gameSettings.saveOptions();
       
       //Stop space from activating buttons, allowing it to be used for adding keyframes in the timeline.
       InputMap im = (InputMap)UIManager.get("Button.focusInputMap");
       im.put(KeyStroke.getKeyStroke("pressed SPACE"), "none");
       im.put(KeyStroke.getKeyStroke("released SPACE"), "none");
}
 
Example 8
Project: ExPetrum   File: ExPCrop.java   View source code 6 votes vote down vote up
@Override
public void causeDamage(float damage)
{
	CropEvent.Damage dmgEvent = new CropEvent.Damage(this, this.getContainer().getWorld(), this.getContainer().getPos(), damage);
	if (this.isDead() || MinecraftForge.EVENT_BUS.post(dmgEvent))
	{
		return;
	}
	
	damage = dmgEvent.amount;
	this.setHealth(this.getHealth() - damage);
	if (this.isDead())
	{
		this.stats.type = EnumCrop.DEAD;
	}
}
 
Example 9
Project: UniversalRemote   File: UniversalRemote.java   View source code 6 votes vote down vote up
@EventHandler
  public void preInit(FMLPreInitializationEvent event){
  	Util.logger = new Logger(event.getModLog());

  	// find the fields we need regardless of obs
  	OpenGuiWrapper.findFields();

  	// register event handlers
  	MinecraftForge.EVENT_BUS.register(new Registrar());
  	MinecraftForge.EVENT_BUS.register(new VersionTracker());
  	MinecraftForge.EVENT_BUS.register(PlayerWorldSyncServer.INSTANCE);

// setup networking
  	RemoteGuiNetworkManager.INSTANCE.preInit(event);

  	VersionTracker.register(new UniversalRemoteVersionProvider());

  	proxy.preInit(event);

  	// fix broken config issues
  	UniversalRemoteConfiguration.validateConfig();
  }
 
Example 10
Project: CustomWorldGen   File: ChunkIOProvider.java   View source code 6 votes vote down vote up
public void syncCallback()
{
    if (chunk == null)
    {
        this.runCallbacks();
        return;
    }

    // Load Entities
    this.loader.loadEntities(this.chunkInfo.world, this.nbt.getCompoundTag("Level"), this.chunk);

    MinecraftForge.EVENT_BUS.post(new ChunkDataEvent.Load(this.chunk, this.nbt)); // Don't call ChunkDataEvent.Load async

    this.chunk.setLastSaveTime(provider.worldObj.getTotalWorldTime());
    this.provider.chunkGenerator.recreateStructures(this.chunk, this.chunkInfo.x, this.chunkInfo.z);

    provider.id2ChunkMap.put(ChunkPos.asLong(this.chunkInfo.x, this.chunkInfo.z), this.chunk);
    this.chunk.onChunkLoad();
    this.chunk.populateChunk(provider, provider.chunkGenerator);

    this.runCallbacks();
}
 
Example 11
Project: CustomWorldGen   File: ForgeEventFactory.java   View source code 5 votes vote down vote up
public static int onHoeUse(ItemStack stack, EntityPlayer player, World worldIn, BlockPos pos)
{
    UseHoeEvent event = new UseHoeEvent(player, stack, worldIn, pos);
    if (MinecraftForge.EVENT_BUS.post(event)) return -1;
    if (event.getResult() == Result.ALLOW)
    {
        stack.damageItem(1, player);
        return 1;
    }
    return 0;
}
 
Example 12
Project: CustomWorldGen   File: AutomaticEventSubscriber.java   View source code 5 votes vote down vote up
public static void inject(ModContainer mod, ASMDataTable data, Side side)
{
    FMLLog.fine("Attempting to inject @EventBusSubscriber classes into the eventbus for %s", mod.getModId());
    Set<ASMDataTable.ASMData> targets = data.getAnnotationsFor(mod).get(Mod.EventBusSubscriber.class.getName());
    ClassLoader mcl = Loader.instance().getModClassLoader();

    for (ASMDataTable.ASMData targ : targets)
    {
        try
        {
            //noinspection unchecked
            List<ModAnnotation.EnumHolder> sidesEnum = (List<ModAnnotation.EnumHolder>)targ.getAnnotationInfo().get("value");
            EnumSet<Side> sides = DEFAULT;
            if (sidesEnum != null) {
                sides = EnumSet.noneOf(Side.class);
                for (ModAnnotation.EnumHolder h: sidesEnum) {
                    sides.add(Side.valueOf(h.getValue()));
                }
            }
            if (sides == DEFAULT || sides.contains(side)) {
                FMLLog.fine("Found @EventBusSubscriber class %s", targ.getClassName());
                Class<?> subscriptionTarget = Class.forName(targ.getClassName(), true, mcl);
                MinecraftForge.EVENT_BUS.register(subscriptionTarget);
                FMLLog.fine("Injected @EventBusSubscriber class %s", targ.getClassName());
            }
        }
        catch (Exception e)
        {
            FMLLog.log(Level.ERROR, e, "An error occurred trying to load an EventBusSubscriber %s for modid %s", targ.getClassName(), mod.getModId());
            throw new LoaderException(e);
        }
    }
}
 
Example 13
Project: TFCPrimitiveTech   File: ItemSlingshot.java   View source code 5 votes vote down vote up
@Override
public ItemStack onItemRightClick(ItemStack is, World world, EntityPlayer player)
{
	ArrowNockEvent event = new ArrowNockEvent(player, is);
	MinecraftForge.EVENT_BUS.post(event);
	if (event.isCanceled())
		return event.result;

	if (player.capabilities.isCreativeMode || player.inventory.hasItem(ModItems.itemSharpStone) || player.inventory.hasItem(ModItems.itemHardStone) || player.inventory.hasItem(ModItems.itemSoftStone) )
		player.setItemInUse(is, this.getMaxItemUseDuration(is));

	return is;
}
 
Example 14
Project: ExPetrum   File: CropLogic.java   View source code 5 votes vote down vote up
public static void onWorldUpdate(ExPCrop crop)
{
	if (((VCSettings)(VoidApi.config.dataHolder)).recoveryMode)
	{
		return;
	}
	
	if (MinecraftForge.EVENT_BUS.post(new CropEvent.Update.Pre(crop, crop.getContainer().getWorld(), crop.getContainer().getPos())))
	{
		return;
	}
	
	Calendar prev = crop.timeKeeper;
	
	// Should not happen
	if (prev.getTime() == 0)
	{
		prev.setTime(IExPWorld.of(crop.getContainer().getWorld()).today().getTime());
	}
	else
	{
		Calendar current = IExPWorld.of(crop.getContainer().getWorld()).today();
		long ticksDelta = current.getTime() - prev.getTime();
		crop.timeKeeper = current;
		handleTimePassed(crop, ticksDelta, current);
	}
	
	if (crop.getContainer() != null && !crop.getContainer().isInvalid() && !crop.getContainer().getWorld().isAirBlock(crop.getContainer().getPos()))
	{
		MinecraftForge.EVENT_BUS.post(new CropEvent.Update.Post(crop, crop.getContainer().getWorld(), crop.getContainer().getPos()));
	}
}
 
Example 15
Project: pnc-repressurized   File: BlockTrackEntryInventory.java   View source code 5 votes vote down vote up
@Override
public boolean shouldTrackWithThisEntry(IBlockAccess world, BlockPos pos, IBlockState state, TileEntity te) {
    if (te instanceof TileEntityChest) {
        TileEntityChest chest = (TileEntityChest) te;
        if (chest.adjacentChestXNeg != null || chest.adjacentChestZNeg != null) return false;
    }

    return te != null
            && !invBlackList.contains(TileEntity.getKey(te.getClass()))
            && te.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)
            && !MinecraftForge.EVENT_BUS.post(new InventoryTrackEvent(te));
}
 
Example 16
Project: pnc-repressurized   File: GuiKeybindCheckBox.java   View source code 5 votes vote down vote up
public GuiKeybindCheckBox(int id, int x, int y, int color, String text, String keyBindingName) {
    super(id, x, y, color, text);
    this.keyBindingName = keyBindingName;
    keyBinding = setOrAddKeybind(keyBindingName, -1);//get the saved value.
    if (!trackedCheckboxes.containsKey(keyBindingName)) {
        checked = HelmetWidgetDefaults.INSTANCE.getKey(keyBindingName);
        trackedCheckboxes.put(keyBindingName, this);
        MinecraftForge.EVENT_BUS.register(this);
    } else {
        checked = trackedCheckboxes.get(keyBindingName).checked;
    }
}
 
Example 17
Project: ExPetrum   File: ExPBiomeDecorator.java   View source code 5 votes vote down vote up
public void pebblePassGenerate(World worldIn, Random rand, Biome biome, BlockPos pos)
{
	int x = rand.nextInt(16) + 8;
	int z = rand.nextInt(16) + 8;
	BlockPos at = worldIn.getHeight(pos.add(x, 0, z));
	EventGenPebble event = new EventGenPebble(worldIn, at, rand, genPebble);
	if (MinecraftForge.TERRAIN_GEN_BUS.post(event))
	{
		return;
	}
	
	event.generator.generate(worldIn, rand, at);
}
 
Example 18
Project: LagssieMC   File: Lagssie.java   View source code 5 votes vote down vote up
@EventHandler
public void init(FMLInitializationEvent event) {
    if (intervalServer > 0) {
        MinecraftForge.EVENT_BUS.register(new LagssieServer());
    }
    if (FMLCommonHandler.instance().getSide() == Side.CLIENT && intervalClient > 0) {
        initClient();
    }
}
 
Example 19
Project: Proyecto-DASI   File: ClientStateMachine.java   View source code 5 votes vote down vote up
public ClientStateMachine(ClientState initialState, MalmoModClient inputController)
{
    super(initialState);
    this.inputController = inputController;

    // Register ourself on the event busses, so we can harness the client tick:
    FMLCommonHandler.instance().bus().register(this);
    MinecraftForge.EVENT_BUS.register(this);
    MalmoMod.MalmoMessageHandler.registerForMessage(this, MalmoMessageType.SERVER_TEXT);
}
 
Example 20
Project: pnc-repressurized   File: TileEntityElectricCompressor.java   View source code 5 votes vote down vote up
@Override
public void invalidate() {
    if (getWorld() != null && !getWorld().isRemote) {
        MinecraftForge.EVENT_BUS.post(new EnergyTileUnloadEvent(this));
    }
    super.invalidate();
}
 
Example 21
Project: Game-Stages   File: PlayerDataHandler.java   View source code 5 votes vote down vote up
@Override
public void unlockStage (String stage) {

    final GameStageEvent event = new GameStageEvent.Add(this.getPlayer(), stage);
    MinecraftForge.EVENT_BUS.post(event);

    if (!event.isCanceled()) {
        this.unlockedStages.add(event.getStageName().toLowerCase());
        MinecraftForge.EVENT_BUS.post(new GameStageEvent.Added(this.getPlayer(), stage));
    }
}
 
Example 22
Project: minecraft-quiverbow   File: AquaAccelerator.java   View source code 5 votes vote down vote up
private void checkReloadFromWater(ItemStack stack, World world, EntityPlayer player)
  {
MovingObjectPosition movingobjectposition = this.getMovingObjectPositionFromPlayer(world, player, true);
FillBucketEvent event = new FillBucketEvent(player, stack, world, movingobjectposition);
      
if (MinecraftForge.EVENT_BUS.post(event)) { return; }

      MovingObjectPosition movObj = this.getMovingObjectPositionFromPlayer(world, player, true);

      if (movObj == null) { return; }	// Didn't click on anything in particular
      else
      {            
          if (movObj.typeOfHit == MovingObjectPosition.MovingObjectType.BLOCK)
          {
              int x = movObj.blockX;
              int y = movObj.blockY;
              int z = movObj.blockZ;

              if (!world.canMineBlock(player, x, y, z)) { return; }					// Not allowed to mine this, getting out of here
              if (!player.canPlayerEdit(x, y, z, movObj.sideHit, stack)) { return; }	// Not allowed to edit this, getting out of here

              Material material = world.getBlock(x, y, z).getMaterial();
              int meta = world.getBlockMetadata(x, y, z);

              // Is this water?
              if (material == Material.water && meta == 0)
              {
              	world.setBlockToAir(x, y, z);
              	stack.setItemDamage(0);
              	
                  return;
              }
              // else, not water
          }
          // else, didn't click on a block
      }
  }
 
Example 23
Project: Proyecto-DASI   File: ClientStateMachine.java   View source code 5 votes vote down vote up
public ClientStateMachine(ClientState initialState, MalmoModClient inputController)
{
    super(initialState);
    this.inputController = inputController;

    // Register ourself on the event busses, so we can harness the client tick:
    FMLCommonHandler.instance().bus().register(this);
    MinecraftForge.EVENT_BUS.register(this);
    MalmoMod.MalmoMessageHandler.registerForMessage(this, MalmoMessageType.SERVER_TEXT);
}
 
Example 24
Project: TFCPrimitiveTech   File: EntityProjectileSharpStone.java   View source code 5 votes vote down vote up
@Override
public void onCollideWithPlayer(EntityPlayer player)
{
	if (!this.worldObj.isRemote)
	{
		NBTTagCompound nbt = new NBTTagCompound();
		this.writeToNBT(nbt);

		boolean inground = nbt.hasKey("inGround") && nbt.getByte("inGround") == 1;
		if(inground)
		{
			boolean flag = this.canBePickedUp == 1 || (this.canBePickedUp == 2 && player.capabilities.isCreativeMode);

			EntityItem ei = new EntityItem(this.worldObj, this.posX, this.posY, this.posZ, new ItemStack(this.pickupItem, 1, 0));

			if (this.canBePickedUp == 1)
			{
				EntityItemPickupEvent event = new EntityItemPickupEvent(player, ei);

				if (MinecraftForge.EVENT_BUS.post(event))
					return;
			}

			ItemStack itemstack = ei.getEntityItem();
			if (itemstack.stackSize <= 0)
				flag = true;
			else if (this.canBePickedUp == 1 && !player.inventory.addItemStackToInventory(itemstack))
				flag = false;

			if (flag)
			{
				this.playSound("random.pop", 0.2F, ((this.rand.nextFloat() - this.rand.nextFloat()) * 0.7F + 1.0F) * 2.0F);
				player.onItemPickup(this, 1);
				this.setDead();
			}
		}
	}
}
 
Example 25
Project: CustomWorldGen   File: NetworkDispatcher.java   View source code 5 votes vote down vote up
@Override
public void disconnect(ChannelHandlerContext ctx, ChannelPromise promise) throws Exception
{
    if (side == Side.CLIENT)
    {
        MinecraftForge.EVENT_BUS.post(new FMLNetworkEvent.ClientDisconnectionFromServerEvent(manager));
    }
    else
    {
        MinecraftForge.EVENT_BUS.post(new FMLNetworkEvent.ServerDisconnectionFromClientEvent(manager));
    }
    cleanAttributes(ctx);
    ctx.disconnect(promise);
}
 
Example 26
Project: CreeperKiller   File: CreeperKiller.java   View source code 5 votes vote down vote up
@Mod.EventHandler
public void preInit(FMLPreInitializationEvent e) {
    LOG = e.getModLog();

    Map<Object, ModContainer> forgeListenerOwners = getForgeListenerOwners();
    // Remove CreeperHost ads.
    forgeListenerOwners.entrySet().stream()
            .filter(objectModContainerEntry -> objectModContainerEntry.getValue().getModId().equals("creeperhost"))
            .forEach(objectModContainerEntry -> {
                        LOG.info("CreeperKiller Removed {} handler from forge, CreeperHost ads will no longer be displayed", objectModContainerEntry.getKey().toString());
                        MinecraftForge.EVENT_BUS.unregister(objectModContainerEntry.getKey());
                    }
            );
}
 
Example 27
Project: chesttransporter   File: ItemChestTransporter.java   View source code 5 votes vote down vote up
ItemChestTransporter(TransporterType type)
{
    super();
    this.type = type;

    setUnlocalizedName("chesttransporter_" + type.iconName);
    setMaxStackSize(1);
    setMaxDamage(type.maxDamage);
    setCreativeTab(CreativeTabs.TOOLS);
    MinecraftForge.EVENT_BUS.register(this);
}
 
Example 28
Project: CreeperKiller   File: CreeperKiller.java   View source code 5 votes vote down vote up
public static Map<Object, ModContainer> getForgeListenerOwners() {
    try {
        return ((Map<Object, ModContainer>) FieldUtils.readField(MinecraftForge.EVENT_BUS, "listenerOwners", true));
    } catch (IllegalAccessException e) {
        e.printStackTrace();
    }
    return null;
}
 
Example 29
Project: CustomWorldGen   File: ForgeEventFactory.java   View source code 5 votes vote down vote up
public static boolean fireSleepingLocationCheck(EntityPlayer player, BlockPos sleepingLocation)
{
    SleepingLocationCheckEvent evt = new SleepingLocationCheckEvent(player, sleepingLocation);
    MinecraftForge.EVENT_BUS.post(evt);

    Result canContinueSleep = evt.getResult();
    if (canContinueSleep == Result.DEFAULT)
    {
        IBlockState state = player.worldObj.getBlockState(player.bedLocation);
        return state.getBlock().isBed(state, player.worldObj, player.bedLocation, player);
    }
    else
        return canContinueSleep == Result.ALLOW;
}
 
Example 30
Project: Industrial-Foregoing   File: CommonProxy.java   View source code 5 votes vote down vote up
public void preInit(FMLPreInitializationEvent event) {
    IFRegistries.poke();

    CraftingHelper.register(new ResourceLocation(Reference.MOD_ID, "configuration_value"), new ConfigurationConditionFactory());
    random = new Random();

    FluidsRegistry.registerFluids();
    BlockRegistry.poke();

    MinecraftForge.EVENT_BUS.register(new BlockRegistry());
    MinecraftForge.EVENT_BUS.register(new ItemRegistry());
    MinecraftForge.EVENT_BUS.register(new StrawRegistry());
    MinecraftForge.EVENT_BUS.register(new MeatFeederTickHandler());
    MinecraftForge.EVENT_BUS.register(new MobDeathHandler());
    MinecraftForge.EVENT_BUS.register(new WorldTickHandler());
    MinecraftForge.EVENT_BUS.register(new PlantRecollectableRegistryHandler());
    MinecraftForge.EVENT_BUS.register(new FakePlayerRideEntityHandler());
    MinecraftForge.EVENT_BUS.register(new PlantInteractorHarvestDropsHandler());

    NetworkRegistry.INSTANCE.registerGuiHandler(IndustrialForegoing.instance, new GuiHandler());

    CustomConfiguration.config = new Configuration(event.getSuggestedConfigurationFile());
    CustomConfiguration.config.load();
    CustomConfiguration.sync();
    CustomConfiguration.configValues = new HashMap<>();
    CustomConfiguration.configValues.put("useTEFrames", CustomConfiguration.config.getBoolean("useTEFrames", Configuration.CATEGORY_GENERAL, true, "Use Thermal Expansion Machine Frames instead of Tesla Core Lib"));

    if (Loader.isModLoaded("crafttweaker")) CraftTweakerHelper.register();

    EntityRegistry.registerModEntity(new ResourceLocation(Reference.MOD_ID, "pink_slime"), EntityPinkSlime.class, "pink_slime", 135135, IndustrialForegoing.instance, 32, 1, false, 10485860, 16777215);
    PINK_SLIME_LOOT = LootTableList.register(new ResourceLocation(Reference.MOD_ID, "entities/pink_slime"));
}
 
Example 31
Project: minecraft-quiverbow   File: QuiverBow.java   View source code 5 votes vote down vote up
@Override
public void onPlayerStoppedUsing(ItemStack stack, World par2World, EntityPlayer par3EntityPlayer, int par4)
{
	if (!par2World.isRemote)
	{
		int j = this.getMaxItemUseDuration(stack) - par4;		// Reduces the durability by the ItemInUseCount (probably 1 for anything that isn't a tool)

		ArrowLooseEvent event = new ArrowLooseEvent(par3EntityPlayer, stack, j);
		MinecraftForge.EVENT_BUS.post(event);
		if (event.isCanceled()) { return; }
		j = event.charge;

		if (this.getDamage(stack) == this.getMaxDamage()) {	return; }		// No arrows in the quiver? Getting out of here early

		float f = j / 20.0F;
		f = (f * f + f * 2.0F) / 3.0F;

		if (f < 0.1D) { return; }
		if (f > 1.0F) { f = 1.0F; }

		EntityArrow entityarrow = new EntityArrow(par2World, par3EntityPlayer, f * 2.0F);
		if (f == 1.0F) { entityarrow.setIsCritical(true); }

		par2World.playSoundAtEntity(par3EntityPlayer, "random.bow", 1.0F, 1.0F / (itemRand.nextFloat() * 0.4F + 1.2F) + f * 0.5F);

		if (par3EntityPlayer.capabilities.isCreativeMode) { entityarrow.canBePickedUp = 0; }
		else
		{
			entityarrow.canBePickedUp = 1;
			stack.setItemDamage(this.getDamage(stack) + 1);		// Reversed. MORE Damage for a shorter durability bar
		}

		par2World.spawnEntityInWorld(entityarrow);

	}
}
 
Example 32
Project: CustomWorldGen   File: ForgeEventFactory.java   View source code 5 votes vote down vote up
public static int onItemExpire(EntityItem entity, ItemStack item)
{
    if (item == null) return -1;
    ItemExpireEvent event = new ItemExpireEvent(entity, (item.getItem() == null ? 6000 : item.getItem().getEntityLifespan(item, entity.worldObj)));
    if (!MinecraftForge.EVENT_BUS.post(event)) return -1;
    return event.getExtraLife();
}
 
Example 33
Project: Proyecto-DASI   File: CraftingHelper.java   View source code 5 votes vote down vote up
/** Attempt to craft the given recipe.<br>
 * This pays no attention to tedious things like using the right crafting table / brewing stand etc, or getting the right shape.<br>
 * It simply takes the raw ingredients out of the player's inventory, and inserts the output of the recipe, if possible.
 * @param player the SERVER SIDE player that will do the crafting.
 * @param recipe the IRecipe we wish to craft.
 * @return true if the recipe had an output, and the player had the required ingredients to create it; false otherwise.
 */
public static boolean attemptCrafting(EntityPlayerMP player, IRecipe recipe)
{
    if (player == null || recipe == null)
        return false;

    ItemStack is = recipe.getRecipeOutput();
    if (is == null)
        return false;

    List<ItemStack> ingredients = getIngredients(recipe);
    if (playerHasIngredients(player, ingredients))
    {
        // We have the ingredients we need, so directly manipulate the inventory.
        // First, remove the ingredients:
        removeIngredientsFromPlayer(player, ingredients);
        // Now add the output of the recipe:

        ItemStack resultForInventory = is.copy();
        ItemStack resultForReward = is.copy();
        player.inventory.addItemStackToInventory(resultForInventory);
        RewardForCollectingItemImplementation.GainItemEvent event = new RewardForCollectingItemImplementation.GainItemEvent(resultForReward);
        MinecraftForge.EVENT_BUS.post(event);

        return true;
    }
    return false;
}
 
Example 34
Project: Proyecto-DASI   File: CraftingHelper.java   View source code 5 votes vote down vote up
/** Manually attempt to remove ingredients from the player's inventory.<br>
 * @param player
 * @param ingredients
 */
public static void removeIngredientsFromPlayer(EntityPlayerMP player, List<ItemStack> ingredients)
{
    ItemStack[] main = player.inventory.mainInventory;
    ItemStack[] arm = player.inventory.armorInventory;

    for (ItemStack isIngredient : ingredients)
    {
        int target = isIngredient.stackSize;
        for (int i = 0; i < main.length + arm.length && target > 0; i++)
        {
            ItemStack isPlayer = (i >= main.length) ? arm[i - main.length] : main[i];
            if (isPlayer != null && isIngredient != null && itemStackIngredientsMatch(isPlayer, isIngredient))
            {
                if (target >= isPlayer.stackSize)
                {
                    // Consume this stack:
                    target -= isPlayer.stackSize;
                    if (i >= main.length)
                        arm[i - main.length] = null;
                    else
                        main[i] = null;
                }
                else
                {
                    isPlayer.stackSize -= target;
                    target = 0;
                }
            }
        }
        ItemStack resultForReward = isIngredient.copy();
        RewardForDiscardingItemImplementation.LoseItemEvent event = new RewardForDiscardingItemImplementation.LoseItemEvent(resultForReward);
        MinecraftForge.EVENT_BUS.post(event);
    }
}
 
Example 35
Project: Clef   File: ProxyClient.java   View source code 5 votes vote down vote up
@Override
public void preInitMod()
{
    super.preInitMod();

    Clef.eventHandlerClient = new EventHandlerClient();
    MinecraftForge.EVENT_BUS.register(Clef.eventHandlerClient);
}
 
Example 36
Project: PrimalChests   File: PrimalChests.java   View source code 5 votes vote down vote up
@Mod.EventHandler
public void preinit(FMLPreInitializationEvent event) {
    MinecraftForge.EVENT_BUS.register(new PBlocks());
    PBlocks.preInit();
    GameRegistry.registerTileEntity(TileEntityPrimalChest.class, "tile_primal_chest");
    GameRegistry.registerTileEntity(TileEntityPrimalChestAdvanced.class, "tile_primal_chest_advanced");
}
 
Example 37
Project: MooncakeCraft   File: MooncakeProxy.java   View source code 5 votes vote down vote up
public void init(FMLInitializationEvent event) {
    for (int i = 0; i < MooncakeFillingType.VALUES.length; i++) {
        GameRegistry.addSmelting(new ItemStack(MooncakeConstants.RAW_MOONCAKE_ITEM, 1, i), new ItemStack(MooncakeConstants.MOONCAKE_ITEM, 1, i), 1.0f);
    }
    MinecraftForge.addGrassSeed(new ItemStack(MooncakeConstants.SESAME_SEED), 10);
    MinecraftForge.addGrassSeed(new ItemStack(MooncakeConstants.PEANUT_SEED), 10);
}
 
Example 38
Project: MeeCreeps   File: ClientProxy.java   View source code 5 votes vote down vote up
@Override
    public void preInit(FMLPreInitializationEvent e) {
        super.preInit(e);

        MinecraftForge.EVENT_BUS.register(this);
//        OBJLoader.INSTANCE.addDomain(MeeCreeps.MODID);
//        ModelLoaderRegistry.registerLoader(new BakedModelLoader());

        // Typically initialization of models and such goes here:
        ModEntities.initModels();
    }
 
Example 39
Project: CraftingParadiseMod   File: CraftingParadise.java   View source code 5 votes vote down vote up
@Mod.EventHandler
public void initialize(FMLInitializationEvent event)
{
    ModItems.initModels();
    ModBlocks.initModels();

    MinecraftForge.EVENT_BUS.register(new EntityHandler());
    proxy.initSideHandlers();

    PacketHandler.init();
    proxy.init();
}
 
Example 40
Project: World-Border   File: WorldBorder.java   View source code 5 votes vote down vote up
@SideOnly(Side.SERVER)
public void enableBlockPlaceListener(boolean enable)
{
    if      (enable)
        MinecraftForge.EVENT_BUS.register(this.blockPlaceListener = new BlockPlaceListener());
    else if (blockPlaceListener != null)
        MinecraftForge.EVENT_BUS.unregister(this.blockPlaceListener);
}