1
0
Fork 0

improve container gui

This commit is contained in:
Sen 2025-09-08 00:15:58 +02:00
parent fe4a8fa6a5
commit 10abaef2b4
Signed by: sen
GPG key ID: 3AC50A6F47D1B722
9 changed files with 47 additions and 173 deletions

View file

@ -1388,7 +1388,7 @@ public class Client implements IThreadListener {
GL15.glEnable(GL15.GL_SCISSOR_TEST);
}
GlState.enableDepth();
this.renderItem.renderItemAndEffectIntoGUI(itemstack, xPos, by);
this.renderItem.renderInGui(itemstack, xPos, by);
if(width < 40 && selected != index && selected != index + 1 && cnt != total - 1)
GL15.glDisable(GL15.GL_SCISSOR_TEST);
xPos += width >= 40 || selected == index || selected == index + 1 ? 40 : width;
@ -1405,7 +1405,7 @@ public class Client implements IThreadListener {
item = this.pointed.entity.getItem();
if(item != null) {
GlState.enableDepth();
this.renderItem.renderItemAndEffectIntoGUI(new ItemStack(item), this.fbX / 2 - 180 + 4 + 1, this.hudMargin + 20 + 1);
this.renderItem.renderInGui(new ItemStack(item), this.fbX / 2 - 180 + 4 + 1, this.hudMargin + 20 + 1);
}
}

View file

@ -406,7 +406,7 @@ public abstract class GuiContainer extends Gui
this.itemRender.zLevel = 100.0F;
GlState.enableDepth();
this.itemRender.renderItemAndEffectIntoGUI(ITEM_LIST.get(i1), this.cheatX + 36 * l + 2, this.cheatY + k * 36 + 2);
this.itemRender.renderInGui(ITEM_LIST.get(i1), this.cheatX + 36 * l + 2, this.cheatY + k * 36 + 2);
this.itemRender.zLevel = 0.0F;
if(this.isPointInRegion(this.cheatX + 36 * l + 2, this.cheatY + k * 36 + 2, 32, 32, this.gm.mouseX, this.gm.mouseY))
this.renderToolTip(ITEM_LIST.get(i1), mouseX, mouseY);
@ -532,7 +532,7 @@ public abstract class GuiContainer extends Gui
GL15.glPushMatrix();
GL15.glTranslatef(0.0F, 0.0F, 32.0F);
this.itemRender.zLevel = 200.0F;
this.itemRender.renderItemAndEffectIntoGUI(stack, x, y);
this.itemRender.renderInGui(stack, x, y);
this.drawnOverlays.add(new Overlay(stack, x, y, altText));
this.itemRender.zLevel = 0.0F;
GL15.glPopMatrix();
@ -586,7 +586,7 @@ public abstract class GuiContainer extends Gui
this.itemRender.zLevel = 100.0F;
GlState.enableDepth();
this.itemRender.renderItemAndEffectIntoGUI(itemstack, i, j);
this.itemRender.renderInGui(itemstack, i, j);
this.drawnOverlays.add(new Overlay(itemstack, i, j, s));
this.itemRender.zLevel = 0.0F;
@ -873,7 +873,7 @@ public abstract class GuiContainer extends Gui
this.itemRender.zLevel = 100.0F;
ItemStack itemstack = tab.getIcon();
GlState.enableDepth();
this.itemRender.renderItemAndEffectIntoGUI(itemstack, this.cheatX + 36 * (tab.getIndex() % this.cheatWidth) + 2, this.cheatY + this.cheatHeight * 36 + 8 + 40 * (tab.getIndex() / this.cheatWidth) + 2);
this.itemRender.renderInGui(itemstack, this.cheatX + 36 * (tab.getIndex() % this.cheatWidth) + 2, this.cheatY + this.cheatHeight * 36 + 8 + 40 * (tab.getIndex() / this.cheatWidth) + 2);
this.itemRender.zLevel = 0.0F;
}

View file

