Jump to content

Make something happen to the player every x ticks or every tick.


sigurd4

Recommended Posts

im trying to have a variable that goes down every x ticks and is stored as nbt in the player. what is the proper function for this. (i read somewhere that it was onUpdate() but it must have been outdated) and how in the world do i set up a tick handler? here is my code:

 

package com.sigurd4.Bioshock.entity;

import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.world.World;
import net.minecraftforge.common.IExtendedEntityProperties;

public class ExtendedPlayer implements IExtendedEntityProperties
{
public static final int EVE_WATCHER = 23;
public static final int DRUNKNESS_WATCHER = 24;

public int eveMax;

public final static String EXT_PROP_NAME = "BioshockPlayer";
public final static String PLASMIDS_NAME = "plasmids";
public final static String TONICS_NAME = "tonics";

private final EntityPlayer player;
private boolean plasmidsOldManWinter;
private boolean plasmidsPeepingTom;
private boolean plasmidsBuckingBronco;
private boolean plasmidsCharge;
private boolean plasmidsDevilsKiss;
private boolean plasmidsIronsides;
private boolean plasmidsMurderOfCrows;
private boolean plasmidsPossession;
private boolean plasmidsReturnToSender;
private boolean plasmidsShockJockey;
private boolean plasmidsUndertow;

public ExtendedPlayer(EntityPlayer player)
{
	this.player = player;
	this.eveMax = 200;
	this.setCurrentEve(this.eveMax);
	this.setDrunkness(0);
}

public void onUpdate() //this doesnt work!!
{
	setDrunkness(getDrunkness()-1);
	System.out.println(getDrunkness());
}

/**
 * Returns ExtendedPlayer properties for player
 * This method is for convenience only; it will make your code look nicer
 */
public static final ExtendedPlayer get(EntityPlayer player)
{
	return (ExtendedPlayer) player.getExtendedProperties(EXT_PROP_NAME);
}

/**
 * Used to register these extended properties for the player during EntityConstructing event
 * This method is for convenience only; it makes my code look nicer.
 */
public static final void register(EntityPlayer player)
{
	player.registerExtendedProperties(ExtendedPlayer.EXT_PROP_NAME, new ExtendedPlayer(player));
}

@Override
public void init(Entity arg0, World arg1)
{

}

@Override
public void loadNBTData(NBTTagCompound compound) {
	NBTTagCompound properties = (NBTTagCompound) compound.getTag(EXT_PROP_NAME);
	NBTTagCompound plasmids = (NBTTagCompound) properties.getTag(PLASMIDS_NAME);
	//NBTTagList tonics = (NBTTagList) properties.getTag(TONICS_NAME);
	this.player.getDataWatcher().updateObject(EVE_WATCHER, properties.getInteger("Eve"));
	this.player.getDataWatcher().updateObject(DRUNKNESS_WATCHER, properties.getInteger("Drunkness"));
	this.eveMax = properties.getInteger("EveMax");
	this.plasmidsOldManWinter = plasmids.getBoolean("oldManWinter");
	this.plasmidsPeepingTom = plasmids.getBoolean("peepingTom");
	this.plasmidsBuckingBronco = plasmids.getBoolean("buckingBronco");
	this.plasmidsCharge = plasmids.getBoolean("charge");
	this.plasmidsDevilsKiss = plasmids.getBoolean("devilsKiss");
	this.plasmidsIronsides = plasmids.getBoolean("ironsides");
	this.plasmidsMurderOfCrows = plasmids.getBoolean("murderOfCrows");
	this.plasmidsPossession = plasmids.getBoolean("possession");
	this.plasmidsReturnToSender = plasmids.getBoolean("returnToSender");
	this.plasmidsShockJockey = plasmids.getBoolean("shockJockey");
	this.plasmidsUndertow = plasmids.getBoolean("undertow");
}

@Override
public void saveNBTData(NBTTagCompound compound) {
	NBTTagCompound properties = new NBTTagCompound();
	NBTTagCompound plasmids = new NBTTagCompound();
	NBTTagList tonics = new NBTTagList();
	compound.setTag(EXT_PROP_NAME, properties);
	properties.setTag(PLASMIDS_NAME, plasmids);
	properties.setTag(TONICS_NAME, tonics);
	properties.setInteger("Eve", this.player.getDataWatcher().getWatchableObjectInt(EVE_WATCHER));
	properties.setInteger("Drunkness", this.player.getDataWatcher().getWatchableObjectInt(DRUNKNESS_WATCHER));
	properties.setInteger("EveMax", this.eveMax);
	plasmids.setBoolean("oldManWinter", this.plasmidsOldManWinter);
	plasmids.setBoolean("peepingTom", this.plasmidsPeepingTom);
	plasmids.setBoolean("buckingBronco", this.plasmidsBuckingBronco);
	plasmids.setBoolean("charge", this.plasmidsCharge);
	plasmids.setBoolean("devilsKiss", this.plasmidsDevilsKiss);
	plasmids.setBoolean("ironsides", this.plasmidsIronsides);
	plasmids.setBoolean("murderOfCrows", this.plasmidsMurderOfCrows);
	plasmids.setBoolean("possession", this.plasmidsPossession);
	plasmids.setBoolean("returnToSender", this.plasmidsReturnToSender);
	plasmids.setBoolean("shockJockey", this.plasmidsShockJockey);
	plasmids.setBoolean("undertow", this.plasmidsUndertow);
}

public final boolean consumeEve(int amount)
{
	int eve = this.player.getDataWatcher().getWatchableObjectInt(EVE_WATCHER);

	boolean sufficient = amount <= eve;
	eve -= (amount < eve ? amount : eve);

	this.player.getDataWatcher().updateObject(EVE_WATCHER, eve);

	return sufficient;
}

public final int getMaxEve()
{
	return eveMax;
}

public final int getCurrentEve()
{
	return this.player.getDataWatcher().getWatchableObjectInt(EVE_WATCHER);
}

public final int getDrunkness()
{
	return this.player.getDataWatcher().getWatchableObjectInt(DRUNKNESS_WATCHER);
}

public final void setCurrentEve(int amount)
{
	this.player.getDataWatcher().updateObject(EVE_WATCHER, (amount < this.eveMax ? amount : this.eveMax));
}

public final void setDrunkness(int amount)
{
	this.player.getDataWatcher().updateObject(DRUNKNESS_WATCHER, amount);
}

public boolean hasPlasmid(String i)
{
	boolean b = false;
	if(i=="oldManWinter"){b=this.plasmidsOldManWinter;}
	if(i=="peepingTom"){b=this.plasmidsPeepingTom;}
	if(i=="buckingBronco"){b=this.plasmidsBuckingBronco;}
	if(i=="charge"){b=this.plasmidsCharge;}
	if(i=="devilsKiss"){b=this.plasmidsDevilsKiss;}
	if(i=="ironsides"){b=this.plasmidsIronsides;}
	if(i=="murderOfCrows"){b=this.plasmidsMurderOfCrows;}
	if(i=="possession"){b=this.plasmidsPossession;}
	if(i=="returnToSender"){b=this.plasmidsReturnToSender;}
	if(i=="shockJockey"){b=this.plasmidsShockJockey;}
	if(i=="undertow"){b=this.plasmidsUndertow;}
	return b;
}

public void givePlasmid(String i, boolean b)
{
	if(i=="oldManWinter"){b=this.plasmidsOldManWinter;}
	if(i=="peepingTom"){b=this.plasmidsPeepingTom;}
	if(i=="buckingBronco"){this.plasmidsBuckingBronco=b;}
	if(i=="charge"){this.plasmidsCharge=b;}
	if(i=="devilsKiss"){this.plasmidsDevilsKiss=b;}
	if(i=="ironsides"){this.plasmidsIronsides=b;}
	if(i=="murderOfCrows"){this.plasmidsMurderOfCrows=b;}
	if(i=="possession"){this.plasmidsPossession=b;}
	if(i=="returnToSender"){this.plasmidsReturnToSender=b;}
	if(i=="shockJockey"){this.plasmidsShockJockey=b;}
	if(i=="undertow"){this.plasmidsUndertow=b;}
}
}

 

