Jump to content

JimiIT92

Members
  • Posts

    867
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by JimiIT92

  1. I've created a custom capability to add mana, strength and other stats. Server side they works as intended but i'm having troubles displaying them correctly client side. So, for instance, i have a mana bar that will display the current amount of mana. But it always display 100 (the base value), even if i send a message to the client telling it what is the current mana value. So here are the message and the message handler i'm using package com.rpg.messages; import com.rpg.capabilities.player.IPlayerCapabilities; import io.netty.buffer.ByteBuf; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; public class PlayerCapabilitiesMessage implements IMessage{ private IPlayerCapabilities value; public PlayerCapabilitiesMessage() { this.value = null; } public PlayerCapabilitiesMessage(IPlayerCapabilities value) { this.value = value; } @Override public void fromBytes(ByteBuf buf) { if(this.value != null) { this.value.setStrength(buf.readInt()); this.value.setSkill(buf.readInt()); this.value.setResistance(buf.readInt()); this.value.setSpeed(buf.readInt()); this.value.setVitality(buf.readInt()); this.value.setMana(buf.readInt()); this.value.setLevel(buf.readInt()); this.value.setMaxHealth(buf.readFloat()); this.value.setMaxHunger(buf.readFloat()); } } @Override public void toBytes(ByteBuf buf) { if(this.value != null) { buf.writeInt(this.value.getStrength()); buf.writeInt(this.value.getSkill()); buf.writeInt(this.value.getResistance()); buf.writeInt(this.value.getSpeed()); buf.writeInt(this.value.getVitality()); buf.writeInt(this.value.getMana()); buf.writeInt(this.value.getLevel()); buf.writeFloat(this.value.getMaxHealth()); buf.writeFloat(this.value.getMaxHunger()); } } public void setValue(IPlayerCapabilities value) { this.value = value; } public IPlayerCapabilities getValue() { return this.value; } } package com.rpg.messages; import com.rpg.RPG; import com.rpg.capabilities.player.IPlayerCapabilities; import com.rpg.capabilities.player.PlayerCapabilitiesProvider; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.IThreadListener; import net.minecraftforge.fml.common.network.simpleimpl.IMessage; import net.minecraftforge.fml.common.network.simpleimpl.IMessageHandler; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; public class PlayerMessageHandler implements IMessageHandler<PlayerCapabilitiesMessage, IMessage>{ @Override public IMessage onMessage(PlayerCapabilitiesMessage message, MessageContext ctx) { IThreadListener thread = RPG.PROXY.getListener(ctx); final EntityPlayer player = RPG.PROXY.getPlayer(ctx); final IPlayerCapabilities value = message.getValue(); thread.addScheduledTask(new Runnable() { @Override public void run() { if(player != null) { IPlayerCapabilities capabilities = player.getCapability(PlayerCapabilitiesProvider.PLAYER_CAP, null); if(capabilities != null && value != null) { capabilities.setStrength(value.getStrength()); capabilities.setSkill(value.getSkill()); capabilities.setResistance(value.getResistance()); capabilities.setSpeed(value.getSpeed()); capabilities.setVitality(value.getVitality()); capabilities.setMana(value.getMana()); capabilities.setLevel(value.getLevel()); capabilities.setMaxHealth(value.getMaxHealth()); capabilities.setMaxHunger(value.getMaxHunger()); } } } }); return null; } } This is the mana bar rendering code package com.rpg.gui; import org.lwjgl.opengl.GL11; import com.rpg.RPG; import com.rpg.capabilities.player.IPlayerCapabilities; import com.rpg.capabilities.player.PlayerCapabilitiesProvider; import net.minecraft.client.Minecraft; import net.minecraft.client.gui.Gui; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.event.RenderGameOverlayEvent; import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; public class GuiOverlay extends Gui{ private Minecraft mc; private static final ResourceLocation icons = new ResourceLocation(RPG.MODID, "textures/gui/icons.png"); public GuiOverlay(Minecraft mc) { super(); this.mc = mc; } @SubscribeEvent public void onRenderExperienceBar(RenderGameOverlayEvent event) { if (event.isCancelable() || event.getType() != ElementType.EXPERIENCE) return; int xPos = 2; int yPos = 2; GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); GL11.glDisable(GL11.GL_LIGHTING); this.mc.getTextureManager().bindTexture(icons); EntityPlayer player = this.mc.thePlayer; IPlayerCapabilities iplayer = player.getCapability(PlayerCapabilitiesProvider.PLAYER_CAP, null); if(iplayer != null) { this.drawTexturedModalRect(xPos, yPos, 0, 80, 100, 5); int manaBarWidth = (int) (((float) iplayer.getMana() / 100) * 100); this.drawTexturedModalRect(xPos, yPos, 0, 85, manaBarWidth, 5); this.drawCenteredString(this.mc.fontRendererObj, String.valueOf(iplayer.getMana()),xPos + 50, yPos - 1, 0xFFFFFF); } } } This is how i registered the message public static SimpleNetworkWrapper NETWORK; @EventHandler public void preInit(FMLPreInitializationEvent event) { NETWORK = NetworkRegistry.INSTANCE.newSimpleChannel(MODID); NETWORK.registerMessage(PlayerMessageHandler.class, PlayerCapabilitiesMessage.class, 1, Side.CLIENT); } And these are the proxyes package com.rpg.proxy; import com.rpg.events.EventDimensionChange; import com.rpg.events.EventPlayerClone; import com.rpg.events.EventPlayerLogIn; import com.rpg.events.EventPlayerTick; import com.rpg.messages.PlayerMessageHandler; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.IThreadListener; import net.minecraft.world.WorldServer; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; public class CommonProxy { public void init() { MinecraftForge.EVENT_BUS.register(new PlayerMessageHandler()); } public IThreadListener getListener(MessageContext ctx) { return (WorldServer) ctx.getServerHandler().playerEntity.worldObj; } public EntityPlayer getPlayer(MessageContext ctx) { return ctx.getServerHandler().playerEntity; } } package com.rpg.proxy; import com.rpg.RPG; import com.rpg.capabilities.CapabilityHandler; import com.rpg.capabilities.item.IItemCapabilities; import com.rpg.capabilities.item.ItemCapabilities; import com.rpg.capabilities.item.ItemCapabilitiesStorage; import com.rpg.capabilities.player.IPlayerCapabilities; import com.rpg.capabilities.player.PlayerCapabilities; import com.rpg.capabilities.player.PlayerCapabilitiesStorage; import com.rpg.events.EventDimensionChange; import com.rpg.events.EventPlayerClone; import com.rpg.events.EventPlayerLogIn; import com.rpg.events.EventPlayerRespawn; import com.rpg.events.EventPlayerTick; import com.rpg.events.EventRightClick; import com.rpg.gui.GuiHandler; import com.rpg.gui.GuiOverlay; import net.minecraft.client.Minecraft; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.IThreadListener; import net.minecraftforge.common.MinecraftForge; import net.minecraftforge.common.capabilities.CapabilityManager; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; import net.minecraftforge.fml.relauncher.Side; public class ClientProxy extends CommonProxy{ public void init() { CapabilityManager.INSTANCE.register(IPlayerCapabilities.class, new PlayerCapabilitiesStorage(), PlayerCapabilities.class); CapabilityManager.INSTANCE.register(IItemCapabilities.class, new ItemCapabilitiesStorage(), ItemCapabilities.class); MinecraftForge.EVENT_BUS.register(new CapabilityHandler()); MinecraftForge.EVENT_BUS.register(new EventDimensionChange()); MinecraftForge.EVENT_BUS.register(new EventPlayerClone()); MinecraftForge.EVENT_BUS.register(new EventPlayerLogIn()); MinecraftForge.EVENT_BUS.register(new EventPlayerTick()); MinecraftForge.EVENT_BUS.register(new EventPlayerRespawn()); MinecraftForge.EVENT_BUS.register(new EventRightClick()); MinecraftForge.EVENT_BUS.register(new GuiOverlay(Minecraft.getMinecraft())); NetworkRegistry.INSTANCE.registerGuiHandler(RPG.INSTANCE, new GuiHandler()); } public IThreadListener getListener(MessageContext ctx) { return ctx.side == Side.CLIENT ? Minecraft.getMinecraft() : super.getListener(ctx); } public EntityPlayer getPlayer(MessageContext ctx) { return ctx.side == Side.CLIENT ? Minecraft.getMinecraft().thePlayer : super.getPlayer(ctx); } } Every tick i do this package com.rpg.events; import com.rpg.RPG; import com.rpg.capabilities.player.IPlayerCapabilities; import com.rpg.capabilities.player.PlayerCapabilitiesProvider; import com.rpg.messages.PlayerCapabilitiesMessage; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.gameevent.TickEvent.PlayerTickEvent; import net.minecraftforge.fml.relauncher.Side; public class EventPlayerTick { @SubscribeEvent public void onPlayerTick(PlayerTickEvent event) { if(event.side == Side.SERVER) { EntityPlayer player = event.player; IPlayerCapabilities capabilities = player.getCapability(PlayerCapabilitiesProvider.PLAYER_CAP, null); RPG.NETWORK.sendTo(new PlayerCapabilitiesMessage(capabilities), (EntityPlayerMP) player); } } } As i said server side there are no problems at all, it's just that in GUI isn't displayed the correct value. How can i fix this?
  2. I changed my class to this package com.mineworld.entity.decorations; import net.minecraft.block.material.Material; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAILookIdle; import net.minecraft.entity.ai.EntityLookHelper; import net.minecraft.entity.ai.EntityMoveHelper; import net.minecraft.entity.passive.EntityWaterMob; import net.minecraft.init.SoundEvents; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.datasync.DataParameter; import net.minecraft.network.datasync.DataSerializers; import net.minecraft.network.datasync.EntityDataManager; import net.minecraft.pathfinding.PathNavigate; import net.minecraft.pathfinding.PathNavigateSwimmer; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.datafix.DataFixer; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class EntityFish extends EntityWaterMob { private static final DataParameter<Byte> STATUS = EntityDataManager.<Byte>createKey(EntityFish.class, DataSerializers.BYTE); private float clientSideTailAnimation; private float clientSideTailAnimationO; private float clientSideTailAnimationSpeed; private boolean clientSideTouchedGround; public EntityFish(World worldIn) { super(worldIn); this.experienceValue = 10; this.setSize(0.45F, 0.45F); this.moveHelper = new EntityFish.FishMoveHelper(this); this.clientSideTailAnimation = this.rand.nextFloat(); this.clientSideTailAnimationO = this.clientSideTailAnimation; } protected void initEntityAI() { this.tasks.addTask(0, new EntityAILookIdle(this)); } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(2.0D); this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(1.0D); } public static void func_189766_b(DataFixer fixer) { EntityLiving.func_189752_a(fixer, "Fish"); } /** * (abstract) Protected helper method to read subclass entity data from NBT. */ public void readEntityFromNBT(NBTTagCompound compound) { super.readEntityFromNBT(compound); } /** * (abstract) Protected helper method to write subclass entity data to NBT. */ public void writeEntityToNBT(NBTTagCompound compound) { super.writeEntityToNBT(compound); } /** * Returns new PathNavigateGround instance */ protected PathNavigate getNewNavigator(World worldIn) { return new PathNavigateSwimmer(this, worldIn); } protected void entityInit() { super.entityInit(); this.dataManager.register(STATUS, Byte.valueOf((byte)0)); } /** * Returns true if given flag is set */ private boolean isSyncedFlagSet(int flagId) { return (((Byte)this.dataManager.get(STATUS)).byteValue() & flagId) != 0; } /** * Sets a flag state "on/off" on both sides (client/server) by using DataWatcher */ private void setSyncedFlag(int flagId, boolean state) { byte b0 = ((Byte)this.dataManager.get(STATUS)).byteValue(); if (state) { this.dataManager.set(STATUS, Byte.valueOf((byte)(b0 | flagId))); } else { this.dataManager.set(STATUS, Byte.valueOf((byte)(b0 & ~flagId))); } } public boolean isMoving() { return this.isSyncedFlagSet(2); } private void setMoving(boolean moving) { this.setSyncedFlag(2, moving); } public void notifyDataManagerChange(DataParameter<?> key) { super.notifyDataManagerChange(key); } /** * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to * prevent them from trampling crops */ protected boolean canTriggerWalking() { return false; } public float getEyeHeight() { return this.height * 0.2F; } public float getBlockPathWeight(BlockPos pos) { return 10.0F + this.worldObj.getLightBrightness(pos) - 0.5F; } /** * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons * use this to react to sunlight and start to burn. */ public void onLivingUpdate() { if (this.worldObj.isRemote) { this.clientSideTailAnimationO = this.clientSideTailAnimation; if (!this.isInWater()) { this.clientSideTailAnimationSpeed = 2.0F; if (this.motionY > 0.0D && this.clientSideTouchedGround && !this.isSilent()) { this.worldObj.playSound(this.posX, this.posY, this.posZ, SoundEvents.ENTITY_GUARDIAN_FLOP, this.getSoundCategory(), 1.0F, 1.0F, false); } this.clientSideTouchedGround = this.motionY < 0.0D && this.worldObj.isBlockNormalCube((new BlockPos(this)).down(), false); } else if (this.isMoving()) { if (this.clientSideTailAnimationSpeed < 0.5F) { this.clientSideTailAnimationSpeed = 4.0F; } else { this.clientSideTailAnimationSpeed += (0.5F - this.clientSideTailAnimationSpeed) * 0.1F; } } else { this.clientSideTailAnimationSpeed += (0.125F - this.clientSideTailAnimationSpeed) * 0.2F; } this.clientSideTailAnimation += this.clientSideTailAnimationSpeed; if (this.isMoving() && this.isInWater()) { Vec3d vec3d = this.getLook(0.0F); for (int i = 0; i < 2; ++i) { this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width - vec3d.xCoord * 1.5D, this.posY + this.rand.nextDouble() * (double)this.height - vec3d.yCoord * 1.5D, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width - vec3d.zCoord * 1.5D, 0.0D, 0.0D, 0.0D, new int[0]); } } } if (this.inWater) { this.setAir(300); } else if (this.onGround) { this.motionY += 0.5D; this.motionX += (double)((this.rand.nextFloat() * 2.0F - 1.0F) * 0.4F); this.motionZ += (double)((this.rand.nextFloat() * 2.0F - 1.0F) * 0.4F); this.rotationYaw = this.rand.nextFloat() * 360.0F; this.onGround = false; this.isAirBorne = true; } super.onLivingUpdate(); } @SideOnly(Side.CLIENT) public float getTailAnimation(float f) { return this.clientSideTailAnimationO + (this.clientSideTailAnimation - this.clientSideTailAnimationO) * f; } protected void updateAITasks() { super.updateAITasks(); } @Override public boolean handleWaterMovement() { return worldObj.handleMaterialAcceleration(getEntityBoundingBox(), Material.WATER, this); } /** * Checks to make sure the light is not too bright where the mob is spawning */ protected boolean isValidLightLevel() { return true; } /** * Checks that the entity is not colliding with any blocks / liquids */ public boolean isNotColliding() { return this.worldObj.checkNoEntityCollision(this.getEntityBoundingBox(), this) && this.worldObj.getCollisionBoxes(this, this.getEntityBoundingBox()).isEmpty(); } /** * Checks if the entity's current position is a valid location to spawn this entity. */ public boolean getCanSpawnHere() { return this.posY > 45.0D && this.posY < (double)this.worldObj.getSeaLevel() && super.getCanSpawnHere(); } /** * Moves the entity based on the specified heading. */ public void moveEntityWithHeading(float strafe, float forward) { if (this.isServerWorld()) { if (this.isInWater()) { this.moveRelative(strafe, forward, 0.1F); this.moveEntity(this.motionX, this.motionY, this.motionZ); this.motionX *= 0.8999999761581421D; this.motionY *= 0.8999999761581421D; this.motionZ *= 0.8999999761581421D; if (!this.isMoving() && this.getAttackTarget() == null) { this.motionY -= 0.005D; } } else { super.moveEntityWithHeading(strafe, forward); } } else { super.moveEntityWithHeading(strafe, forward); } } static class FishMoveHelper extends EntityMoveHelper { private final EntityFish entityFish; public FishMoveHelper(EntityFish fish) { super(fish); this.entityFish = fish; } public void onUpdateMoveHelper() { if (this.action == EntityMoveHelper.Action.MOVE_TO && !this.entityFish.getNavigator().noPath()) { double d0 = this.posX - this.entityFish.posX; double d1 = this.posY - this.entityFish.posY; double d2 = this.posZ - this.entityFish.posZ; double d3 = d0 * d0 + d1 * d1 + d2 * d2; d3 = (double)MathHelper.sqrt_double(d3); d1 = d1 / d3; float f = (float)(MathHelper.atan2(d2, d0) * (180D / Math.PI)) - 90.0F; this.entityFish.rotationYaw = this.limitAngle(this.entityFish.rotationYaw, f, 90.0F); this.entityFish.renderYawOffset = this.entityFish.rotationYaw; float f1 = (float)(this.speed * this.entityFish.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue()); this.entityFish.setAIMoveSpeed(this.entityFish.getAIMoveSpeed() + (f1 - this.entityFish.getAIMoveSpeed()) * 0.125F); double d4 = Math.sin((double)(this.entityFish.ticksExisted + this.entityFish.getEntityId()) * 0.5D) * 0.05D; double d5 = Math.cos((double)(this.entityFish.rotationYaw * 0.017453292F)); double d6 = Math.sin((double)(this.entityFish.rotationYaw * 0.017453292F)); this.entityFish.motionX += d4 * d5; this.entityFish.motionZ += d4 * d6; d4 = Math.sin((double)(this.entityFish.ticksExisted + this.entityFish.getEntityId()) * 0.75D) * 0.05D; this.entityFish.motionY += d4 * (d6 + d5) * 0.25D; this.entityFish.motionY += (double)this.entityFish.getAIMoveSpeed() * d1 * 0.1D; EntityLookHelper entitylookhelper = this.entityFish.getLookHelper(); double d7 = this.entityFish.posX + d0 / d3 * 2.0D; double d8 = (double)this.entityFish.getEyeHeight() + this.entityFish.posY + d1 / d3; double d9 = this.entityFish.posZ + d2 / d3 * 2.0D; double d10 = entitylookhelper.getLookPosX(); double d11 = entitylookhelper.getLookPosY(); double d12 = entitylookhelper.getLookPosZ(); if (!entitylookhelper.getIsLooking()) { d10 = d7; d11 = d8; d12 = d9; } this.entityFish.getLookHelper().setLookPosition(d10 + (d7 - d10) * 0.125D, d11 + (d8 - d11) * 0.125D, d12 + (d9 - d12) * 0.125D, 10.0F, 40.0F); this.entityFish.setMoving(true); } else { this.entityFish.setAIMoveSpeed(0.0F); this.entityFish.setMoving(false); } } } } But it still try to spawn on ground
  3. I've already tried but not only the fish tries to spawn on ground, it doesn't move too
  4. I'm trying to make a water creature (a fish) that is passive and will spawn in river and oceans. To handle is movement and AI i've looked at how guardians works and the mob itself works fine. But it doesn't naturally spawn in the world. I've registered it like this EntityRegistry.addSpawn(EntityClownFish.class, 50, 5, 10, EnumCreatureType.WATER_CREATURE, Biomes.RIVER, Biomes.OCEAN, Biomes.DEEP_OCEAN); But the game tries to spawn it on ground and not in water (so the canSpawnHere will return false and the fish will not spawn). So how can i make it actually spawn in the water? This is the entity class i'm using package com.mineworld.entity.decorations; import javax.annotation.Nullable; import com.google.common.base.Predicate; import com.mineworld.MW; import net.minecraft.block.material.Material; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.ai.EntityAIBase; import net.minecraft.entity.ai.EntityAILookIdle; import net.minecraft.entity.ai.EntityAIMoveTowardsRestriction; import net.minecraft.entity.ai.EntityAINearestAttackableTarget; import net.minecraft.entity.ai.EntityAIWander; import net.minecraft.entity.ai.EntityAIWatchClosest; import net.minecraft.entity.ai.EntityLookHelper; import net.minecraft.entity.ai.EntityMoveHelper; import net.minecraft.entity.monster.EntityMob; import net.minecraft.entity.passive.EntitySquid; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.init.MobEffects; import net.minecraft.init.SoundEvents; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.network.datasync.DataParameter; import net.minecraft.network.datasync.DataSerializers; import net.minecraft.network.datasync.EntityDataManager; import net.minecraft.network.play.server.SPacketChangeGameState; import net.minecraft.pathfinding.PathNavigate; import net.minecraft.pathfinding.PathNavigateSwimmer; import net.minecraft.potion.Potion; import net.minecraft.potion.PotionEffect; import net.minecraft.util.DamageSource; import net.minecraft.util.EnumParticleTypes; import net.minecraft.util.ResourceLocation; import net.minecraft.util.SoundEvent; import net.minecraft.util.datafix.DataFixer; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.Vec3d; import net.minecraft.world.EnumDifficulty; import net.minecraft.world.World; import net.minecraft.world.storage.loot.LootTableList; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; public class EntityFish extends EntityMob { private static final DataParameter<Byte> STATUS = EntityDataManager.<Byte>createKey(EntityFish.class, DataSerializers.BYTE); private float clientSideTailAnimation; private float clientSideTailAnimationO; private float clientSideTailAnimationSpeed; private boolean clientSideTouchedGround; private EntityAIWander wander; public EntityFish(World worldIn) { super(worldIn); this.experienceValue = 10; this.setSize(0.45F, 0.45F); this.moveHelper = new EntityFish.FishMoveHelper(this); this.clientSideTailAnimation = this.rand.nextFloat(); this.clientSideTailAnimationO = this.clientSideTailAnimation; } protected void initEntityAI() { EntityAIMoveTowardsRestriction entityaimovetowardsrestriction = new EntityAIMoveTowardsRestriction(this, 1.0D); this.wander = new EntityAIWander(this, 1.0D, 80); this.tasks.addTask(5, entityaimovetowardsrestriction); this.tasks.addTask(7, this.wander); this.tasks.addTask(9, new EntityAILookIdle(this)); this.wander.setMutexBits(3); entityaimovetowardsrestriction.setMutexBits(3); } protected void applyEntityAttributes() { super.applyEntityAttributes(); this.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(2.0D); this.getEntityAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(1.0D); } public static void func_189766_b(DataFixer p_189766_0_) { EntityLiving.func_189752_a(p_189766_0_, "ClownFish"); } /** * (abstract) Protected helper method to read subclass entity data from NBT. */ public void readEntityFromNBT(NBTTagCompound compound) { super.readEntityFromNBT(compound); } /** * (abstract) Protected helper method to write subclass entity data to NBT. */ public void writeEntityToNBT(NBTTagCompound compound) { super.writeEntityToNBT(compound); } /** * Returns new PathNavigateGround instance */ protected PathNavigate getNewNavigator(World worldIn) { return new PathNavigateSwimmer(this, worldIn); } protected void entityInit() { super.entityInit(); this.dataManager.register(STATUS, Byte.valueOf((byte)0)); } /** * Returns true if given flag is set */ private boolean isSyncedFlagSet(int flagId) { return (((Byte)this.dataManager.get(STATUS)).byteValue() & flagId) != 0; } /** * Sets a flag state "on/off" on both sides (client/server) by using DataWatcher */ private void setSyncedFlag(int flagId, boolean state) { byte b0 = ((Byte)this.dataManager.get(STATUS)).byteValue(); if (state) { this.dataManager.set(STATUS, Byte.valueOf((byte)(b0 | flagId))); } else { this.dataManager.set(STATUS, Byte.valueOf((byte)(b0 & ~flagId))); } } public boolean isMoving() { return this.isSyncedFlagSet(2); } private void setMoving(boolean moving) { this.setSyncedFlag(2, moving); } public void notifyDataManagerChange(DataParameter<?> key) { super.notifyDataManagerChange(key); } /** * returns if this entity triggers Block.onEntityWalking on the blocks they walk on. used for spiders and wolves to * prevent them from trampling crops */ protected boolean canTriggerWalking() { return false; } public float getEyeHeight() { return this.height * 0.2F; } public float getBlockPathWeight(BlockPos pos) { return this.worldObj.getBlockState(pos).getMaterial() == Material.WATER ? 10.0F + this.worldObj.getLightBrightness(pos) - 0.5F : super.getBlockPathWeight(pos); } /** * Called frequently so the entity can update its state every tick as required. For example, zombies and skeletons * use this to react to sunlight and start to burn. */ public void onLivingUpdate() { if (this.worldObj.isRemote) { this.clientSideTailAnimationO = this.clientSideTailAnimation; if (!this.isInWater()) { this.clientSideTailAnimationSpeed = 2.0F; if (this.motionY > 0.0D && this.clientSideTouchedGround && !this.isSilent()) { this.worldObj.playSound(this.posX, this.posY, this.posZ, SoundEvents.ENTITY_GUARDIAN_FLOP, this.getSoundCategory(), 1.0F, 1.0F, false); } this.clientSideTouchedGround = this.motionY < 0.0D && this.worldObj.isBlockNormalCube((new BlockPos(this)).down(), false); } else if (this.isMoving()) { if (this.clientSideTailAnimationSpeed < 0.5F) { this.clientSideTailAnimationSpeed = 4.0F; } else { this.clientSideTailAnimationSpeed += (0.5F - this.clientSideTailAnimationSpeed) * 0.1F; } } else { this.clientSideTailAnimationSpeed += (0.125F - this.clientSideTailAnimationSpeed) * 0.2F; } this.clientSideTailAnimation += this.clientSideTailAnimationSpeed; if (this.isMoving() && this.isInWater()) { Vec3d vec3d = this.getLook(0.0F); for (int i = 0; i < 2; ++i) { this.worldObj.spawnParticle(EnumParticleTypes.WATER_BUBBLE, this.posX + (this.rand.nextDouble() - 0.5D) * (double)this.width - vec3d.xCoord * 1.5D, this.posY + this.rand.nextDouble() * (double)this.height - vec3d.yCoord * 1.5D, this.posZ + (this.rand.nextDouble() - 0.5D) * (double)this.width - vec3d.zCoord * 1.5D, 0.0D, 0.0D, 0.0D, new int[0]); } } } if (this.inWater) { this.setAir(300); } else if (this.onGround) { this.motionY += 0.5D; this.motionX += (double)((this.rand.nextFloat() * 2.0F - 1.0F) * 0.4F); this.motionZ += (double)((this.rand.nextFloat() * 2.0F - 1.0F) * 0.4F); this.rotationYaw = this.rand.nextFloat() * 360.0F; this.onGround = false; this.isAirBorne = true; } super.onLivingUpdate(); } @SideOnly(Side.CLIENT) public float getTailAnimation(float p_175471_1_) { return this.clientSideTailAnimationO + (this.clientSideTailAnimation - this.clientSideTailAnimationO) * p_175471_1_; } protected void updateAITasks() { super.updateAITasks(); } /** * Checks to make sure the light is not too bright where the mob is spawning */ protected boolean isValidLightLevel() { return true; } /** * Checks that the entity is not colliding with any blocks / liquids */ public boolean isNotColliding() { return this.worldObj.checkNoEntityCollision(this.getEntityBoundingBox(), this) && this.worldObj.getCollisionBoxes(this, this.getEntityBoundingBox()).isEmpty(); } /** * Checks if the entity's current position is a valid location to spawn this entity. */ public boolean getCanSpawnHere() { System.out.println(this.posX + " " + this.posZ + " VALUE: " + (this.posY > 45.0D && this.posY < (double)this.worldObj.getSeaLevel() && super.getCanSpawnHere())); return !this.worldObj.canBlockSeeSky(new BlockPos(this)) && super.getCanSpawnHere(); } /** * Moves the entity based on the specified heading. */ public void moveEntityWithHeading(float strafe, float forward) { if (this.isServerWorld()) { if (this.isInWater()) { this.moveRelative(strafe, forward, 0.1F); this.moveEntity(this.motionX, this.motionY, this.motionZ); this.motionX *= 0.8999999761581421D; this.motionY *= 0.8999999761581421D; this.motionZ *= 0.8999999761581421D; if (!this.isMoving() && this.getAttackTarget() == null) { this.motionY -= 0.005D; } } else { super.moveEntityWithHeading(strafe, forward); } } else { super.moveEntityWithHeading(strafe, forward); } } static class FishMoveHelper extends EntityMoveHelper { private final EntityFish entityFish; public FishMoveHelper(EntityFish fish) { super(fish); this.entityFish = fish; } public void onUpdateMoveHelper() { if (this.action == EntityMoveHelper.Action.MOVE_TO && !this.entityFish.getNavigator().noPath()) { double d0 = this.posX - this.entityFish.posX; double d1 = this.posY - this.entityFish.posY; double d2 = this.posZ - this.entityFish.posZ; double d3 = d0 * d0 + d1 * d1 + d2 * d2; d3 = (double)MathHelper.sqrt_double(d3); d1 = d1 / d3; float f = (float)(MathHelper.atan2(d2, d0) * (180D / Math.PI)) - 90.0F; this.entityFish.rotationYaw = this.limitAngle(this.entityFish.rotationYaw, f, 90.0F); this.entityFish.renderYawOffset = this.entityFish.rotationYaw; float f1 = (float)(this.speed * this.entityFish.getEntityAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).getAttributeValue()); this.entityFish.setAIMoveSpeed(this.entityFish.getAIMoveSpeed() + (f1 - this.entityFish.getAIMoveSpeed()) * 0.125F); double d4 = Math.sin((double)(this.entityFish.ticksExisted + this.entityFish.getEntityId()) * 0.5D) * 0.05D; double d5 = Math.cos((double)(this.entityFish.rotationYaw * 0.017453292F)); double d6 = Math.sin((double)(this.entityFish.rotationYaw * 0.017453292F)); this.entityFish.motionX += d4 * d5; this.entityFish.motionZ += d4 * d6; d4 = Math.sin((double)(this.entityFish.ticksExisted + this.entityFish.getEntityId()) * 0.75D) * 0.05D; this.entityFish.motionY += d4 * (d6 + d5) * 0.25D; this.entityFish.motionY += (double)this.entityFish.getAIMoveSpeed() * d1 * 0.1D; EntityLookHelper entitylookhelper = this.entityFish.getLookHelper(); double d7 = this.entityFish.posX + d0 / d3 * 2.0D; double d8 = (double)this.entityFish.getEyeHeight() + this.entityFish.posY + d1 / d3; double d9 = this.entityFish.posZ + d2 / d3 * 2.0D; double d10 = entitylookhelper.getLookPosX(); double d11 = entitylookhelper.getLookPosY(); double d12 = entitylookhelper.getLookPosZ(); if (!entitylookhelper.getIsLooking()) { d10 = d7; d11 = d8; d12 = d9; } this.entityFish.getLookHelper().setLookPosition(d10 + (d7 - d10) * 0.125D, d11 + (d8 - d11) * 0.125D, d12 + (d9 - d12) * 0.125D, 10.0F, 40.0F); this.entityFish.setMoving(true); } else { this.entityFish.setAIMoveSpeed(0.0F); this.entityFish.setMoving(false); } } } }
  5. So debugging looks like client side the game check if the book is a writable book (not a written one) and so the GUI doesn't show up. By adding this Minecraft.getMinecraft().displayGuiScreen(new GuiScreenBook(playerIn, wr.item, false)); to the block code i can now show the GUI. But i'm confused on why the client check for a writable book if that code is called from the ItemWrittenBook
  6. Wops, ok so now the block class extends blocks and uses the Block.class methods for the tile entity package com.mineworld.blocks.decorations; import com.mineworld.core.MWTabs; import com.mineworld.tileentity.decorations.TileEntityLectern; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemWrittenBook; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class BlockLectern extends Block{ public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public BlockLectern() { super(Material.WOOD); this.setHardness(2.0F); this.setSoundType(SoundType.WOOD); this.setCreativeTab(MWTabs.tabDecorations); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); } public IBlockState withRotation(IBlockState state, Rotation rot) { return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING))); } /** * Returns the blockstate with the given mirror of the passed blockstate. If * inapplicable, returns the passed blockstate. */ public IBlockState withMirror(IBlockState state, Mirror mirrorIn) { return state.withRotation(mirrorIn.toRotation((EnumFacing) state.getValue(FACING))); } /** * Called by ItemBlocks just before a block is actually set in the world, to * allow for adjustments to the IBlockstate */ public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing()); } /** * Convert the given metadata into a BlockState for this Block */ public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)); } /** * Convert the BlockState into the correct metadata value */ public int getMetaFromState(IBlockState state) { return ((EnumFacing) state.getValue(FACING)).getHorizontalIndex(); } protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] { FACING }); } @Override public boolean isOpaqueCube(IBlockState state) { return false; } @Override public boolean isFullCube(IBlockState state) { return false; } @Override public boolean hasTileEntity(IBlockState state) { return true; } @Override public TileEntity createTileEntity(World world, IBlockState state) { return new TileEntityLectern(); } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { if (!worldIn.isRemote) { TileEntity te = worldIn.getTileEntity(pos); if (te instanceof TileEntityLectern) { TileEntityLectern wr = (TileEntityLectern) te; if (heldItem != null && heldItem.getItem() instanceof ItemWrittenBook) { if (wr.addItem(heldItem)) { playerIn.inventory.removeStackFromSlot(playerIn.inventory.currentItem); return true; } } if(playerIn.isSneaking()) wr.removeItem(); else { if(wr.item != null) { playerIn.openBook(wr.item, hand); } } } } return true; } public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityLectern) { ((TileEntityLectern) tileentity).removeItem(); } super.breakBlock(worldIn, pos, state); } } But the behavior is not changed, i can still put a book in it, get it back if i shift click but if i right click it won't open the book gui of the book stored in it (wich i assume is correctly stored since i can get it back)
  7. Ok, so i changed my class to this package com.mineworld.blocks.decorations; import com.mineworld.core.MWTabs; import com.mineworld.tileentity.decorations.TileEntityLectern; import com.mineworld.tileentity.decorations.TileEntityWeaponRack; import net.minecraft.block.BlockContainer; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.item.ItemWrittenBook; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumBlockRenderType; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class BlockLectern extends BlockContainer{ public static final PropertyDirection FACING = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL); public BlockLectern() { super(Material.WOOD); this.setHardness(2.0F); this.setSoundType(SoundType.WOOD); this.setCreativeTab(MWTabs.tabDecorations); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); } public IBlockState withRotation(IBlockState state, Rotation rot) { return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING))); } /** * Returns the blockstate with the given mirror of the passed blockstate. If * inapplicable, returns the passed blockstate. */ public IBlockState withMirror(IBlockState state, Mirror mirrorIn) { return state.withRotation(mirrorIn.toRotation((EnumFacing) state.getValue(FACING))); } /** * Called by ItemBlocks just before a block is actually set in the world, to * allow for adjustments to the IBlockstate */ public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing()); } /** * Convert the given metadata into a BlockState for this Block */ public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)); } /** * Convert the BlockState into the correct metadata value */ public int getMetaFromState(IBlockState state) { return ((EnumFacing) state.getValue(FACING)).getHorizontalIndex(); } protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] { FACING }); } @Override public boolean isOpaqueCube(IBlockState state) { return false; } @Override public boolean isFullCube(IBlockState state) { return false; } @Override public boolean hasTileEntity() { return true; } @Override public TileEntity createNewTileEntity(World world, int state) { return new TileEntityLectern(); } @Override public EnumBlockRenderType getRenderType(IBlockState state) { return EnumBlockRenderType.MODEL; } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { if (!worldIn.isRemote) { TileEntity te = worldIn.getTileEntity(pos); if (te instanceof TileEntityLectern) { TileEntityLectern wr = (TileEntityLectern) te; if (heldItem != null && heldItem.getItem() instanceof ItemWrittenBook) { if (wr.addItem(heldItem)) { playerIn.inventory.removeStackFromSlot(playerIn.inventory.currentItem); return true; } } if(playerIn.isSneaking()) wr.removeItem(); else { if(wr.item != null) { playerIn.openBook(wr.item, hand); } } } } return true; } public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityLectern) { ((TileEntityLectern) tileentity).removeItem(); } super.breakBlock(worldIn, pos, state); } } But still the book GUI doesn't show up
  8. Here it is package com.mineworld.tileentity.decorations; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagList; import net.minecraft.network.NetworkManager; import net.minecraft.network.play.server.SPacketUpdateTileEntity; import net.minecraft.tileentity.TileEntity; public class TileEntityLectern extends TileEntity { public ItemStack item = null; public boolean render = false; public boolean addItem(ItemStack item) { if (this.item == null) { this.item = item; this.render = true; markDirty(); IBlockState state = worldObj.getBlockState(pos); worldObj.notifyBlockUpdate(pos, state, state, 3); return true; } return false; } public void removeItem() { if (this.item != null) { worldObj.spawnEntityInWorld( new EntityItem(worldObj, pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5, this.item)); this.item = null; this.render = false; markDirty(); IBlockState state = worldObj.getBlockState(pos); worldObj.notifyBlockUpdate(pos, state, state, 3); return; } } public void readFromNBT(NBTTagCompound compound) { super.readFromNBT(compound); NBTTagList nbttaglist = compound.getTagList("Items", 10); for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i); int j = nbttagcompound.getByte("Item") & 255; this.item = ItemStack.loadItemStackFromNBT(nbttagcompound); } this.render = compound.getBoolean("render"); } public NBTTagCompound writeToNBT(NBTTagCompound compound) { super.writeToNBT(compound); NBTTagList nbttaglist = new NBTTagList(); NBTTagCompound nbttagcompound = new NBTTagCompound(); if (this.item != null) { nbttagcompound.setByte("Item", (byte) 1); this.item.writeToNBT(nbttagcompound); nbttaglist.appendTag(nbttagcompound); } compound.setTag("Items", nbttaglist); compound.setBoolean("render", this.render); return compound; } @Override public void onDataPacket(NetworkManager net, SPacketUpdateTileEntity pkt) { NBTTagCompound compound = pkt.getNbtCompound(); readUpdateTag(compound); } @Override public SPacketUpdateTileEntity getUpdatePacket() { NBTTagCompound tagCom = new NBTTagCompound(); this.writeUpdateTag(tagCom); return new SPacketUpdateTileEntity(pos, getBlockMetadata(), tagCom); } @Override public NBTTagCompound getUpdateTag() { NBTTagCompound tag = super.getUpdateTag(); writeUpdateTag(tag); return tag; } public void writeUpdateTag(NBTTagCompound tag) { NBTTagList nbttaglist = new NBTTagList(); NBTTagCompound nbttagcompound = new NBTTagCompound(); if (this.item != null) { nbttagcompound.setByte("Item", (byte) 1); this.item.writeToNBT(nbttagcompound); nbttaglist.appendTag(nbttagcompound); } tag.setTag("Items", nbttaglist); tag.setBoolean("render", this.render); } public void readUpdateTag(NBTTagCompound tag) { NBTTagList nbttaglist = tag.getTagList("Items", 10); for (int i = 0; i < nbttaglist.tagCount(); ++i) { NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i); int j = nbttagcompound.getByte("Item") & 255; this.item = ItemStack.loadItemStackFromNBT(nbttagcompound); } this.render = tag.getBoolean("render"); } }
  9. I'm trying to make a lectern so players can place a book in it and open its GUI when right click the block. But unfortunately the GUI doesn't show up when the player right click the block. This is the block code i'm using package com.mineworld.blocks.decorations; import com.mineworld.core.MWTabs; import com.mineworld.tileentity.decorations.TileEntityLectern; import com.mineworld.tileentity.decorations.TileEntityWeaponRack; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.ITileEntityProvider; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.item.ItemStack; import net.minecraft.item.ItemSword; import net.minecraft.item.ItemWrittenBook; import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; public class BlockLectern extends BlockHorizontal implements ITileEntityProvider { public BlockLectern() { super(Material.WOOD); this.setHardness(2.0F); this.setSoundType(SoundType.WOOD); this.setCreativeTab(MWTabs.tabDecorations); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); } public IBlockState withRotation(IBlockState state, Rotation rot) { return state.withProperty(FACING, rot.rotate((EnumFacing) state.getValue(FACING))); } /** * Returns the blockstate with the given mirror of the passed blockstate. If * inapplicable, returns the passed blockstate. */ public IBlockState withMirror(IBlockState state, Mirror mirrorIn) { return state.withRotation(mirrorIn.toRotation((EnumFacing) state.getValue(FACING))); } /** * Called by ItemBlocks just before a block is actually set in the world, to * allow for adjustments to the IBlockstate */ public IBlockState onBlockPlaced(World worldIn, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) { return this.getDefaultState().withProperty(FACING, placer.getHorizontalFacing()); } /** * Convert the given metadata into a BlockState for this Block */ public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(FACING, EnumFacing.getHorizontal(meta)); } /** * Convert the BlockState into the correct metadata value */ public int getMetaFromState(IBlockState state) { return ((EnumFacing) state.getValue(FACING)).getHorizontalIndex(); } protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] { FACING }); } @Override public boolean isOpaqueCube(IBlockState state) { return false; } @Override public boolean isFullCube(IBlockState state) { return false; } @Override public TileEntity createNewTileEntity(World worldIn, int meta) { return new TileEntityLectern(); } @Override public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state, EntityPlayer playerIn, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ) { if (!worldIn.isRemote) { TileEntity te = worldIn.getTileEntity(pos); if (te instanceof TileEntityLectern) { TileEntityLectern wr = (TileEntityLectern) te; if (heldItem != null && heldItem.getItem() != null && heldItem.getItem() instanceof ItemWrittenBook) { if (wr.addItem(heldItem)) { playerIn.inventory.removeStackFromSlot(playerIn.inventory.currentItem); return true; } } if(playerIn.isSneaking()) wr.removeItem(); else { if(wr.item != null) { playerIn.openBook(wr.item, hand); } } } } return true; } public void breakBlock(World worldIn, BlockPos pos, IBlockState state) { TileEntity tileentity = worldIn.getTileEntity(pos); if (tileentity instanceof TileEntityLectern) { ((TileEntityLectern) tileentity).removeItem(); } super.breakBlock(worldIn, pos, state); } } I'm sure the book is correctly saved into the tile entity because i can remove the book from the block if i shift-click it. So why the GUI doesn't open?
  10. YAY! Now the model works as intended, but i have one little question. How can i render the custom name of the sword that is placed? I already looked at how ItemFrame does but that doesn't work very well in this case (i can see the name from a larger distance)
  11. Thanks for your help, by doing the ITEM1.hoverStart = 0 it seems that problem is solved. For the translate i do this before any rotation GlStateManager.translate(x, y, z); And then rotate and re-position, but i guess i'll try again using the playerPos to see where exactly translate the object I really appreciate you help, thank you for helped me
  12. That could be related to the Teleporter class, i suggest to run the game in debug mode, add a breakpoint in the teleporter class and see what the game does so you can understand why it takes you back to the Nether
  13. If your item is an instance of ItemSword than you can override the hitEntity method. In here you should check if the attacker is sprinting (by using attacker.isSprinting()) and if he is then you should apply more damage by doing target.attackEntityFrom(source, amount), where source is the source of your damage, and amount is the amount of damage you want to do. An example of the code could be this @Override public boolean hitEntity(ItemStack stack, EntityLivingBase target, EntityLivingBase attacker) { if(attacker instanceof EntityPlayer) { EntityPlayer player = (EntityPlayer)attacker; if(player.isSprinting()) target.attackEntityFrom(DamageSource.causePlayerDamage(player), this.getDamageVsEntity() * 2); else target.attackEntityFrom(DamageSource.causePlayerDamage(player), this.getDamageVsEntity()); } return super.hitEntity(stack, target, attacker); }
  14. Mmm, you can debug to see if the teleporter code is actually called and what it does. Also try changing the onEntityCollide method to this public void onEntityCollidedWithBlock(World worldIn, BlockPos pos, IBlockState state, Entity entityIn) { if (!entityIn.isRiding() && !entityIn.isBeingRidden() && entityIn instanceof EntityPlayerMP) { entityIn.setPortal(pos); EntityPlayerMP thePlayer = (EntityPlayerMP)entityIn; if (thePlayer.timeUntilPortal > 0) { thePlayer.timeUntilPortal = 10; } else if (thePlayer.dimension != BedrockiumMod.dimensionIdBedrockium) { thePlayer.timeUntilPortal = 10; thePlayer.mcServer.getConfigurationManager().transferPlayerToDimension(thePlayer, BedrockiumMod.dimensionIdBedrockium, new TeleporterCorrupted(thePlayer.mcServer.worldServerForDimension(BedrockiumMod.dimensionIdBedrockium))); } else if (thePlayer.dimension == BedrockiumMod.dimensionIdBedrockium) { thePlayer.timeUntilPortal = 10; thePlayer.mcServer.getConfigurationManager().transferPlayerToDimension(thePlayer, 0, new TeleporterCorrupted(thePlayer.mcServer.worldServerForDimension(0))); } } } I'm using in my mod and it works fine (notice that something could be different as i take the code from 1.10)
  15. I think that this this.worldServerInstance.provider.getDimensionId() != 1 should be changed to this this.worldServerInstance.provider.getDimensionId() != BedrockiumMod.dimensionIdBedrockium Also is the dimension correctly registered?
  16. @Kokkie i've to do this before the rotating/translating part or after? So, i've done what TGG said, first time works "fine", i just need to translate the object but the rotation is good. But as i reload the world the object is messed up and it uses the exact same code This is how it looks the first time And this is how it looks reloading the world As i said while reloading the world i didn't changed the code and this is why i don't understand why it changed This is the rendering code i'm using now package com.mineworld.tileentity.renderer.decorations; import com.mineworld.blocks.decorations.BlockWeaponRack; import com.mineworld.tileentity.decorations.TileEntityWeaponRack; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing.Axis; public class TileEntityWeaponRackRenderer extends TileEntitySpecialRenderer<TileEntityWeaponRack> { EntityItem ITEM1 = new EntityItem(Minecraft.getMinecraft().theWorld, 0, 0, 0); @Override public void renderTileEntityAt(TileEntityWeaponRack te, double x, double y, double z, float partialTicks, int destroyStage) { super.renderTileEntityAt(te, x, y, z, partialTicks, destroyStage); Axis ax = Axis.X; PropertyDirection dir = (PropertyDirection) te.getBlockType().getBlockState() .getProperty(BlockWeaponRack.FACING.getName()); if (dir != null) { ax = te.getWorld().getBlockState(te.getPos()).getValue(dir).getAxis(); } if (te.render) { GlStateManager.pushMatrix(); GlStateManager.translate(x, y, z); if (ax == Axis.Z) { GlStateManager.rotate(35.953893327090036F, 0, 0, 1); GlStateManager.rotate(20.12758483703185F, 1, 0, 0); } else { GlStateManager.rotate(135F, 0, 1, 0); GlStateManager.rotate(135F, 0, 0, 1); GlStateManager.rotate(60F, 0, 1, 0); GlStateManager.translate(0.5, 0, 0); GlStateManager.translate(0.05, -0.5, 0.75); } ITEM1.setEntityItemStack(new ItemStack(te.item)); Minecraft.getMinecraft().getRenderManager().doRenderEntity(ITEM1, 0, 0, 0, 0F, 0F, false); GlStateManager.popMatrix(); } } } I've tested only on the Z axis using the TGG method to get that values
  17. @Animefan8888 This is what it looks when i place 2 of them on the X axis And this is what it looks wehn i place 2 of them on the Z axis It looks like they rotate or something. I've also changed the code while making some test, here is the new one package com.mineworld.tileentity.renderer.decorations; import com.mineworld.blocks.decorations.BlockWeaponRack; import com.mineworld.tileentity.decorations.TileEntityWeaponRack; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing.Axis; public class TileEntityWeaponRackRenderer extends TileEntitySpecialRenderer<TileEntityWeaponRack> { EntityItem ITEM1 = new EntityItem(Minecraft.getMinecraft().theWorld, 0, 0, 0); @Override public void renderTileEntityAt(TileEntityWeaponRack te, double x, double y, double z, float partialTicks, int destroyStage) { super.renderTileEntityAt(te, x, y, z, partialTicks, destroyStage); Axis ax = Axis.X; PropertyDirection dir = (PropertyDirection) te.getBlockType().getBlockState() .getProperty(BlockWeaponRack.FACING.getName()); if (dir != null) { ax = te.getWorld().getBlockState(te.getPos()).getValue(dir).getAxis(); } if (te.render) { GlStateManager.pushMatrix(); GlStateManager.translate(x, y, z); if (ax == Axis.Z) { GlStateManager.rotate(-135F, 0, 0, 1); GlStateManager.translate(0, 0, 0.5); GlStateManager.translate(-0.1, 0, 0); GlStateManager.translate(0, -1.2, 0); GlStateManager.translate(0.2, -0.1, 0.1); } else { GlStateManager.rotate(135F, 0, 1, 0); GlStateManager.rotate(135F, 0, 0, 1); GlStateManager.rotate(60F, 0, 1, 0); GlStateManager.translate(0.5, 0, 0); GlStateManager.translate(0.05, -0.5, 0.75); } ITEM1.setEntityItemStack(new ItemStack(te.item)); Minecraft.getMinecraft().getRenderManager().doRenderEntity(ITEM1, 0, 0, 0, 0F, 0F, false); GlStateManager.popMatrix(); } } } @TheGreyGhost I will try doing that, what i don't understand is how exactly the rotation and the translation works, since if i translate on the Z axis the object goes up or down too. But i'll see if i understand this by using your method and let you know
  18. I have a block with a Tile Entity that will show an item texture placed into that block (for instance a diamond sword). But when the sword is rendered is not rendered as i want (in this case it should look like a sword into a stone). I runned the game in debug mode to adjust this, but when i reload the world and place a new block the rendering is messed up. So, how can i render correctly the sword? Here is my Tile Entity Render Class package com.mineworld.tileentity.renderer.decorations; import com.mineworld.blocks.decorations.BlockWeaponRack; import com.mineworld.tileentity.decorations.TileEntityWeaponRack; import net.minecraft.block.properties.PropertyDirection; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.GlStateManager; import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer; import net.minecraft.entity.item.EntityItem; import net.minecraft.item.ItemStack; import net.minecraft.util.EnumFacing.Axis; public class TileEntityWeaponRackRenderer extends TileEntitySpecialRenderer<TileEntityWeaponRack> { EntityItem ITEM1 = new EntityItem(Minecraft.getMinecraft().theWorld, 0, 0, 0); @Override public void renderTileEntityAt(TileEntityWeaponRack te, double x, double y, double z, float partialTicks, int destroyStage) { super.renderTileEntityAt(te, x, y, z, partialTicks, destroyStage); Axis ax = Axis.X; PropertyDirection dir = (PropertyDirection) te.getBlockType().getBlockState() .getProperty(BlockWeaponRack.FACING.getName()); if (dir != null) { ax = te.getWorld().getBlockState(te.getPos()).getValue(dir).getAxis(); } if (te.render) { GlStateManager.pushMatrix(); GlStateManager.translate(x, y, z); if (ax == Axis.Z) { GlStateManager.rotate(135F, 0, 0, 1); GlStateManager.translate(0, 0, 0.5); GlStateManager.translate(-0.1, 0, 0); GlStateManager.translate(0, -1.2, 0); GlStateManager.translate(0.2, -0.1, 0.1); } else { GlStateManager.rotate(135F, 0, 1, 0); GlStateManager.rotate(135F, 0, 0, 1); GlStateManager.rotate(60F, 0, 1, 0); GlStateManager.translate(0.5, 0, 0); GlStateManager.translate(0.05, -0.5, 0.75); } ITEM1.setEntityItemStack(new ItemStack(te.item)); Minecraft.getMinecraft().getRenderManager().doRenderEntity(ITEM1, 0, 0, 0, 0F, 0F, false); GlStateManager.popMatrix(); } } } And this is how it looks right now
  19. Just look at the Vanilla Sapling Class and a Tree Class (Like the Oak Tree class). Change them to your needs and that's it
  20. Yes i know, just a bit tired and didn't understand that i would check if the block is NOT "this"
  21. I've done this in my class @Override public boolean shouldSideBeRendered(IBlockState blockState, IBlockAccess blockAccess, BlockPos pos, EnumFacing side) { return blockAccess.getBlockState(pos.offset(side)).getBlock() == this ? false : super.shouldSideBeRendered(blockState, blockAccess, pos, side); } But nothing changed EDIT: dumb me, if i just return true it works Thank you so much for your help
  22. I'm making a cherry tree, but the leaves are rendering too transparents. Right now they render like this what i want is that they render like vanilla leaves, like this This is the class i'm using for the leaves package com.mineworld.blocks.decorations; import java.util.List; import java.util.Random; import com.mineworld.blocks.plants.BlockPlanksMW; import com.mineworld.core.MWBlocks; import com.mineworld.core.MWItems; import com.mineworld.core.MWTabs; import net.minecraft.block.BlockLeaves; import net.minecraft.block.BlockPlanks.EnumType; import net.minecraft.block.SoundType; import net.minecraft.block.properties.IProperty; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; import net.minecraft.init.Blocks; import net.minecraft.init.Items; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; import net.minecraft.util.BlockRenderLayer; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; public class BlockFruitLeaves extends BlockLeaves { public BlockFruitLeaves() { this.setDefaultState(this.blockState.getBaseState().withProperty(CHECK_DECAY, Boolean.valueOf(true)) .withProperty(DECAYABLE, Boolean.valueOf(true))); this.setHardness(0.2F); this.setSoundType(SoundType.PLANT); this.setTickRandomly(true); this.setCreativeTab(MWTabs.tabDecorations); } public BlockRenderLayer getBlockLayer() { return Blocks.LEAVES.getBlockLayer(); } public Item getItemDropped(IBlockState state, Random rand, int fortune) { if (this == MWBlocks.cherry_leaves) return Item.getItemFromBlock(MWBlocks.sapling_cherry); else if (this == MWBlocks.orange_leaves) return Item.getItemFromBlock(MWBlocks.sapling_orange); else return Item.getItemFromBlock(MWBlocks.sapling_lemon); } protected void dropApple(World worldIn, BlockPos pos, IBlockState state, int chance) { if (this.RANDOM.nextInt(5) == 3) { if (this == MWBlocks.cherry_leaves) spawnAsEntity(worldIn, pos, new ItemStack(MWItems.cherry, 1, 0)); else if (this == MWBlocks.orange_leaves) spawnAsEntity(worldIn, pos, new ItemStack(MWItems.orange, 1, 0)); else spawnAsEntity(worldIn, pos, new ItemStack(MWItems.lemon, 1, 0)); } } @Override public boolean isOpaqueCube(IBlockState state) { return false; } protected int getSaplingDropChance(IBlockState state) { return super.getSaplingDropChance(state); } public IBlockState getStateFromMeta(int meta) { return this.getDefaultState().withProperty(DECAYABLE, Boolean.valueOf((meta & 4) == 0)) .withProperty(CHECK_DECAY, Boolean.valueOf((meta & > 0)); } public int getMetaFromState(IBlockState state) { byte b0 = 0; int i = b0; if (!((Boolean) state.getValue(DECAYABLE)).booleanValue()) { i |= 4; } if (((Boolean) state.getValue(CHECK_DECAY)).booleanValue()) { i |= 8; } return i; } protected BlockStateContainer createBlockState() { return new BlockStateContainer(this, new IProperty[] { CHECK_DECAY, DECAYABLE }); } @Override public List<ItemStack> onSheared(ItemStack item, IBlockAccess world, BlockPos pos, int fortune) { IBlockState state = world.getBlockState(pos); return new java.util.ArrayList(java.util.Arrays.asList(new ItemStack(this, 1, 0).getMetadata())); } @Override public EnumType getWoodType(int meta) { return null; } } What should i change to make them rendering correctly?
  23. I've actually managed to do this, but i guess i'llchange it to check the corners boolean flag = true; HashMap<BlockPos, Integer> nograss = new HashMap<BlockPos, Integer>(); for (int i = 0; i < template.getSize().getX(); i++) { for (int j = 0; j < template.getSize().getZ(); j++) { BlockPos down = pos.add(i, -1, j); Block b = world.getBlockState(down).getBlock(); if (!b.equals(Blocks.GRASS)) { nograss.put(down, 0); } } } if (!nograss.isEmpty()) { for(Entry<BlockPos, Integer> entry : nograss.entrySet()) { BlockPos top = world.getTopSolidOrLiquidBlock(entry.getKey()); if(Math.abs(top.getY() - entry.getKey().getY()) > 3) { flag = false; break; } else entry.setValue(Math.abs(top.getY() - entry.getKey().getY())); } if(flag) { for(Entry<BlockPos, Integer> entry : nograss.entrySet()) { for(int i = 0; i < entry.getValue()+1; i++) { world.setBlockState(entry.getKey().down(i), Blocks.COBBLESTONE.getDefaultState()); } } } } if (flag) { //do stuff } So what i do is: check all the blocks, if there are some blocks that don't have grass under them then add it's position to an HashMap. Then, if this HashMap is not empty check if the location of the structure (the blocks that made the base and are in the HashMap) are at most 3 blocks up from the ground. If there is at least one that is up more than 3 blocks then the structure will not generate. Else, every block that has not grass underneath is at most 3 blocks up from the ground, so place 3 blocks of cobblestone down to the ground, so it will looks like the structure has some layers of cobblestone and then the structure itself (mostly like villages sometimes generates)
  24. Not actually a problem, i need a help to figure out how to generate common structures in forests that fits with the forest itself. So the structure is actually generated on the solid ground, not in water, not in air. Right now to do this i got this check in the function that loads my structure flag = true; if(check) { for (int i = 0; i < 16; i++) { for (int j = 0; j < 16; j++) { if (!world.getBlockState(pos.add(i, -1, j)).getBlock().equals(Blocks.GRASS)) { flag = false; break; } } } } if (flag) { //place the structure} So here i'm saying that if an area of 16x16 blocks in the forest is made of grass than spawn the structure. But, as you might guess, in the forest is really hard to have flat plains area, and this results in the structure being pretty rare. So how can i do to make the structure generate in a proper way BUT let it not be too rare?
  25. Thanks for your answer, that solved the glitch
×
×
  • Create New...

Important Information

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