Jump to content

Recommended Posts

Posted

So I am having a problem with my tileentity for a wind turbine I am working on, I have got the wind turbine in the game, it is rendered correctly, and I don't crash when using it (except for shift clicking items into it) but, when I place more than one in the world, two strange things happen, one: the turbine rotor spins faster (I know this is an issue with the TileEntityRendererWindTurbine.class, but I cant figure out what exactly the issue is) and two: the second wind turbine I place in the world has the same amount of power as the first one, and it doubles the output speed, if I add a third one, it triples the output speed and makes the rotor spin even faster. I think the wind turbine isn't creating a new tileentity when it is added, and it is using all the data from the first wind turbine, but even that is strange because the items aren't duplicated across all the wind turbines, they are only in the one I place them in, only power is.

 

Here is my code (Just ask me if you need to see any other relavent classes)

 

 

TileEntityWindTurbine.class

 

 

package net.theepictekkit.generator.common.tileentity;

import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.tileentity.TileEntity;
import net.theepictekkit.generator.Generator;
import net.theepictekkit.generator.common.container.ContainerWindTurbine;
import net.theepictekkit.generator.common.energy.IEnergyGenerator;
import net.theepictekkit.generator.common.items.ItemHandler;

public class TileEntityWindTurbine extends TileEntity implements ISidedInventory, IEnergyGenerator {

public static float rotationAngle = 0;
public static float speed = 3.0F;
public static int worldHeight;
public static int weatherStrength;
public static float efficiency;


public static float output = 30.0F; //The energy being generated per rotation of the turbine;
public static float power = 0.0F; //The currently stored energy value
public static float generating = 0.0F; //The energy currently being generated
public static int bufferMax = 2560000; //The max energy the buffer can store
public static int outputMax = 8; //Can not generate more energy per tick than this (determined by the rotor type)
private static int rotorValue = 74;

public static int rotorType = 0;

public static boolean hasIronTurbine;
public static boolean hasSteelTurbine;
public static boolean hasCarbonTurbine;
public static boolean hasRotor;

public int direction;

public String inventoryName;

private ItemStack[] slots = new ItemStack[3];

public static ItemStack returnStackInSlot() {
	TileEntityWindTurbine tileEntity = new TileEntityWindTurbine();
	ItemStack itemStack = tileEntity.getStackInSlot(0);
	if (itemStack != null && itemStack.stackSize > 0) {
		return itemStack;
	} else {
		return null;
	}
}

public ItemStack getStackInSlot(int i) {
	return this.slots[i];
}

public void updateEntity() {

	if (this.getStackInSlot(0) != null) {
		if (this.getStackInSlot(0).getItem() == ItemHandler.itemTurbineRotorIron) {
			this.rotorType = 1;
		} else if (this.getStackInSlot(0).getItem() == ItemHandler.itemTurbineRotorSteel) {
			this.rotorType = 2;
		} else if (this.getStackInSlot(0).getItem() == ItemHandler.itemTurbineRotorCarbon) {
			this.rotorType = 3;
		}
		System.out.println(this.rotorType);
	} else {
		System.out.println("false");
		this.rotorType = 0;
	}
	if (this.rotorType > 0) {
		generating = output * speed * worldHeight / rotorValue;
		efficiency = (generating / outputMax) * 100;

		worldHeight = this.yCoord;

		rotationAngle += speed * worldHeight / 100;
		if (rotationAngle >= 360) {
			rotationAngle = 0;
		}


		power += output * speed * worldHeight / rotorValue;
		if (power > bufferMax) {
			power = bufferMax;
			this.generating = 0;
			this.efficiency = 0;
		}
		if (power != bufferMax && Generator.developmentMode == true) {
			System.out.println("Current energy stored in wind turbine located at X: " + this.xCoord + ", Y: " + this.yCoord + ", Z: " + this.zCoord + " is: " + this.power + "/" + this.bufferMax + "	Woops! must have accidently set to development mode. Please report this as a bug!");
		}
	} else {
		this.efficiency = 0;
		this.generating = 0;
	}
	/*ItemStack itemStack = this.getStackInSlot(0);

	if (this.getStackInSlot(0).getItem() == ItemHandler.itemTurbineRotorIron) {
		TileEntityRendererWindTurbine.instance.rotorType = 1;
	} if (this.getStackInSlot(0).getItem() == ItemHandler.itemTurbineRotorSteel) {
		this.hasRotor = true;
		TileEntityRendererWindTurbine.instance.rotorType = 2;
	} if (this.getStackInSlot(0).getItem() == ItemHandler.itemTurbineRotorCarbon) {
		this.hasRotor = true;
		TileEntityRendererWindTurbine.instance.rotorType = 3;
	} if (this.getStackInSlot(0).getItem() == null) {
		this.hasRotor = false;
		TileEntityRendererWindTurbine.instance.rotorType = 0;
	} else {
		this.hasRotor = false;
		TileEntityRendererWindTurbine.instance.rotorType = 1;
	}*/
}

public int getPowerScaled(int i) {
	return ((int)power * i / bufferMax);
}

public boolean isInvNameLocalized() {
	return this.inventoryName != null && this.inventoryName.length() > 0;
}

public void readFromNBT (NBTTagCompound nbt) {
	super.readFromNBT(nbt);

	NBTTagList nbtTagList = nbt.getTagList("Items", 10);
	this.slots = new ItemStack[this.getSizeInventory()];

	for (int i = 0; i < nbtTagList.tagCount(); i++) {
		NBTTagCompound nbt1 = (NBTTagCompound) nbtTagList.getCompoundTagAt(i);
		byte b0 = nbt1.getByte("Slot");

		if (b0 >= 0 && b0 < this.slots.length) {
			this.slots[b0] = ItemStack.loadItemStackFromNBT(nbt1);
		}
	}

	this.power = nbt.getShort("EnergyStored");

	if (nbt.hasKey("CustomName")) {
		this.inventoryName = nbt.getString("CustomName");
	}
}

public void writeToNBT (NBTTagCompound nbt) {
	super.writeToNBT(nbt);

	nbt.setShort(("EnergyStored"), (short)this.power);
	NBTTagList nbtTagList = new NBTTagList();

	for (int i = 0; i < this.slots.length; i++) {
		if (this.slots[i] != null) {
			NBTTagCompound nbtTagCompound = new NBTTagCompound();
			nbtTagCompound.setByte("Slot", (byte)i);
			this.slots[i].writeToNBT(nbtTagCompound);
			nbtTagList.appendTag(nbtTagCompound);
		}
	}

	nbt.setTag("Items", nbtTagList);

	if (this.isInvNameLocalized()) {
		nbt.setString("CustomName", this.inventoryName);
	}
}

public int maxOutput() {
	return this.outputMax;
}

public float currentOutput() {
	return this.output;
}

public int bufferSize() {
	return this.bufferMax;
}

public float bufferStored() {
	return this.power;
}

public boolean canPushEnergy() {
	return true;
}

public boolean stopIfFull() {
	return false;
}

public void getFuelValueFromItem(ItemStack item) {

}

public void onBufferOverload(int currentBufferStored, boolean isBufferFull) {

}

public int getSizeInventory() {
	return 64;
}

public ItemStack decrStackSize(int i, int j) {

	if (this.slots[i] != null) {
		ItemStack itemStack;
		if (this.slots[i].stackSize <= j) {
			itemStack = this.slots[i];
			this.slots[i] = null;
			return itemStack;
		} else {
			itemStack = this.slots[i].splitStack(j);

			if (this.slots[i].stackSize == 0) {
				this.slots[i] = null;
			}
		}
		return itemStack;
	}
	return null;
}

public ItemStack getStackInSlotOnClosing(int i) {
	if (this.slots[i] != null)  {
		ItemStack itemStack = this.slots[i];
		this.slots[i] = null;
		return itemStack;
	}
	return null;
}

public void setInventorySlotContents(int i, ItemStack itemStack) {

	this.slots[i] = itemStack;

	if (itemStack != null && itemStack.stackSize > this.getInventoryStackLimit())

		itemStack.stackSize = this.getInventoryStackLimit();
}

public String getInventoryName() {
	return this.hasCustomInventoryName() ? this.inventoryName : "container.furnace";
}

/**
 * Returns if the inventory is named
 */
public boolean hasCustomInventoryName()
{
	return this.inventoryName != null && this.inventoryName.length() > 0;
}

public void setGuiDisplayName(String str)
{
	this.inventoryName = str;
}

public int getInventoryStackLimit() {
	return 1;
}

public boolean isUseableByPlayer(EntityPlayer player) {
	return true;
}

public void openInventory() {

}

public void closeInventory() {

}

public static boolean isItemTurbine(ItemStack itemStack) {
	return itemStack.getItem() == ItemHandler.itemTurbineRotorIron ? true : (itemStack.getItem() == ItemHandler.itemTurbineRotorSteel ? true : (itemStack.getItem() == ItemHandler.itemTurbineRotorCarbon ? true : false));


}

public boolean isItemValidForSlot(int i, ItemStack itemStack) {
	return  i == 0 ? isItemTurbine(itemStack) : false;

}

public int[] getAccessibleSlotsFromSide(int p_94128_1_) {
	return null;
}

public boolean canInsertItem(int par1, ItemStack itemStack, int par3) {
	return this.isItemValidForSlot(par1, itemStack);
}

public boolean canExtractItem(int par1, ItemStack itemStack, int par3) {
	return par3 != 0 || par1 != 1;
}
}

 

 

 