@ -105,13 +105,13 @@ public class GuiMerchant extends GuiContainer implements ButtonCallback {
GlState.enableColorMaterial();
GlState.enableLighting();
this.itemRender.zLevel = 100.0F;
this.itemRender.renderItemAndEffectIntoGUI(itemstack, 36, 24);
this.itemRender.renderInGui(itemstack, 36, 24);
if(itemstack1 != null) {
this.itemRender.renderItemAndEffectIntoGUI(itemstack1, 62, 24);
this.itemRender.renderInGui(itemstack1, 62, 24);
}
this.itemRender.renderItemAndEffectIntoGUI(itemstack2, 120, 24);
this.itemRender.renderInGui(itemstack2, 120, 24);
this.itemRender.zLevel = 0.0F;
GlState.disableLighting();

View file

@ -9,97 +9,38 @@ import common.entity.item.EntityItem;
import common.item.Item;
import common.item.ItemStack;
import common.rng.Random;
import common.util.ExtMath;
public class RenderEntityItem extends Render<EntityItem>
{
private final RenderItem itemRenderer;
private Random field_177079_e = new Random();
private final Random rand = new Random();
public RenderEntityItem(RenderManager renderManagerIn, RenderItem p_i46167_2_)
public RenderEntityItem(RenderManager renderManagerIn, RenderItem renderer)
{
super(renderManagerIn);
this.itemRenderer = p_i46167_2_;
// this.shadowSize = 0.15F;
// this.shadowOpaque = 0.75F;
this.itemRenderer = renderer;
}
private int func_177077_a(EntityItem itemIn, double p_177077_2_, double p_177077_4_, double p_177077_6_, float p_177077_8_, IBakedModel p_177077_9_)
private boolean preRender(EntityItem entity, double x, double y, double z, float partial, IBakedModel model)
{
ItemStack itemstack = itemIn.getEntityItem();
ItemStack itemstack = entity.getEntityItem();
Item item = itemstack.getItem();
if (item == null)
{
return 0;
}
else
{
boolean flag = p_177077_9_.isGui3d();
int i = this.getMultiplier(itemstack);
float f = 0.25F;
float f1 = ExtMath.sin(((float)itemIn.getAge() + p_177077_8_) / 10.0F + itemIn.hoverStart) * 0.1F + 0.1F;
GL15.glTranslatef((float)p_177077_2_, (float)p_177077_4_ + f1 + 0.25F, (float)p_177077_6_);
if (flag || this.manager.gm != null)
{
float f3 = (((float)itemIn.getAge() + p_177077_8_) / 20.0F + itemIn.hoverStart) * (180F / (float)Math.PI);
GL15.glRotatef(f3, 0.0F, 1.0F, 0.0F);
}
if (!flag)
{
float f6 = -0.0F * (float)(i - 1) * 0.5F;
float f4 = -0.0F * (float)(i - 1) * 0.5F;
float f5 = -0.046875F * (float)(i - 1) * 0.5F;
GL15.glTranslatef(f6, f4, f5);
}
if(item == null)
return false;
boolean flag = model.isGui3d();
float f = flag ? 0.125F : 0.015625f;
GL15.glTranslatef((float)x, (float)y + f, (float)z);
if(!flag)
GL15.glRotatef(-90.0f, 1.0F, 0.0F, 0.0F);
GlState.color(1.0F, 1.0F, 1.0F, 1.0F);
return i;
}
return true;
}
private int getMultiplier(ItemStack stack)
{
int i = 1;
if (stack.getSize() > 48)
{
i = 5;
}
else if (stack.getSize() > 32)
{
i = 4;
}
else if (stack.getSize() > 16)
{
i = 3;
}
else if (stack.getSize() > 1)
{
i = 2;
}
return i;
}
/**
* Renders the desired {@code T} type Entity.
*/
public void doRender(EntityItem entity, double x, double y, double z, float partialTicks)
{
ItemStack itemstack = entity.getEntityItem();
this.field_177079_e.setSeed(187L);
// boolean flag = false;
// if (
this.rand.setSeed(187L);
this.bindEntityTexture(entity);
// )
// {
// this.renderManager.renderEngine.getTexture(this.getEntityTexture(entity)).unsetMipmap();
// flag = true;
// }
GlState.enableRescaleNormal();
GlState.alphaFunc(GL15.GL_GREATER, 0.1F);
@ -107,22 +48,11 @@ public class RenderEntityItem extends Render<EntityItem>
GlState.tryBlendFuncSeparate(GL15.GL_SRC_ALPHA, GL15.GL_ONE_MINUS_SRC_ALPHA, GL15.GL_ONE, GL15.GL_ZERO);
GL15.glPushMatrix();
IBakedModel ibakedmodel = this.itemRenderer.getItemModelMesher().getItemModel(itemstack);
int i = this.func_177077_a(entity, x, y, z, partialTicks, ibakedmodel);
for (int j = 0; j < i; ++j)
if (this.preRender(entity, x, y, z, partialTicks, ibakedmodel))
{
if (ibakedmodel.isGui3d())
{
GL15.glPushMatrix();
if (j > 0)
{
float f = (this.field_177079_e.floatv() * 2.0F - 1.0F) * 0.15F;
float f1 = (this.field_177079_e.floatv() * 2.0F - 1.0F) * 0.15F;
float f2 = (this.field_177079_e.floatv() * 2.0F - 1.0F) * 0.15F;
GL15.glTranslatef(f, f1, f2);
}
GL15.glScalef(0.5F, 0.5F, 0.5F);
this.itemRenderer.renderItem(itemstack, ibakedmodel);
GL15.glPopMatrix();
@ -132,7 +62,6 @@ public class RenderEntityItem extends Render<EntityItem>
GL15.glPushMatrix();
this.itemRenderer.renderItem(itemstack, ibakedmodel);
GL15.glPopMatrix();
GL15.glTranslatef(0.0F, 0.0F, 0.046875F);
}
}
@ -141,24 +70,11 @@ public class RenderEntityItem extends Render<EntityItem>
GlState.disableBlend();
this.bindEntityTexture(entity);
// if (flag)
// {
// this.renderManager.renderEngine.getTexture(this.getEntityTexture(entity)).restoreLastMipmap();
// }
super.doRender(entity, x, y, z, partialTicks);
}
/**
* Returns the location of an entity's texture. Doesn't seem to be called unless you call Render.bindEntityTexture.
*/
protected String getEntityTexture(EntityItem entity)
{
return TextureMap.BLOCKS;
}
// protected boolean canRenderName(EntityItem entity)
// {
// return entity.getEntityItem().stackSize > 1 || super.canRenderName(entity);
// }
}

View file

@ -353,7 +353,7 @@ public class RenderItem
}
}
public void renderItemAndEffectIntoGUI(final ItemStack stack, int xPosition, int yPosition)
public void renderInGui(final ItemStack stack, int xPosition, int yPosition)
{
if (stack != null && stack.getItem() != null)
{

View file

@ -43,32 +43,26 @@ public class BlockChest extends Block implements ITileEntityProvider, Rotatable
public static final PropertyBool OPEN = PropertyBool.create("open");
private static final Map<Integer, BlockChest> CHESTS = Maps.newHashMap();
private final int width;
private final int height;
private final int capacity;
public static BlockChest getChest(int size) {
return CHESTS.get(size);
}
public BlockChest(int width, int height)
public BlockChest(int capacity)
{
super(width == 9 && height == 3 ? Material.WOOD : Material.SOLID);
super(capacity <= 30 ? Material.WOOD : Material.SOLID);
this.setDefaultState(this.getBaseState().withProperty(FACING, Facing.NORTH).withProperty(OPEN, false));
this.width = width;
this.height = height;
this.capacity = capacity;
this.setTab(CheatTab.TECHNOLOGY);
this.setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 0.875F, 0.9375F);
this.setHardness(2.5F);
this.setSound(width == 9 && height == 3 ? SoundType.WOOD : SoundType.STONE);
CHESTS.put(this.width * this.height, this);
this.setSound(capacity <= 30 ? SoundType.WOOD : SoundType.STONE);
CHESTS.put(this.capacity, this);
}
public int getInventoryWidth() {
return this.width;
}
public int getInventoryHeight() {
return this.height;
public int getInventoryCapacity() {
return this.capacity;
}
public boolean isOpaqueCube()
@ -208,7 +202,7 @@ public class BlockChest extends Block implements ITileEntityProvider, Rotatable
public TileEntity createNewTileEntity()
{
return new TileEntityChest(this.width * this.height);
return new TileEntityChest(this.capacity);
}
private boolean isBlocked(World worldIn, LocalPos pos)
@ -261,12 +255,12 @@ public class BlockChest extends Block implements ITileEntityProvider, Rotatable
@Clientside
public void getTooltips(ItemStack stack, EntityNPC player, List<String> tooltip) {
super.getTooltips(stack, player, tooltip);
tooltip.add(Color.DARK_GREEN + "Kapazität" + Color.DARK_GRAY + ": " + Color.GREEN + (this.width * this.height));
tooltip.add(Color.DARK_GREEN + "Kapazität" + Color.DARK_GRAY + ": " + Color.GREEN + this.capacity);
}
@Clientside
public String getInfo(World world, LocalPos pos, State state, EntityNPC player) {
return Color.DARK_GREEN + "Kapazität für " + Color.GREEN + (this.width * this.height) + Color.DARK_GREEN + " Gegenstände";
return Color.DARK_GREEN + "Kapazität für " + Color.GREEN + this.capacity + Color.DARK_GREEN + " Gegenstände";
}
public Model getModel(ModelProvider provider, String name, State state) {

View file

@ -25,25 +25,14 @@ import common.world.AWorldServer;
public class EntityItem extends Entity
{
/**
* The age of this EntityItem (used to animate it up and down as well as expire it)
*/
private int age;
private int delayBeforeCanPickup;
/** The health of this EntityItem. (For example, damage for tools) */
private int health;
// private String thrower;
// private String owner;
/** The EntityItem's random initial float height. */
public float hoverStart;
public EntityItem(World worldIn, double x, double y, double z)
{
super(worldIn);
this.health = 5;
this.hoverStart = (float)(Math.random() * Math.PI * 2.0D);
this.setSize(0.25F, 0.25F);
this.setPosition(x, y, z);
this.rotYaw = (float)(Math.random() * 360.0D);
@ -58,11 +47,6 @@ public class EntityItem extends Entity
this.setEntityItemStack(stack);
}
// public EntityItem(World worldIn, double x, double y, double z, int data)
// {
// this(worldIn, x, y, z);
// }
public void fall(float distance, float damageMultiplier)
{
if(!this.worldObj.client && ((Vars.itemFallDamage && distance >= 1.0f && this.getEntityItem().getItem().isFragile()) || (Vars.itemExplosion && distance >= 2.0f && this.getEntityItem().getItem().getExplosive() > 0))) {
@ -90,7 +74,6 @@ public class EntityItem extends Entity
{
super(worldIn);
this.health = 5;
this.hoverStart = (float)(Math.random() * Math.PI * 2.0D);
this.setSize(0.25F, 0.25F);
this.setEntityItemStack(new ItemStack((Item)null, 0));
}

View file

@ -574,14 +574,14 @@ public abstract class BlockRegistry {
register("cauldron", (new BlockCauldron()).setHardness(2.0F).setDisplay("Kessel").setTab(CheatTab.TECHNOLOGY));
register("effect_generator", (new BlockEffectGenerator()).setDisplay("Effektgenerator").setLight(0xffffff));
register("wood_chest", new BlockChest(9, 3).setDisplay("Holztruhe"));
register("stone_chest", new BlockChest(9, 6).setDisplay("Steintruhe"));
register("iron_chest", new BlockChest(12, 8).setDisplay("Eisentruhe"));
register("platinum_chest", new BlockChest(16, 10).setDisplay("Platintruhe"));
register("silver_chest", new BlockChest(18, 14).setDisplay("Silbertruhe"));
register("thetium_chest", new BlockChest(22, 18).setDisplay("Thetiumtruhe"));
register("black_metal_chest", new BlockChest(28, 18).setDisplay("Schwarzmetalltruhe"));
register("nichun_chest", new BlockChest(32, 18).setDisplay("Nichuntruhe"));
register("wood_chest", new BlockChest(22).setDisplay("Holztruhe"));
register("stone_chest", new BlockChest(48).setDisplay("Steintruhe"));
register("iron_chest", new BlockChest(90).setDisplay("Eisentruhe"));
register("platinum_chest", new BlockChest(150).setDisplay("Platintruhe"));
register("silver_chest", new BlockChest(240).setDisplay("Silbertruhe"));
register("thetium_chest", new BlockChest(384).setDisplay("Thetiumtruhe"));
register("black_metal_chest", new BlockChest(480).setDisplay("Schwarzmetalltruhe"));
register("nichun_chest", new BlockChest(550).setDisplay("Nichuntruhe"));
register("warp_chest", (new BlockWarpChest()).setHardness(22.5F).setResistance(1000.0F).setSound(SoundType.STONE)
.setDisplay("Warptruhe").setLight(0x7f00af));

View file

@ -2,7 +2,6 @@ package common.inventory;
import java.util.List;
import common.block.tech.BlockChest;
import common.collect.Lists;
import common.entity.npc.EntityNPC;
import common.item.ItemStack;
@ -12,24 +11,16 @@ public class ContainerChest extends Container
{
private final IInventory chest;
private final int chestSize;
private final int width;
private final int height;
public ContainerChest(EntityNPC player, IInventory chest)
{
this.chest = chest;
this.chestSize = chest.getSizeInventory();
BlockChest block = BlockChest.getChest(this.chestSize);
this.width = block.getInventoryWidth();
this.height = block.getInventoryHeight();
List<SlotCommon> list = Lists.newArrayList();
for (int j = 0; j < this.height; ++j)
for (int j = 0; j < this.chestSize; ++j)
{
for (int k = 0; k < this.width; ++k)
{
this.addSlotToContainer(new SlotCommon(list, chest, k + j * this.width, false));
}
this.addSlotToContainer(new SlotCommon(list, chest, j, false));
}
this.addPlayerSlots(player);
@ -100,14 +91,4 @@ public class ContainerChest extends Container
{
return this.chest;
}
public int getWidth()
{
return this.width;
}
public int getHeight()
{
return this.height;
}
}