Jump to content

JimiIT92

Members
  • Posts

    866
  • Joined

  • Last visited

  • Days Won

    3

Everything posted by JimiIT92

  1. 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
  2. I've already tried but not only the fish tries to spawn on ground, it doesn't move too
  3. 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); } } } }
  4. 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
  5. 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)
  6. 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
  7. 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"); } }
  8. 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?
  9. 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)
  10. 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
  11. 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
  12. 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); }
  13. 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)
  14. 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?
  15. @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
  16. @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
  17. 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
  18. 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
  19. Yes i know, just a bit tired and didn't understand that i would check if the block is NOT "this"
  20. 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
  21. 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?
  22. 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)
  23. 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?
  24. Thanks for your answer, that solved the glitch
  25. I've created a block using a custom model, to make it looks like is a Tombstone. But in some points the texture used is stretched and it looks awful This is the class file package com.mineworld.blocks.decorations; import com.mineworld.core.MWBlocks; import com.mineworld.core.MWTabs; import net.minecraft.block.Block; import net.minecraft.block.BlockHorizontal; import net.minecraft.block.SoundType; import net.minecraft.block.material.MapColor; 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.util.BlockRenderLayer; import net.minecraft.util.EnumFacing; import net.minecraft.util.Mirror; import net.minecraft.util.Rotation; import net.minecraft.util.math.BlockPos; import net.minecraft.world.IBlockAccess; import net.minecraft.world.World; import net.minecraftforge.common.IPlantable; public class BlockGrave extends BlockHorizontal{ public BlockGrave() { super(Material.ROCK, MapColor.STONE); this.setDefaultState(this.blockState.getBaseState().withProperty(FACING, EnumFacing.NORTH)); this.setHardness(0.5F); this.setCreativeTab(MWTabs.tabDecorations); this.setSoundType(SoundType.STONE); } /** * Used to determine ambient occlusion and culling when rebuilding chunks for render */ public boolean isOpaqueCube(IBlockState state) { return false; } public boolean isFullCube(IBlockState state) { return false; } @Override public BlockRenderLayer getBlockLayer() { return BlockRenderLayer.CUTOUT; } /** * Returns the blockstate with the given rotation from the passed blockstate. If inapplicable, returns the passed * blockstate. */ 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().getOpposite()); } /** * 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}); } } And this is the model file { "parent": "block/block", "textures": { "stone": "blocks/stone", "particle": "blocks/stone" }, "elements": [ { "from": [ 3, 0, 3 ], "to": [ 13, 1, 13 ], "faces": { "down": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "west": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "east": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"} } }, { "from": [ 5, 1, 5], "to": [ 11, 2, 11 ], "faces": { "down": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "west": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "east": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"} } }, { "from": [ 7, 2, 7], "to": [ 9, 15, 9 ], "faces": { "down": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "west": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "east": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"} } }, { "from": [ 4, 9, 7], "to": [ 7, 11, 9 ], "faces": { "down": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "west": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "east": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"} } } , { "from": [ 9, 9, 7], "to": [ 12, 11, 9 ], "faces": { "down": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "up": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "north": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "south": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "west": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"}, "east": { "uv": [ 0, 0, 16, 16 ], "texture": "#stone"} } } ] } How can i make the texture looks "normal" and not "stretched"?
×
×
  • Create New...

Important Information

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