TileEntityRendererWindTurbine.class

 

 

package net.theepictekkit.generator.client.blocks.renderer;

import net.minecraft.block.Block;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.entity.Entity;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.World;
import net.theepictekkit.generator.Reference;
import net.theepictekkit.generator.common.blocks.model.*;
import net.theepictekkit.generator.common.tileentity.TileEntityWindTurbine;

import org.lwjgl.opengl.GL11;

public class TileEntityRendererWindTurbine extends TileEntitySpecialRenderer {

private static String modid = Reference.MODID;
protected static final ResourceLocation textureTurbine = new ResourceLocation("generator:textures/models/WindTurbine.png");
protected static final ResourceLocation textureRotor1 = new ResourceLocation("generator:textures/models/TurbineRotorIron.png");
protected static final ResourceLocation textureRotor2 = new ResourceLocation("generator:textures/models/TurbineRotorSteel.png");
protected static final ResourceLocation textureRotor3 = new ResourceLocation("generator:textures/models/TurbineRotorCarbon.png");

private modelWindTurbine modelTurbine;
private modelTurbineRotor modelRotor;

public static boolean doRenderRotor;

public static TileEntityRendererWindTurbine instance;

public int rotorType = 0;

public TileEntityRendererWindTurbine() {
	modelTurbine = new modelWindTurbine();
	modelRotor = new modelTurbineRotor();

	this.instance = this;
}


public void adjustRotatePivotViaMeta(World world, int x, int y, int z) {

}

@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float f) {

	TileEntityWindTurbine tileEntity1 = (TileEntityWindTurbine) tileEntity;

	//Turbine Main
	GL11.glPushMatrix();
	GL11.glTranslatef((float)x + 0.5F, (float)y + 1.5F, (float)z + 0.5F);
	GL11.glRotatef(180, 0, 0, 1);
	Minecraft.getMinecraft().renderEngine.bindTexture(textureTurbine);
	GL11.glPushMatrix();
	this.modelTurbine.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
	GL11.glPopMatrix();
	GL11.glPopMatrix();


	//Turbine Rotor
	if (TileEntityWindTurbine.rotorType > 0) {
		GL11.glPushMatrix();
		GL11.glTranslatef((float)x + 0.5F, (float)y + 8.75F, (float)z + 0.5F);

		TileEntityWindTurbine windTurbine = (TileEntityWindTurbine) tileEntity.getWorldObj().getTileEntity(tileEntity.xCoord, tileEntity.yCoord, tileEntity.zCoord);
		GL11.glRotatef(TileEntityWindTurbine.rotationAngle, 0, 0, 1);

		if (TileEntityWindTurbine.rotorType == 1) {
			Minecraft.getMinecraft().renderEngine.bindTexture(textureRotor1);
		} else if (TileEntityWindTurbine.rotorType == 2) {
			Minecraft.getMinecraft().renderEngine.bindTexture(textureRotor2);
		} else if (TileEntityWindTurbine.rotorType == 3) {
			Minecraft.getMinecraft().renderEngine.bindTexture(textureRotor3);
		}
		GL11.glPushMatrix();
		this.modelRotor.render((Entity)null, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);
		GL11.glPopMatrix();
		GL11.glPopMatrix();
	}
}