i dont know what to do and its hard to find any tutorials that are up to date.

http://www.planetminecraft.com/member/sigurd4

I'm making the bioshock mod!

Link to comment
Share on other sites

how in the world do i set up a tick handler?  ...

i dont know what to do and its hard to find any tutorials that are up to date.

 

I've just drafted a tutorial on 1.7.2 event handling.  There is a lot of information there, but it should explain the concepts, how to register handlers, and list of various available events.

 

As diesieben07 advises, there is PlayerTickHandler (on FML event bus) available.  Just create a counter there that you can test to see that so many ticks have gone by and you can use event.player to find the player and then you can call his NBT handling methods.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Okay, I'm still planning to augment the tutorials with full github examples, although I did put a lot of instruction into the tutorial.  I'll see if I can make a clearer summary though because I guess I do have a lot of information there.

 

The basic idea is:

1) Create an event handling class, call it whatever you want.  I give an example of such a class in the tutorial.

2) Put a method in it that follows the example in my tutorial.  In needs to have the @SubscribeEvent annotation and the parameter must be the type of event you're trying to handle (I put lists of pretty much all known events in the tutorial).  That method should do whatever you want when the event happens.

3) register the handling class to the event bus.  This is done in your main class (or CommonProxy) in the init() method.  I give examples of registering the class to the bus in my tutorial.

 

