Jump to content

Recommended Posts

Posted

As the title slightly states, I want my tile entity that is connected to my "egg" block to start incubating when there is a lit furnace nearby (within one block that is directly touching it, it is shown in the code below).

 

I have tried using the same code (with a few exceptions to some parts) in the block file in onBlockAddedToWorld() [i am pretty sure that's what its called] and onNeighbourChange() [or whatever it is called] and it didn't seem to set the set the egg incubating. That reminds me, I may have stuffed my incubating handler, so I will include that too.

 

Incubating Handler:

package rpg.handlers.events;

import net.minecraftforge.event.ForgeSubscribe;
import net.minecraftforge.event.entity.living.LivingEvent;
import rpg.blocks.tileentity.TileEntityPetEgg;
import rpg.network.packet.PacketSpawnPet;

public class IncubatorHandler {

@ForgeSubscribe
public void incubateEgg(LivingEvent event){
	TileEntityPetEgg petEgg = new TileEntityPetEgg();
	if(petEgg.canIncubate) {
		int timer = petEgg.getIncubatingTimer();
		timer++;
		if (timer >= petEgg.getIncubationTime()) {
			new PacketSpawnPet(event.entity.worldObj, petEgg.petType).sendToServer();
			System.out.println("Incubation finishes in: " +  timer + "EntityPlayer Updates");
		}
		if(timer == petEgg.getIncubationTime()) {
			petEgg.setIncubatingTimer(0);
		}
	}
}
}

 

TileEntityPetEgg (the tile entity in question)

package rpg.blocks.tileentity;

import net.minecraft.block.Block;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import rpg.blocks.BlockPetEgg;
import rpg.pet.EnumPetType;

public class TileEntityPetEgg extends TileEntity {

public boolean canIncubate = false;
public int incubatingTimer = 0;

public EnumPetType petType;

public TileEntityPetEgg() {
	this.petType = BlockPetEgg.petType;
}

/**
 * Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner uses this to count
 * ticks and creates a new spawn inside its implementation.
 */
public void updateEntity() {
	boolean isFurnaceAbove = this.worldObj.getBlockId(this.xCoord, this.yCoord + 1, this.zCoord) == Block.furnaceBurning.blockID;
	boolean isFurnaceBelow = this.worldObj.getBlockId(this.xCoord, this.yCoord - 1, this.zCoord) == Block.furnaceBurning.blockID;

	boolean isFurnaceLeft = this.worldObj.getBlockId(this.xCoord - 1, this.yCoord, this.zCoord) == Block.furnaceBurning.blockID;
	boolean isFurnaceRight = this.worldObj.getBlockId(this.xCoord + 1, this.yCoord, this.zCoord) == Block.furnaceBurning.blockID;

	boolean isFurnaceInFront = this.worldObj.getBlockId(this.xCoord, this.yCoord, this.zCoord + 1) == Block.furnaceBurning.blockID;
	boolean isFurnaceBehind = this.worldObj.getBlockId(this.xCoord, this.yCoord, this.zCoord - 1) == Block.furnaceBurning.blockID;

	boolean isFurnaceAboveOrBelow = isFurnaceAbove && isFurnaceBelow;
	boolean isFurnaceLeftOrRight = isFurnaceLeft && isFurnaceRight;
	boolean isFurnaceInFrontOrBehind = isFurnaceInFront && isFurnaceBehind;

	boolean furnaceIsNearby = isFurnaceAboveOrBelow && isFurnaceLeftOrRight && isFurnaceInFrontOrBehind;

	if(furnaceIsNearby) {
		this.canIncubate = true;
	}
}

public int getIncubationTime() {
	return BlockPetEgg.incubationTime;
}

@Override
public void writeToNBT(NBTTagCompound par1NBTTag) {
	super.writeToNBT(par1NBTTag);
	par1NBTTag.setBoolean("canIncubate", canIncubate);
	par1NBTTag.setInteger("incubatingTimer", incubatingTimer);

}

@Override
public void readFromNBT(NBTTagCompound par1NBTTag) {
	super.readFromNBT(par1NBTTag);
	canIncubate = par1NBTTag.getBoolean("canIncubate");
	incubatingTimer = par1NBTTag.getInteger("incubatingTimer");
}

public int getIncubatingTimer() {
	return this.incubatingTimer;
}

public int setIncubatingTimer(int newTime) {
	if(this.incubatingTimer != newTime)
		this.incubatingTimer = newTime;

	return this.incubatingTimer;
}
}

 

That should be all. There is no code in the block file anymore that has anything to do with the incubating of it. The only code that is to do with the TileEntityPetEgg is the registering it and such.

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

Posted

Your TE is created by a BlockContainer class.

 

That class is a subclass of Block.

 

Block has a function called onNeighborChanged

 

Use it.

Apparently I'm a complete and utter jerk and come to this forum just like to make fun of people, be confrontational, and make your personal life miserable.  If you think this is the case, JUST REPORT ME.  Otherwise you're just going to get reported when you reply to my posts and point it out, because odds are, I was trying to be nice.

 

Exception: If you do not understand Java, I WILL NOT HELP YOU and your thread will get locked.

 

DO NOT PM ME WITH PROBLEMS. No help will be given.

Posted

Your TE is created by a BlockContainer class.

 

That class is a subclass of Block.

 

Block has a function called onNeighborChanged

 

Use it.

Your TE is created by a BlockContainer class.

 

That class is a subclass of Block.

 

Block has a function called onNeighborChanged

 

Use it.

He said he did. I'd like to see that setup, though.

 

Okay. Ill show you what I had in a re-create of it.

 

Block code:

    TileEntityPetEgg petEgg = new TileEntityPetEgg();

    @Override
    /**
     * Called whenever the block is added into the world. Args: world, x, y, z
     */
    public void onBlockAdded(World par1World, int par2, int par3, int par4) {
        par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate(par1World));


        boolean isFurnaceAbove = par1World.getBlockId(par2, par3 + 1, par4) == Block.furnaceBurning.blockID;
        boolean isFurnaceBelow = par1World.getBlockId(par2, par3 - 1, par4) == Block.furnaceBurning.blockID;


        boolean isFurnaceLeft = par1World.getBlockId(par2 - 1, par3, par4) == Block.furnaceBurning.blockID;
        boolean isFurnaceRight = par1World.getBlockId(par2 + 1, par3, par4) == Block.furnaceBurning.blockID;


        boolean isFurnaceInFront = par1World.getBlockId(par2, par3, par4 + 1) == Block.furnaceBurning.blockID;
        boolean isFurnaceBehind = par1World.getBlockId(par2, par3, par4 - 1) == Block.furnaceBurning.blockID;


        boolean isFurnaceAboveOrBelow = isFurnaceAbove && isFurnaceBelow;
        boolean isFurnaceLeftOrRight = isFurnaceLeft && isFurnaceRight;
        boolean isFurnaceInFrontOrBehind = isFurnaceInFront && isFurnaceBehind;


        boolean furnaceIsNearby = isFurnaceAboveOrBelow && isFurnaceLeftOrRight && isFurnaceInFrontOrBehind;


        if(furnaceIsNearby) {
            this.petEgg.canIncubate = true;
        }
    }


    @Override
    /**
     * Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed (coordinates passed are
     * their own) Args: x, y, z, neighbor blockID
     */
    // This is the method to use to see if a furnace has been placed so that the egg can be incubated
    public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5) {
        par1World.scheduleBlockUpdate(par2, par3, par4, this.blockID, this.tickRate(par1World));


        boolean isFurnaceAbove = par1World.getBlockId(par2, par3 + 1, par4) == Block.furnaceBurning.blockID;
        boolean isFurnaceBelow = par1World.getBlockId(par2, par3 - 1, par4) == Block.furnaceBurning.blockID;


        boolean isFurnaceLeft = par1World.getBlockId(par2 - 1, par3, par4) == Block.furnaceBurning.blockID;
        boolean isFurnaceRight = par1World.getBlockId(par2 + 1, par3, par4) == Block.furnaceBurning.blockID;


        boolean isFurnaceInFront = par1World.getBlockId(par2, par3, par4 + 1) == Block.furnaceBurning.blockID;
        boolean isFurnaceBehind = par1World.getBlockId(par2, par3, par4 - 1) == Block.furnaceBurning.blockID;


        boolean isFurnaceAboveOrBelow = isFurnaceAbove && isFurnaceBelow;
        boolean isFurnaceLeftOrRight = isFurnaceLeft && isFurnaceRight;
        boolean isFurnaceInFrontOrBehind = isFurnaceInFront && isFurnaceBehind;


        boolean furnaceIsNearby = isFurnaceAboveOrBelow && isFurnaceLeftOrRight && isFurnaceInFrontOrBehind;


        if(furnaceIsNearby) {
            this.petEgg.canIncubate = true;
        }
    }

 