public void adjustLightFixture(World world, int x, int y, int z, Block block) {
	Tessellator tessellator = Tessellator.instance;
	float brightness = block.getLightValue(world, x, y, z);
	int skyLight = world.getLightBrightnessForSkyBlocks(x, y, z, 0);
	int modifier = skyLight % 65536;
	int divModifier = skyLight / 65536;
	tessellator.setColorOpaque_F(brightness, brightness, brightness);
	OpenGlHelper.setLightmapTextureCoords(OpenGlHelper.lightmapTexUnit, (float)modifier, divModifier);
}
}

 

 

 

Oh, and another thing I would like to try and do and cant figure out is how to get the wind turbine to face the player, I know how to do this with a normal block, but it isn't working with the custom rendered block. I have tried to get the metadata of the block (because the orientation of the block is stored in metadata) and use that in a switch statement to rotate the model with GL11 in TileEntityRendererWindTurbine.class, but it didn't work.

 

Help would be much appreciated.

Thanks in advance

 

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

This is basic Java.

 

In Java (and other object-oriented languanges) whenever all of your instances are acting like they have the same value it means you're using static fields wrong.  You should study what static means.  Static means that all your instances will have the same value.

 

In you code you have the power levels static so all will have same power.

 

Just remove the static declaration and I think it should improve and maybe fix your problems.  Please also read about how static works to ensure you fully understand why this was a problem.

 

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

