Первый пост здесь.
У меня небольшая проблема с моделями TESR и Java;
Итак, во-первых, я не новичок в Java, а также в программировании, но у меня нет большого опыта работы с кузницей.
Мне было интересно масштабировать куб из этой модели в соответствии со значением, предоставленным TileEntity.
Я уже пытался создать переменные в модели и изменить их внешне, но не получилось. До этого модель рендерилась в мире, в правильном месте и т. Д.
Теперь я попытался добавить значения масштабирования в конструктор моей модели, и теперь модель даже не рендерится в мире.
//Model Class
package com.gpginc.gp_extended.blocks.renderer.models;
//Made with Blockbench
//Paste this code into your mod.
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelBox;
import net.minecraft.client.model.ModelRenderer;
import net.minecraft.entity.Entity;
public class ModelFluidContainer extends ModelBase {
private final ModelRenderer bone;
private final ModelRenderer glasses_left;
private final ModelRenderer glasses_right;
private final ModelRenderer lava;
private final ModelRenderer water;
/**
* I've tried changing this values, and they were placed where u found water_y and lava_y, respectively
*/
public int waterY = 0;
public int lavaY = 0;
public ModelFluidContainer(int water_y, int lava_y) {
textureWidth = 128;
textureHeight = 128;
bone = new ModelRenderer(this);
bone.setRotationPoint(0.0F, 24.0F, 0.0F);
bone.cubeList.add(new ModelBox(bone, 56, 0, -8.0F, -1.0F, -8.0F, 16, 1, 16, 0.0F, false));
bone.cubeList.add(new ModelBox(bone, 0, 28, -2.0F, -15.0F, -8.0F, 4, 14, 16, 0.0F, false));
bone.cubeList.add(new ModelBox(bone, 0, 49, -8.0F, -16.0F, -8.0F, 16, 1, 1, 0.0F, false));
bone.cubeList.add(new ModelBox(bone, 0, 55, -8.0F, -16.0F, 7.0F, 16, 1, 1, 0.0F, false));
bone.cubeList.add(new ModelBox(bone, 1, 35, -2.0F, -16.0F, -7.0F, 4, 1, 14, 0.0F, false));
bone.cubeList.add(new ModelBox(bone, 4, 40, 7.0F, -16.0F, -7.0F, 1, 1, 14, 0.0F, false));
bone.cubeList.add(new ModelBox(bone, 4, 41, -8.0F, -16.0F, -7.0F, 1, 1, 14, 0.0F, false));
glasses_left = new ModelRenderer(this);
glasses_left.setRotationPoint(0.0F, 24.0F, 0.0F);
glasses_left.cubeList.add(new ModelBox(glasses_left, 0, 0, 7.0F, -15.0F, -7.0F, 0, 14, 14, 0.0F, false));
glasses_left.cubeList.add(new ModelBox(glasses_left, 9, 0, 2.0F, -15.0F, -7.0F, 5, 14, 0, 0.0F, false));
glasses_left.cubeList.add(new ModelBox(glasses_left, 9, 0, 2.0F, -15.0F, 7.0F, 5, 14, 0, 0.0F, false));
glasses_right = new ModelRenderer(this);
glasses_right.setRotationPoint(0.0F, 24.0F, 0.0F);
setRotationAngle(glasses_right, 0.0F, 3.1416F, 0.0F);
glasses_right.cubeList.add(new ModelBox(glasses_right, 0, 0, 7.0F, -15.0F, -7.0F, 0, 14, 14, 0.0F, false));
glasses_right.cubeList.add(new ModelBox(glasses_right, 9, 0, 2.0F, -15.0F, -7.0F, 5, 14, 0, 0.0F, false));
glasses_right.cubeList.add(new ModelBox(glasses_right, 9, 0, 2.0F, -15.0F, 7.0F, 5, 14, 0, 0.0F, false));
lava = new ModelRenderer(this);
lava.setRotationPoint(0.0F, 24.0F, 0.0F);
lava.cubeList.add(new ModelBox(lava, 88, 21, 2.0F, -1.0F, -6.7F, 4, lava_y, 13, 0.0F, false));
water = new ModelRenderer(this);
water.setRotationPoint(0.0F, 24.0F, 0.0F);
water.cubeList.add(new ModelBox(water, 90, 80, -6.7F, -1.0F, -7.0F, 4, water_y, 13, 0.0F, false));
}
@Override
public void render(Entity entity, float f, float f1, float f2, float f3, float f4, float f5) {
bone.render(f5);
glasses_left.render(f5);
glasses_right.render(f5);
lava.render(f5);
water.render(f5);
}
public void setRotationAngle(ModelRenderer modelRenderer, float x, float y, float z) {
modelRenderer.rotateAngleX = x;
modelRenderer.rotateAngleY = y;
modelRenderer.rotateAngleZ = z;
}
}
//TESR class
package com.gpginc.gp_extended.blocks.renderer.tileentity;
import com.gpginc.gp_extended.blocks.machines.fluidcontainer.FluidContainerBlock;
import com.gpginc.gp_extended.blocks.machines.fluidcontainer.TileEntityFluidContainer;
import com.gpginc.gp_extended.blocks.renderer.models.ModelFluidContainer;
import com.gpginc.gp_extended.util.Reference;
import net.minecraft.block.Block;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class TileEntityFluidContainerRenderer extends TileEntitySpecialRenderer<TileEntityFluidContainer>
{
private static final ResourceLocation TEXTURE_ALL = new ResourceLocation(Reference.MOD_ID + ":textures/blocks/special/fluid_block_container.png");
public TileEntityFluidContainerRenderer() {}
public void render(TileEntityFluidContainer te, double x, double y, double z, float partialTicks, int destroyStage, float alpha)
{
GlStateManager.enableDepth();
GlStateManager.depthFunc(515);
GlStateManager.depthMask(true);
ModelFluidContainer newmodel = new ModelFluidContainer(Math.round(te.waterValue / 10), Math.round(te.lavaValue / 10));
if (destroyStage >= 0)
{
this.bindTexture(DESTROY_STAGES[destroyStage]);
GlStateManager.matrixMode(5890);
GlStateManager.pushMatrix();
GlStateManager.scale(4.0F, 4.0F, 1.0F);
GlStateManager.translate(0.0625F, 0.0625F, 0.0625F);
GlStateManager.matrixMode(5888);
} else this.bindTexture(TEXTURE_ALL);
GlStateManager.pushMatrix();
GlStateManager.enableRescaleNormal();
GlStateManager.translate((float)x, (float)y + 1.0F, (float)z + 1.0F);
GlStateManager.scale(1.0F, -1.0F, -1.0F);
GlStateManager.translate(0.5f,-0.5f,0.5f);
newmodel.waterY = Math.round(te.waterValue / 10);
newmodel.lavaY = Math.round(te.lavaValue / 10);
newmodel.render(null, 0, 0, 0, 0, 0, 0.0625f);
GlStateManager.disableRescaleNormal();
GlStateManager.popMatrix();
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
if (destroyStage >= 0)
{
GlStateManager.matrixMode(5890);
GlStateManager.popMatrix();
GlStateManager.matrixMode(5888);
}
}
}
//For some use, tileentity class
package com.gpginc.gp_extended.blocks.machines.fluidcontainer;
import java.util.logging.Logger;
import com.gpginc.gp_extended.blocks.machines.fluidcontainer.container.ContainerFluidContainer;
import com.gpginc.gp_extended.util.Reference;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.init.Items;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.ItemStackHelper;
import net.minecraft.item.ItemBucket;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntityLockableLoot;
import net.minecraft.util.EnumHand;
import net.minecraft.util.ITickable;
import net.minecraft.util.NonNullList;
public class TileEntityFluidContainer extends TileEntityLockableLoot implements ITickable
{
private NonNullList<ItemStack> blockContents = NonNullList.<ItemStack>withSize(16, ItemStack.EMPTY);
public int waterValue = 0;
public int lavaValue = 0;
private int currentWaterValue, currentLavaValue;
private final int maxWater = 100;
private final int maxLava = 100;
private int numPlayersUsing, tickSinceSync;
@Override
public boolean hasFastRenderer()
{
return true;
}
public void increaseWaterCount(EntityPlayer player, EnumHand hand)
{
if(player.getHeldItem(hand).getItem() instanceof ItemBucket &&!player.isCreative())
{
player.getHeldItem(hand).shrink(1);
player.setHeldItem(hand, new ItemStack(Items.BUCKET));
}
++this.waterValue;
Logger.getGlobal().warning("AUMENTO DE AGUAA "+this.waterValue);
}
public void increaseLavaCount(EntityPlayer player, EnumHand hand)
{
if(player.getHeldItem(hand).getItem() instanceof ItemBucket&&!player.isCreative())
{
player.getHeldItem(hand).shrink(1);
player.setHeldItem(hand, new ItemStack(Items.BUCKET));
}
++this.lavaValue;
Logger.getGlobal().warning("AUMENTO DE lavaaa " + this.lavaValue);
}
@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
this.blockContents = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
if(!this.checkLootAndRead(compound)) ItemStackHelper.loadAllItems(compound, blockContents);
if(compound.hasKey("CustomName", 8)) this.customName = compound.getString("CustomName");
}
@Override
public NBTTagCompound writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
if(!this.checkLootAndRead(compound)) ItemStackHelper.saveAllItems(compound, blockContents);
if(compound.hasKey("CustomName", 8)) compound.setString("CustomName", this.customName);
return compound;
}
@Override
public String getName()
{
return this.hasCustomName() ? this.customName : "container.fluid_container";
}
public void setCustomName(String displayName)
{
this.customName = displayName;
}
@Override
public int getSizeInventory() {
return 16;
}
@Override
public boolean isEmpty()
{
for(ItemStack stack: this.blockContents)
{
if(!stack.isEmpty()) return false;
}
return true;
}
@Override
public int getInventoryStackLimit()
{
return 128;
}
@Override
public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
{
return new ContainerFluidContainer(playerInventory, this, playerIn);
}
@Override
public String getGuiID()
{
return Reference.MOD_ID + ":fluid_container";
}
@Override
protected NonNullList<ItemStack> getItems()
{
return this.blockContents;
}
@Override
public void openInventory(EntityPlayer player)
{
++this.numPlayersUsing;
this.world.addBlockEvent(this.pos, this.getBlockType(), 1, this.numPlayersUsing);
this.world.notifyNeighborsOfStateChange(this.pos, this.getBlockType(), true);
}
@Override
public void closeInventory(EntityPlayer player)
{
--this.numPlayersUsing;
this.world.addBlockEvent(this.pos, this.getBlockType(), 1, this.numPlayersUsing);
this.world.notifyNeighborsOfStateChange(this.pos, this.getBlockType(), true);
}
@Override
public void update() {
// TODO Auto-generated method stub
}
}
Результатом был разум быть таким:
пока пусто (оба значения равны 0)
http://prntscr.com/nnmvgx
при заполнении (оба значения равны 13)
http://prntscr.com/nnmw4c
Заранее спасибо!