Those were the two methods I used, but the System.out wasn't appearing in my console whenever there was a lit furnace next to it.

I am Mew. The Legendary Psychic. I behave oddly and am always playing practical jokes.

 

I have also found that I really love making extremely long and extremely but sometimes not so descriptive variables. Sort of like what I just did there xD

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

    • Update: I stand corrected as I was able to dig up a relevant log from my earlier testing which highlights the overall issue but does not explain how to solve it. See, Diagnostic Logs for pack.mcmeta not found: https://pastebin.com/LXS8Rtna
    • Which mod was this? What are all the mods that were in use? It will help if enough information to replicate the problem is available.
    • I have been attempting to create a supplementary resource pack with Patchouli in order to add back the guidebook for Better End but unfortunately in every prototype I have made pack.mcmeta and my resource pack are not recognized. I have tested both zipped and unzipped and either way curseforge does not recognize my resource pack as existing. For testing I stripped my pack down to just the pack.mcmeta file and two empty folders labelled data and assets and I know the data folder is not the problem as firstly my first attempts just had an assets folder following Patchouli instructions and data came later in my flailing attempts to make anything in my pack work. The mcmeta file is not recognized whether or not I use this:  { "pack": { "pack_format": 15, "description": "A replacement for the BetterEnd Guide Book." } "language": { "en_US": { "name": "English", "region": "United States" } } } ,or this:  { "pack": { "pack_format": 15, "description": "A replacement for the BetterEnd Guide Book." } } I have made sure to only use lowercase and the pack folder is named better-end-guide. Is this some magic nonsense from me doing this manually instead of using an IDE or similar tool? Could it be because my files are by default in UTF-8 even though ANSI gives the same results? Is there a specific community secret tool I am supposed to use for zipping or specific settings? I am pulling my hair in distress. Unfortunately as there are no errors involved I lack logs to offer, if that disqualifies this thread please do not be harsh and instead if you can then please direct me to a forum with different rules and sufficiently respectful but knowledgeable as to be of assistance. Most of my experience with the programming community has been poor and so naturally I find myself wary.
    • I never picked up a tier 0 dragon skull to my knowledge. One of my other skulls must have bugged out and randomly became one. I was confused on what the heck it was and tried placing it, now the game will only crash because it can't render in whatever the heck the tier 0 skull is. This is on a server and it crashes anyone within render distance.
    • After setting up forge, making sure my drivers are updated, and downloading the create mod i tried to run forge and it said it crashed while trying to render the overlay, i heard about deleting a file called forge-client.toml, but when i looked at the config files(and all the files on my computer) it was nowhere to be found. https://pastebin.com/raw/TTyWWyeS
  • Topics

×
×
  • Create New...

Important Information

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