Posted

OK thankyou for your help.

 

now the energy and rotor speed is independent.

 

The reason I was using the static modifier was because other classes were referencing the tileEntityWindTurbine and was giving an error saying to change to static, so this now gives me another problem, things like rendering the rotor is now the same accross all turbines (I have 3 different types of rotors, and it renders the type in the inventory), I have created an instance of the wind turbines tileentity

TileEntityWindTurbine instance;

and made a constructer

public TileEntityWindTurbine() {
    this.instance = this;
}

 

so this seems to have fixed one problem, but created another.

 

Sorry if I seem like a bit of a noob to java, I am new to it.

 

oh, and right now, I am reading up about static modifiers (and some other stuff in java I don't understand)

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

Posted

You don't need the instance variable. You need to get the TileEntity in the render class using IBlockAccess#getTileEntity(x,y,z). That gives you a instance of the TileEntity which you can use for getting variables.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

That's not a actual Java thing, it is used on the forums here to indicate that you need to call that method from a instance of that class, instead of directly like it was a static method.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Posted

Sorry, but I still don't understand, i cant figure out what to do, i cant add IBlockAccess to renderTileEntityAt like

public void renderTileEntityAt(IBlockAccess iblockAccess, TileEntity tileEntity, double x, double y, double z, float f) {...

so what do I do?

I ask complicated questions, and apparently like to write really long detailed posts. But I also help others when I can.

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

    • When I first heard about Bitcoin back in 2018, I was skeptical. The idea of a decentralized, digital currency seemed too good to be true. But I was intrigued as I learned more about the technology behind it and its potential. I started small, investing just a few hundred dollars, dipping my toes into the cryptocurrency waters. At first, it was exhilarating to watch the value of my investment grow exponentially. I felt like I was part of the future, an early adopter of this revolutionary new asset. But that euphoria was short-lived. One day, I logged into my digital wallet only to find it empty - my Bitcoin had vanished without a trace. It turned out that the online exchange I had trusted had been hacked, and my funds were stolen. I was devastated, both financially and emotionally. All the potential I had seen in Bitcoin was tainted by the harsh reality that with decentralization came a lack of regulation and oversight. My hard-earned money was gone, lost to the ether of the digital world. This experience taught me a painful lesson about the price of trust in the uncharted territory of cryptocurrency. While the technology holds incredible promise, the risks can be catastrophic if you don't approach it with extreme caution. My Bitcoin investment gamble had failed, and I was left to pick up the pieces, wiser but poorer for having placed my faith in the wrong hands. My sincere appreciation goes to MUYERN TRUST HACKER. You are my hero in recovering my lost funds. Send a direct m a i l ( muyerntrusted ( @ ) mail-me ( . )c o m ) or message on whats app : + 1 ( 4-4-0 ) ( 3 -3 -5 ) ( 0-2-0-5 )
    • You could try posting a log (if there is no log at all, it may be the launcher you are using, the FAQ may have info on how to enable the log) as described in the FAQ, however this will probably need to be reported to/remedied by the mod author.
    • So me and a couple of friends are playing with a shitpost mod pack and one of the mods in the pack is corail tombstone and for some reason there is a problem with it, where on death to fire the player will get kicked out of the server and the tombstone will not spawn basically deleting an entire inventory, it doesn't matter what type of fire it is, whether it's from vanilla fire/lava, or from modded fire like ice&fire/lycanites and it's common enough to where everyone on the server has experienced at least once or twice and it doesn't give any crash log. a solution to this would be much appreciated thank you!
    • It is 1.12.2 - I have no idea if there is a 1.12 pack
  • Topics

×
×
  • Create New...

Important Information

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