That's pretty much it.

Check out my tutorials here: http://jabelarminecraft.blogspot.com/

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • リアルタイムロトホールダンバー*BCGAME33·COM▧サンシティロト中継リアルタイムイエメンロトポーカー大会[本社お問い合わせテレJBOX7]リアルタイムロト▤*グループトークゲンティングハイランドカジノロト募集リアルタイムグランドレスカジノリアルタイムロト検証[総販お問い合わせカカオトークJBOX7]リアルタイムロト♧*動画フィジーロトホールダンパブリアルタイムイエメンリアルタイムロットユーチューブ[各種オフィコミュニティ制作]リアルロット♧▦サイトサントメプリンシペロットカジノパブ リアル時間バーデンバーデンバーデンバーデンライブ ロトトーナメント[マーケティングお問い合わせ] ロンドン ロトトトーナメント [スポーツ本社]リアルタイムロト⊙♤アクセスバハマロト戦略リアルタイムコートジボワールリアルタイムロトグループトーク[トト本社お問い合わせ]リアルタイムロト▽ポーカー大会フォールズビューカジノロト方法リアルタイムシエラレオネリアルタイムロト業者[トト総販購入]リアルタイムロト▼㏘賭博場フォックスウッドカジノロト接続リアルタイム米国リアルタイムロット戦略[カジノ総販]リアルロット‡♥サイトリオオールスイートカジノロットホールダンパブ実時間台湾実時間ロット総販[大和本社]実時間宝くじモザムバスカラオット総販[大和本社実時間ロット総販]実時間宝くじ ロトYouTube [BCGAMEBCゲーム総販お問い合わせ] お知らせ設定おすすめ購読いいですね
    • 爱媛小姐亚东 ㏇BCGAME55·COM 爱媛小姐 抖音 掷铅球 爱媛小姐 Kakao Talk乒乓球小姐地图 速度小姐位置[本社文电话 @JBOX7] 爱媛小姐系统引导爱媛小姐链接自由式小姐广告板球姑娘社区[总经销文的 Kakao Talk JBOX7]爱媛姑娘最新地址引导爱媛妹儿童跳水姑娘登录[各种官方网络社区制作爱媛少女故事]业余爱好少女运动网[营销广告板球姑娘网站] 单杠艾希梅小姐公开聊天速度小姐广播短道速滑小姐巡回赛[体育总公司]艾希梅小姐地图按摩艾希梅小姐聚会信息手球小姐链接滑冰小姐最新地址[TOTO总公司咨询]艾希梅小姐YouTube足球艾希梅姑娘聚会信息地板运动姑娘验证壁球姑娘聚会信息[TOTO总经销购买]艾希梅姑娘度假村跳水艾希梅姑娘联谊会滑雪姑娘链接游泳[赌场总经销]艾希梅姑娘视频认证 跆拳道姑娘拳击线故事[SOOHIMESKO] YouTube跳水爱媛小姐链接美式足球小姐地图拳击小姐验证[赛马总经销]爱媛小姐网站网式足球爱媛小姐YouTube曲棍球小姐最新地址T-ball小姐位置[BCGAME BC游戏总经销咨询]通知设置推荐订阅点赞
    • インターネットカジノゲームセンター*BCGAME33·COM△ソマリランドカジノ試合インターネットベラジオカジノ放送[本社お問い合わせテレJBOX7]インターネットカジノ◑↑中継アルバニアカジノ総販インターネットニカラグアインターネットカジノ本社[総販お問い合わせカカオトークJBOX7]インターネットカジノ◁◈リーグポルトガルカジノ検証インターネットマリインターネットカジノ戦略[各種オフィコミュニティ制作]ネットカジノ ▶○ゲームミクロネシアカジノポーカー大会ネット ヨーロッパネット カジノ接続[マーケティングお問い合わせ]ネット カジノ ⇒ グループトーク ラトビア カジノバカラパブ ネットガイアナ ネット カジノ本社] インド カジノ本社 キャッシュゲーム[スポーツ本社]インターネットカジノ*☏賭博場カーボベルデカジノパブインターネットブルネイインターネットカジノ中継[ト本社お問い合わせ]インターネットカジノ♣◑動画ドミニカカジノホールダンパブインターネットアフリカインターネットカジノゲーム場[トト総販購入]インターネットカジノ←♧サイトフォールズビューカジノサイトインターネットアイランドネットカジノ業者[梶野総販]ネットカジノ↕*キャッシュゲームボリビアカジノ放送ネットキリバス旅行[大和本社]ネットカジノ◈▧検証アカジノ カジノ カジノ カジノ中継 [バカラ総販] バーベキュー場 チリ総販 [競馬総販]イスラエルカジノ放送 コンゴカジノキャッシュゲーム [BCGAMEBCゲーム総販お問い合わせ] お知らせ設定おすすめ購読いいですね
    • Gaga和Standbar链接♥BCGAME55·COM&Gaga和Standbar推荐的奥运会Gaga和Standbar营业场所招募Maru运动Standbar总经销滑雪Standbar YouTube[本社咨询的Tele @JBOX7] Gaga和Standbar营业场所招募警报Gaga和Standbar旅行排球Standbar Telegram橄榄球支架地址[总经销的Kakao Talk JBOX7] Gaga和STAND BAR故事赛艇比赛场斯坦邦士官司的制作组] Standbar网站【赌场总公司】Gaga和Standbar营业所招募橄榄球Gaga和Standbar网站最新地址硬地滚球Standbar位置足球Standbar亚东【体育总公司】Gaga和Standbar社区滑冰Standbar社区警报Standbar地方【Toto总公司咨询】Gaga和Sendeba网站拳击Gaga和STANDBAR Telegram乒乓球stan Bagram推荐高山滑雪推特【Toke】购买Toka和STANGATE STANGATTANGATE STAN Gaga和SET Gaga和Standbar度假村排球Standbar连接掷铁饼线[BAKARA总经销] Gaga和Standbatictalk 足球 Gaga和Standbar亚东 奥林匹克 Standbar亚东 Speed Standbar验证[赛马总经销] Gaga和Standbar Open聊天格器 Gaga和Standbar Story Anma Stadema Open聊天诱导 Stant bar的地方[BCGAME BC游戏总经销咨询] 设置通知 订阅 推荐点赞 点赞
    • ライブグラフ ホールダンバー ※BCGAME33·COM●イエメングラフ ホールダンパブ ライブオセアニアグラフ接続[本社お問い合わせテレJBOX7]ライブグラフ↙▥検証マーシャル諸島グラフツアーライブリトアニアライブグラフアドレス[総販お問い合わせカカオトークJBOX7]ライブグラフ↑⊙住所ブラジルグラフおすすめライブニカラグアライブグラフ本社[各種オフィコミュニティ制作]ライヴグラフ♬@戦略トルコグラフサイトライヴナミビアライヴグラフ グループトーク[マーケティングお問い合わせ]ライヴグラフ←™方法 クラウンカジノグラフ接続ライヴスロバキアライヴ賭博場[カジノ本社]ライヴ·リーグ総募集 [スポーツ本社]ライブグラフ↓☆検証 セントルシア グラフコミュニティライブ 東ティモールライブグラフコミュニティ[トト本社お問い合わせ]ライブグラフ라이브(株)ゲームイエメングラフ YouTubeライブ 米国ライブグラフサイト[トト総販購入]ライブグラフ㈱◁方法リオオールスイートカジノグラフ 動画ライブ北マケドニアライヴチャートツアー[カジノ総販]ライヴグラフ ▶↑映像サンマリノグラフおすすめ ライヴBCGAMEカジノライヴグラフ旅行[大和本社ベネチアンカジノグラフ中継ライヴアメリカライヴグラフおすすめ[バカラ総販]ライヴ·シンガポール·ライヴ·リーグ·グラッパレイブ·グラップ·グラップ· [競馬総販]アイスランド グラフ コミュニティ モンテカルログラフ バカラパブ [BCGAME BCゲーム総販お問い合わせ] お知らせ設定おすすめ購読いいですね
  • Topics

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.