Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

Mekelaina

Members
  • Posts

    60
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Mekelaina's Achievements

Stone Miner

Stone Miner (3/8)

0

Reputation

  1. @poopoodice Do you have an example of how to use/create packets?
  2. So I'm trying to have my block store experience. and using buttons in the gui of the block you should be able to deposit levels to the block or take them out. while the buttons work and will alter both the players xp levels and the xp stored in the block, if you close the gui it reverts to what it was before using the buttons and if the players xp was changed via the buttons in the gui, upon saving and reloading the world it will be set back to what it was before. I'm really confused because the block can also "gain" xp by placing items in its slot, and this works fine. and the button code i took from that. and i use methods in the EntityPlayer class to alter the xp values. My guess is its something to do with the server not getting the memo things have changed, but i dont know why using the fuel to xp mechanic works then because they both use similar means. Id really appreciate some help here. My Screen package com.mekelaina.gramarye.gui.screens; import com.mekelaina.gramarye.Gramarye; import com.mekelaina.gramarye.gui.containers.ObeliskContainer; import com.mekelaina.gramarye.blocks.tiles.ObeliskTile; import com.mekelaina.gramarye.gui.element.CustomButton; import com.mekelaina.gramarye.gui.element.WidgetWrapper; import com.mekelaina.gramarye.util.XPMathUtils; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.client.gui.widget.button.Button; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; import java.awt.*; public class ObeliskScreen extends ContainerScreen<ObeliskContainer> { private ResourceLocation GUI ; private ObeliskTile obeliskTile; private Rectangle xp; private CustomButton depositLvl; private CustomButton retrieveLvl; public ObeliskScreen(ObeliskContainer screenContainer, PlayerInventory inv, ITextComponent titleIn) { super(screenContainer, inv, titleIn); this.obeliskTile = screenContainer.getTileEntity(); xp = new Rectangle(135, 5, 36, 68); } @Override public void render(int mouseX, int mouseY, float partialTicks) { super.render(mouseX, mouseY, partialTicks); this.renderHoveredToolTip(mouseX, mouseY); } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { // this.font.drawString(this.title.getFormattedText(), 8.0f, 6.0f, 4210752); //this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), 8.0f, (float)(this.ySize - 94), 4210752); // drawString(Minecraft.getInstance().fontRenderer, "Energy: " + container.getEnergy(), this.xSize - (this.xSize / 2), 6, 0x4AEDD9); //renderHoveredToolTip(mouseX - this.xSize - (this.xSize / 2), mouseY); String toDraw = "Xp: " + this.container.getEnergy() + " Lvl: " + XPMathUtils.getClosestLevelByXp(this.container.getEnergy()); // Gramarye.LOGGER.debug(font.getStringWidth(toDraw)); this.font.drawString(toDraw, (float)(this.xSize - (font.getStringWidth(toDraw) + 4)), (float)(this.ySize - 92), 0xF5FF8F); /*//Gramarye.LOGGER.debug("mouse x: " + mouseX + "mouse y: " + mouseY); if(isOverXpBar(mouseX, mouseY)) { blit(mouseX, mouseY, 129, 166, 32, 20); drawString(Minecraft.getInstance().fontRenderer, toDraw, mouseX , mouseY, 0x4AEDD9); }*/ } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { // GlStateManager.color4f(1f, 1f, 1f, 1f); this.minecraft.getTextureManager().bindTexture(GUI); int relX = (this.width - this.xSize) / 2; int relY = (this.height - this.ySize) / 2; this.blit(relX, relY, 0, 0, this.xSize, this.ySize); int k = this.getExperienceStoredScaled(64); // Gramarye.LOGGER.debug(64); //k += (k-64) ; blit(this.guiLeft + 71, this.guiTop + 7 + (64-k), 176, 1+(64-k), 32, k); } private int getExperienceStoredScaled(int pixels) { int i = this.container.getEnergy(); int j = this.obeliskTile.getCapacity(); return i != 0 && j != 0 ? i * pixels / j : 0; } private boolean isOverXpBar(int mouseX, int mouseY) { return mouseX >= this.guiLeft + this.xp.x && mouseY >= this.guiTop + xp.y && mouseX < xp.x + xp.width && mouseY < xp.y + xp.height; } @Override protected void init() { super.init(); GUI = new ResourceLocation(Gramarye.MODID, "textures/gui/test_gui2.png"); WidgetWrapper[] temp = new WidgetWrapper[] {new WidgetWrapper(176, 65, 20, 20), new WidgetWrapper(176, 85, 20, 20), new WidgetWrapper(176, 105, 20, 20), new WidgetWrapper(176, 125, 20, 20)}; depositLvl = new CustomButton(this.guiLeft + 118, this.guiTop + 5, 20, 20, temp, p_onPress_1_ -> insertOneLevel()); depositLvl.setTexture(GUI); this.addButton(depositLvl); temp = new WidgetWrapper[] {new WidgetWrapper(176, 65, 20, 20), new WidgetWrapper(176, 85, 20, 20), new WidgetWrapper(176, 105, 20, 20), new WidgetWrapper(176, 145, 20, 20)}; retrieveLvl = depositLvl = new CustomButton(this.guiLeft + 145, this.guiTop + 5, 20, 20, temp, p_onPress_1_ -> retrieveOneLevel()); retrieveLvl.setTexture(GUI); this.addButton(retrieveLvl); } private void initButtons() { //this.addButton(new Button(this.guiLeft + 84, this.guiTop + 5, 20, 20, "Boop", p_onPress_1_ -> sendMessage())); } private void sendMessage(){ this.container.getPlayer().sendStatusMessage(new StringTextComponent("test"), false); //this.container.getPlayer().e } private void insertOneLevel(){ PlayerEntity player = container.getPlayer(); Gramarye.LOGGER.debug("player"); if(!player.isCreative()) { int playerLvl = player.experienceLevel; int playerTotal = player.experienceTotal; if(playerTotal > 0 && playerLvl > 0) { int currentLvlsWorth = XPMathUtils.getXpToLevelUp(playerLvl-1); this.obeliskTile.insertXp(currentLvlsWorth); player.giveExperiencePoints(-currentLvlsWorth); } else if(playerTotal > 0 && playerLvl <= 0) { this.obeliskTile.insertXp(playerTotal); player.giveExperiencePoints(-playerTotal); } } else { int currentLvl = XPMathUtils.getClosestLevelByXp(this.obeliskTile.getEnergy()); int toAdd = XPMathUtils.totalXpByLevel(currentLvl+1) - this.obeliskTile.getEnergy(); this.obeliskTile.insertXp(toAdd); } } public void retrieveOneLevel() { PlayerEntity player = container.getPlayer(); Gramarye.LOGGER.debug("player"); if(!player.isCreative()) { int obeliskTotal = this.container.getEnergy(); int obeliskLvl = XPMathUtils.getClosestLevelByXp(obeliskTotal); if(obeliskTotal > 0 && obeliskLvl > 0) { int currentLvlsWorth = XPMathUtils.getXpToLevelUp(obeliskLvl-1); this.obeliskTile.removeXp(currentLvlsWorth); player.giveExperiencePoints(currentLvlsWorth); } else if(obeliskTotal > 0 && obeliskLvl <= 0) { this.obeliskTile.removeXp(obeliskTotal); player.giveExperiencePoints(obeliskTotal); } } else { int currentLvl = XPMathUtils.getClosestLevelByXp(this.obeliskTile.getEnergy()); int toRemove = this.obeliskTile.getEnergy() - XPMathUtils.totalXpByLevel(currentLvl-1); this.obeliskTile.removeXp(toRemove); } } } container package com.mekelaina.gramarye.gui.containers; import com.mekelaina.gramarye.Gramarye; import com.mekelaina.gramarye.blocks.ModBlocks; import com.mekelaina.gramarye.blocks.tiles.ObeliskTile; import com.mekelaina.gramarye.items.ModItems; import com.mekelaina.gramarye.util.CustomEnergyStorage; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.Slot; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.util.IWorldPosCallable; import net.minecraft.util.IntReferenceHolder; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.SlotItemHandler; import net.minecraftforge.items.wrapper.InvWrapper; public class ObeliskContainer extends ExtendedContainer { public ObeliskContainer(int windowId, World world, BlockPos pos, PlayerInventory playerInventory, PlayerEntity player) { super(ModContainers.OBELISK_CONTAINER.get(), windowId); tileEntity = world.getTileEntity(pos); this.playerEntity = player; this.playerInventory = new InvWrapper(playerInventory); tileEntity.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY).ifPresent(handler -> { addSlot(new SlotItemHandler(handler, 0, 24, 45)); }); layoutPlayerInventorySlots(8, 84); trackInt(new IntReferenceHolder() { @Override public int get() { return getEnergy(); } @Override public void set(int value) { tileEntity.getCapability(CapabilityEnergy.ENERGY).ifPresent(h -> ((CustomEnergyStorage)h).setEnergy(value)); } }); } public int getEnergy() { return tileEntity.getCapability(CapabilityEnergy.ENERGY).map(IEnergyStorage::getEnergyStored).orElse(0); } @Override public boolean canInteractWith(PlayerEntity playerIn) { return isWithinUsableDistance(IWorldPosCallable.of(tileEntity.getWorld(), tileEntity.getPos()), playerIn, ModBlocks.OBELISK.get()); } @Override public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) { ItemStack itemStack = ItemStack.EMPTY; Slot slot = this.inventorySlots.get(index); if(slot != null && slot.getHasStack()) { ItemStack stack = slot.getStack(); itemStack = stack.copy(); if(index == 0) { if(!this.mergeItemStack(stack, 1, 37, true)) { return ItemStack.EMPTY; } slot.onSlotChange(stack, itemStack); } else { if(stack.getItem() == Items.EXPERIENCE_BOTTLE || stack.getItem() == ModItems.CRYSTAL.get() || stack.getItem() == ModBlocks.CRYSTALBLOCK.get().asItem()) { if(!this.mergeItemStack(stack, 0, 1, false)) { return ItemStack.EMPTY; } } else if(index < 28) { if(!this.mergeItemStack(stack, 28, 37, false)) { return ItemStack.EMPTY; } } else if(index < 37 && !this.mergeItemStack(stack, 1, 28, false)) { return ItemStack.EMPTY; } } if(stack.isEmpty()) { slot.putStack(ItemStack.EMPTY); } else { slot.onSlotChanged(); } if(stack.getCount() == itemStack.getCount()) { return ItemStack.EMPTY; } slot.onTake(playerIn, stack); } return itemStack; } public ObeliskTile getTileEntity() { return (ObeliskTile)this.tileEntity; } private boolean isItemValid(ItemStack stack) { Gramarye.LOGGER.debug(stack); if(stack.getItem() == Items.EXPERIENCE_BOTTLE || stack.getItem() == ModItems.CRYSTAL.get() || stack.getItem() == ModBlocks.CRYSTALBLOCK.get().asItem()) { return true; } return false; } public PlayerEntity getPlayer(){ return this.playerEntity; } } tile entity package com.mekelaina.gramarye.blocks.tiles; import com.mekelaina.gramarye.Gramarye; import com.mekelaina.gramarye.blocks.ModBlocks; import com.mekelaina.gramarye.gui.containers.ObeliskContainer; import com.mekelaina.gramarye.items.ModItems; import com.mekelaina.gramarye.util.CustomEnergyStorage; import com.mekelaina.gramarye.util.XPMathUtils; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.inventory.container.Container; import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.nbt.CompoundNBT; import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.Direction; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.TranslationTextComponent; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.util.INBTSerializable; import net.minecraftforge.common.util.LazyOptional; import net.minecraftforge.energy.CapabilityEnergy; import net.minecraftforge.energy.IEnergyStorage; import net.minecraftforge.items.CapabilityItemHandler; import net.minecraftforge.items.IItemHandler; import net.minecraftforge.items.ItemStackHandler; import javax.annotation.Nonnull; import javax.annotation.Nullable; import java.util.ArrayList; import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicInteger; public class ObeliskTile extends TileEntity implements ITickableTileEntity, INamedContainerProvider { private LazyOptional<IItemHandler> handler = LazyOptional.of(this::createHandler); private LazyOptional<IEnergyStorage> energy = LazyOptional.of(this::createEnergy); private ArrayList<InputWrapper> toProcess = new ArrayList<>(); private int counter; private int inputType=0; private ItemStack lastItem; private double speed = 2; private double translation = 0; private double lastTranslation = 0; public ObeliskTile() { super(ModTileEntities.OBELISK_TILE.get()); } @Override public void tick() { if(world.isRemote()) { return; } if(counter > 0) { counter--; if(counter <= 0) { energy.ifPresent(e -> ((CustomEnergyStorage)e).addEnergy(getXpPerInput())); inputType = 0; } markDirty(); } if(counter <=0) { handler.ifPresent(handler1 -> { ItemStack stack = handler1.getStackInSlot(0); if(stack.getItem() == Items.EXPERIENCE_BOTTLE || stack.getItem() == ModItems.CRYSTAL.get() || stack.getItem() == ModBlocks.CRYSTALBLOCK.get().asItem()) { lastItem = stack.copy(); handler1.extractItem(0, 1, false); counter = 20; markDirty(); } }); } /*for (InputWrapper i : toProcess) { Gramarye.LOGGER.debug("DOOOOOOOOO"); if(i.isAdd()){ energy.ifPresent(iEnergyStorage -> { ((CustomEnergyStorage)iEnergyStorage).addEnergy(XPMathUtils.getXpToInsert(iEnergyStorage.getEnergyStored(), iEnergyStorage.getMaxEnergyStored(), i.getAmount())); }); } else { energy.ifPresent(iEnergyStorage -> { ((CustomEnergyStorage)iEnergyStorage).consumeEnergy(XPMathUtils.getXpToInsert(iEnergyStorage.getEnergyStored(), iEnergyStorage.getMaxEnergyStored(), i.getAmount())); }); } //toProcess.remove(i); markDirty(); } toProcess.clear();*/ sendOutPower(); } private void sendOutPower() { energy.ifPresent(e -> { AtomicInteger capacity = new AtomicInteger(e.getEnergyStored()); if(capacity.get() > 0) { for (Direction direction : Direction.values()) { TileEntity tileEntity = world.getTileEntity(pos.offset(direction)); if(tileEntity != null) { boolean doContinue = tileEntity.getCapability(CapabilityEnergy.ENERGY, direction).map(handler -> { if(handler.canReceive()) { int received = handler.receiveEnergy(Math.min(capacity.get(), 100), false); capacity.addAndGet(-received); ((CustomEnergyStorage)e).consumeEnergy(received); markDirty(); return capacity.get() > 0; } else { return true; } }).orElse(true); if(!doContinue) { return; } } } } }); } @Override public void read(CompoundNBT compound) { CompoundNBT invTag = compound.getCompound("inv"); handler.ifPresent(handler1 -> ((INBTSerializable<CompoundNBT>)handler1).deserializeNBT(invTag)); CompoundNBT energyTag = compound.getCompound("experion"); energy.ifPresent(energy1 -> ((CustomEnergyStorage)energy1).setEnergy(energyTag.getInt("experion"))); CompoundNBT speedTag = compound.getCompound("speed"); this.speed = speedTag.getDouble("speed"); super.read(compound); } @Override public CompoundNBT write(CompoundNBT compound) { handler.ifPresent(h -> { CompoundNBT compoundNBT = ((INBTSerializable<CompoundNBT>)h).serializeNBT(); compound.put("inv", compoundNBT); }); energy.ifPresent(h -> { CompoundNBT compoundNBT = ((INBTSerializable<CompoundNBT>)h).serializeNBT(); compound.put("experion", compoundNBT); }); compound.putDouble("speed", this.speed); return super.write(compound); } private ItemStackHandler createHandler() { return new ItemStackHandler(1){ @Override public boolean isItemValid(int slot, @Nonnull ItemStack stack) { if(stack.getItem() == Items.EXPERIENCE_BOTTLE || stack.getItem() == ModItems.CRYSTAL.get() || stack.getItem() == ModBlocks.CRYSTALBLOCK.get().asItem()) { return true; } return false; } @Override protected void onContentsChanged(int slot) { markDirty(); } @Nonnull @Override public ItemStack insertItem(int slot, @Nonnull ItemStack stack, boolean simulate) { if(stack.getItem() != ModItems.CRYSTAL.get() && stack.getItem() != Items.EXPERIENCE_BOTTLE && stack.getItem() != ModBlocks.CRYSTALBLOCK.get().asItem()){ return stack; } return super.insertItem(slot, stack, simulate); } }; } @Nonnull @Override public <T> LazyOptional<T> getCapability(@Nonnull Capability<T> cap, @Nullable Direction side) { if(cap == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY) { return handler.cast(); } if(cap == CapabilityEnergy.ENERGY) { return energy.cast(); } return super.getCapability(cap, side); } @Override public ITextComponent getDisplayName() { return new TranslationTextComponent("block.gramarye.obelisk"); } @Nullable @Override public Container createMenu(int i, PlayerInventory playerInventory, PlayerEntity playerEntity) { return new ObeliskContainer(i, world, pos, playerInventory, playerEntity); } private IEnergyStorage createEnergy() { return new CustomEnergyStorage(2048, 0); } private int getXpPerInput() { if(lastItem != null) { if(lastItem.getItem() == Items.EXPERIENCE_BOTTLE) { lastItem = ItemStack.EMPTY; return 3 + this.world.rand.nextInt(5) + this.world.rand.nextInt(5); } if(lastItem.getItem() == ModItems.CRYSTAL.get()) { lastItem = ItemStack.EMPTY; return 20; } if(lastItem.getItem() == ModBlocks.CRYSTALBLOCK.get().asItem()) { lastItem = ItemStack.EMPTY; return 100; } } return 0; } public boolean insertXp(int amount) { AtomicBoolean rtn = new AtomicBoolean(false); energy.ifPresent(iEnergyStorage -> { int temp = XPMathUtils.getXpToInsert(iEnergyStorage.getEnergyStored(), iEnergyStorage.getMaxEnergyStored(), amount); ((CustomEnergyStorage)iEnergyStorage).addEnergy(temp); rtn.set(true); markDirty(); }); //markDirty(); return rtn.get(); /*toProcess.add(new InputWrapper(amount, true)); return true;*/ } public boolean removeXp(int amount) { AtomicBoolean rtn = new AtomicBoolean(false); energy.ifPresent(iEnergyStorage -> { int temp = XPMathUtils.getXpToInsert(iEnergyStorage.getEnergyStored(), iEnergyStorage.getMaxEnergyStored(), amount); ((CustomEnergyStorage)iEnergyStorage).consumeEnergy(temp); rtn.set(true); markDirty(); }); return rtn.get(); /*toProcess.add(new InputWrapper(amount, false)); return true;*/ } private void calculateTranslation() { this.lastTranslation = this.translation; this.translation += (float)(Math.sin(speed * counter)); } public double getTranslation() { return translation; } public int getCapacity() { AtomicInteger temp = new AtomicInteger(); energy.ifPresent(e -> { temp.set(e.getMaxEnergyStored());}); return temp.get(); } public int getEnergy() { AtomicInteger temp = new AtomicInteger(); energy.ifPresent(e -> { temp.set(e.getEnergyStored()); }); return temp.get(); } private boolean isItemValid(ItemStack stack) { //Gramarye.LOGGER.debug("called from is item valid"); if(stack.getItem() == Items.EXPERIENCE_BOTTLE) { inputType = 1; Gramarye.LOGGER.debug("xp bottle " + inputType); return true; } else if(stack.getItem() == ModItems.CRYSTAL.get()) { inputType = 2; Gramarye.LOGGER.debug("crystal " + inputType); return true; } else if(stack.getItem() == ModBlocks.CRYSTALBLOCK.get().asItem()) { inputType = 3; Gramarye.LOGGER.debug("cryatal blcok " + inputType); return true; } return false; } } class InputWrapper { private int amount; private boolean add; public InputWrapper(int amount, boolean add) { this.amount = amount; this.add = add; } public int getAmount() { return amount; } public boolean isAdd() { return add; } } the energy capability extension package com.mekelaina.gramarye.util; import net.minecraft.nbt.CompoundNBT; import net.minecraftforge.common.util.INBTSerializable; import net.minecraftforge.energy.EnergyStorage; public class CustomEnergyStorage extends EnergyStorage implements INBTSerializable<CompoundNBT> { public CustomEnergyStorage(int capacity, int maxTransfer) { super(capacity, maxTransfer); } public void setEnergy(int energy){ this.energy = energy; } public void addEnergy(int energy) { this.energy += energy; if(this.energy > getMaxEnergyStored()){ this.energy = getEnergyStored(); } } public void consumeEnergy(int energy) { this.energy -= energy; if(this.energy < 0){ this.energy = 0; } } @Override public CompoundNBT serializeNBT() { CompoundNBT tag = new CompoundNBT(); tag.putInt("experion", getEnergyStored()); return tag; } @Override public void deserializeNBT(CompoundNBT nbt) { setEnergy(nbt.getInt("experion")); } }
  3. Note this topic was posted multiple times, this was in error. I guess refreshing the error screen reposed it idk.
  4. So Ive been trying to get my block to render whatever item its given, but Im having trouble with the rendering part. I was trying to reuse/update code from a tutorial i followed back for 1.12 from shadowfacts with limited success. I haven't found a better example tho. The item renders as a weirdly textured square and only when observed from certain angles (as shown below) what am i doing wrong and if anyone has a good example of how to render stuff properly in 1.14-1.15 it would be greatly appreciated. This is the code of my TER: package com.mekelaina.gramarye.client.render; import com.mekelaina.gramarye.blocks.tiles.ChargerTile; import com.mojang.blaze3d.platform.GlStateManager; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.RenderHelper; import net.minecraft.client.renderer.model.IBakedModel; import net.minecraft.client.renderer.model.ItemCameraTransforms; import net.minecraft.client.renderer.texture.Texture; import net.minecraft.client.renderer.texture.TextureManager; import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraftforge.client.ForgeHooksClient; import org.lwjgl.opengl.GL11; public class ChargerTileEntityRenderer extends TileEntityRenderer<ChargerTile> { public ChargerTileEntityRenderer() { } @Override public void render(ChargerTile tileEntityIn, double x, double y, double z, float partialTicks, int destroyStage) { ItemStack stack = new ItemStack(Items.DIAMOND); if(!stack.isEmpty()){ GlStateManager.enableRescaleNormal(); GlStateManager.alphaFunc(GL11.GL_GREATER, 0.1f); GlStateManager.enableBlend(); RenderHelper.enableStandardItemLighting(); GlStateManager.blendFuncSeparate(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0); GlStateManager.pushMatrix(); //double offset = Math.sin((tileEntityIn.getWorld().getT)) GlStateManager.translated(x + 0.5, y + 0.6, z + 0.5); GlStateManager.rotated((tileEntityIn.getWorld().getGameTime() + partialTicks) * 1.5, 0, 1, 0); IBakedModel model = Minecraft.getInstance().getItemRenderer().getItemModelWithOverrides(stack, tileEntityIn.getWorld(), null); model = ForgeHooksClient.handleCameraTransforms(model, ItemCameraTransforms.TransformType.GROUND, false); Minecraft.getInstance().getItemRenderer().renderItem(stack, model); GlStateManager.popMatrix(); GlStateManager.disableRescaleNormal(); GlStateManager.disableBlend(); } super.render(tileEntityIn, x, y, z, partialTicks, destroyStage); } private void renderItem(ItemStack stack){ } } and this is the result: https://imgur.com/z2PgRVm
  5. @TheGreyGhost the what now? I didnt see a get property function. unless you mean the get(propetyname)PropertyOverride method you used for your lamda function. in my case that just returns the float value private static float getElementPropertyOverride(ItemStack stack, @Nullable World world, @Nullable LivingEntity entity){ return boundSpell.getSpellElement().getValue(); } private static float getLevelPropertyOverride(ItemStack stack, @Nullable World world, @Nullable LivingEntity entity){ return boundSpell.getSpellLevel().getValue(); }
  6. @TheGreyGhost So, does one need to put data to nbt if the values dont change? beacuse i replicated your lamba method for the addPropertiesOverride and my predicate still doesnt work. Like the override properties arent working.
  7. @Draco18s so would i have to use baked item models to do this?
  8. So Im trying to make it so the textures used for my item depends on values that are passed in from a spell object upon creation. so ideally I can just define a new spell with an element and a level and the model will override with the right textures. this probably isnt how the system is supposed to be used, but I was trying to get out of assigning each model manually and could just have each spellbook use the base model with the predicates and such. But idk if mt custom addPropertiesOverride predicates arent registered right or what because they arent working. is there something im missing, do they require a capability or? any help is appreciated. The Item class package com.mekelaina.gramarye.items; import com.mekelaina.gramarye.Gramarye; import com.mekelaina.gramarye.Spell.Spell; import net.minecraft.client.util.ITooltipFlag; import net.minecraft.entity.LivingEntity; import net.minecraft.item.IItemPropertyGetter; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUseContext; import net.minecraft.nbt.CompoundNBT; import net.minecraft.util.ActionResultType; import net.minecraft.util.ResourceLocation; import net.minecraft.util.text.ITextComponent; import net.minecraft.util.text.StringTextComponent; import net.minecraft.world.World; import javax.annotation.Nullable; import java.util.List; public class GenericSpellBook extends Item{ private final Spell boundSpell; public GenericSpellBook(Spell spellToBind) { super(new Properties() .maxStackSize(1) .group(Gramarye.setup.itemGroup) ); this.boundSpell = spellToBind; this.addPropertyOverride(new ResourceLocation("gramarye:element"), new IItemPropertyGetter() { @Override public float call(ItemStack stack, @Nullable World world, @Nullable LivingEntity entity) { return boundSpell.getSpellElement().getValue(); } }); this.addPropertyOverride(new ResourceLocation("gramarye:level"), new IItemPropertyGetter() { @Override public float call(ItemStack stack, @Nullable World world, @Nullable LivingEntity entity) { return boundSpell.getSpellLevel().getValue(); } }); } @Override public boolean updateItemStackNBT(CompoundNBT nbt) { return super.updateItemStackNBT(nbt); } @Nullable @Override public CompoundNBT getShareTag(ItemStack stack) { CompoundNBT compoundNBT = stack.getOrCreateTag(); compoundNBT.putFloat("spellElement", boundSpell.getSpellElement().getValue()); compoundNBT.putFloat("spellLevel", boundSpell.getSpellLevel().getValue()); return compoundNBT; } @Override public void readShareTag(ItemStack stack, @Nullable CompoundNBT nbt) { super.readShareTag(stack, nbt); } @Override public ActionResultType onItemUse(ItemUseContext context) { context.getPlayer().sendStatusMessage(new StringTextComponent(boundSpell.getSpellElement().toString()), false); context.getPlayer().sendStatusMessage(new StringTextComponent(boundSpell.getSpellLevel().toString()), false); return boundSpell.onSpellCast(context); } } { "parent": "item/generated", "textures": { "layer0": "gramarye:item/book/loot_spellbook" }, "overrides": [ { "predicate": { "gramarye:element": 0, "gramarye:level": 0 }, "model": "gramarye:item/book/spellbook_fire_novice" } ] } { "parent": "gramarye:item/book/spellbook_base", "textures": { "layer0": "gramarye:item/book/loot_spellbook", "layer1": "gramarye:item/book/fire", "layer2": "gramarye/item/book/novice" } }
  9. the 2s were just a constant acceleration for the entity. Most of the actual code for the projectile entity was taken from vanillas fireball code. They are used to calculate how quickly the entity should accelerate.
  10. the entity wont render, and most of the time im not even sure if my wand item is actually creating the entity. and occasionally ill get the message in chat of it hitting a certain block but not consistently.
  11. @Ugdhar sorry, its been a day. here is a link to my repository all of the entity code is in the entities package, and the ClientSetup class is where client side stuff is registered
  12. @Ugdhar But its not working, if you look at my source code i did what you said
  13. @poopoodice do you have an example of how to use IRenderFactory?
  14. what new registerEntityRenderingHandler? im using this one "RenderingRegistry.registerEntityRenderingHandler" in my client setup class. is there another one?
×
×
  • Create New...

Important Information

By using this site, you agree to our Privacy Policy.