Jump to content

[1.8] My flag (entity) rendering issue. Need help please


SteveKunG

Recommended Posts

a6a7312a0b.png

 

Here is my code :

Entity

 

package stevekung.mods.moreplanets.common.entities;

 

import net.minecraft.block.Block;

import net.minecraft.block.BlockFence;

import net.minecraft.entity.Entity;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.ItemStack;

import net.minecraft.nbt.NBTTagCompound;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.util.BlockPos;

import net.minecraft.util.DamageSource;

import net.minecraft.util.MovingObjectPosition;

import net.minecraft.world.World;

import stevekung.mods.moreplanets.core.init.MPItems;

 

public class EntityFlagMP extends Entity

{

public boolean indestructable = false;

 

public EntityFlagMP(World world)

{

super(world);

this.setSize(0.4F, 3F);

this.ignoreFrustumCheck = true;

this.preventEntitySpawning = true;

}

 

public EntityFlagMP(World par1World, double x, double y, double z, int facing)

{

this(par1World);

this.setFacingAngle(facing);

this.setPosition(x, y, z);

}

 

@Override

public double getYOffset()

{

return 1.5D;

}

 

@Override

public boolean attackEntityFrom(DamageSource damageSource, float amount)

{

if (!this.worldObj.isRemote && !this.isDead && !this.indestructable)

{

boolean flag = damageSource.getEntity() instanceof EntityPlayer && ((EntityPlayer)damageSource.getEntity()).capabilities.isCreativeMode;

 

if (this.isEntityInvulnerable(damageSource))

{

return false;

}

 

this.setBeenAttacked();

this.setDamage(this.getDamage() + amount * 10.0F);

 

if (flag || this.getDamage() > 40.0F)

{

if (this.riddenByEntity != null)

{

this.riddenByEntity.mountEntity(this);

}

if (flag)

{

this.setDead();

}

else

{

this.setDead();

this.entityDropItem(new ItemStack(MPItems.flag, 1, this.getType()), 0.0F);

}

}

return true;

}

return true;

}

 

@Override

public ItemStack getPickedResult(MovingObjectPosition moving)

{

return new ItemStack(MPItems.flag, 1, this.getType());

}

 

@Override

public boolean canBeCollidedWith()

{

return true;

}

 

@Override

protected boolean canTriggerWalking()

{

return false;

}

 

@Override

public AxisAlignedBB getCollisionBox(Entity entity)

{

return this.getEntityBoundingBox();

}

 

@Override

public AxisAlignedBB getBoundingBox()

{

return this.getEntityBoundingBox();

}

 

@Override

public boolean canBePushed()

{

return false;

}

 

@Override

protected void entityInit()

{

this.dataWatcher.addObject(17, new Float(0.0F));

this.dataWatcher.addObject(18, new Integer(-1));

this.dataWatcher.addObject(19, new Integer(-1));

}

 

@Override

public void readEntityFromNBT(NBTTagCompound nbt)

{

this.setType(nbt.getInteger("Type"));

this.indestructable = nbt.getBoolean("Indestructable");

this.setFacingAngle(nbt.getInteger("AngleI"));

}

 

@Override

protected void writeEntityToNBT(NBTTagCompound nbt)

{

nbt.setInteger("Type", Integer.valueOf(this.getType()));

nbt.setBoolean("Indestructable", this.indestructable);

nbt.setInteger("AngleI", this.getFacingAngle());

}

 

@Override

public void onUpdate()

{

super.onUpdate();

BlockPos pos = this.getPosition().down();

Block block = this.worldObj.getBlockState(pos).getBlock();

 

if (block != null)

{

if (block instanceof BlockFence)

{

}

else if (block.isAir(this.worldObj, pos))

{

this.motionY -= 0.02F;

}

}

this.moveEntity(this.motionX, this.motionY, this.motionZ);

}

 

@Override

public boolean interactFirst(EntityPlayer player)

{

if (!this.worldObj.isRemote)

{

this.setFacingAngle(this.getFacingAngle() + 3);

}

return true;

}

 

public void setDamage(float par1)

{

this.dataWatcher.updateObject(17, Float.valueOf(par1));

}

 

public float getDamage()

{

return this.dataWatcher.getWatchableObjectFloat(17);

}

 

public void setType(int type)

{

this.dataWatcher.updateObject(18, Integer.valueOf(type));

}

 

public int getType()

{

return this.dataWatcher.getWatchableObjectInt(18);

}

 

public void setFacingAngle(int facing)

{

this.dataWatcher.updateObject(19, Integer.valueOf(facing));

}

 

public int getFacingAngle()

{

return this.dataWatcher.getWatchableObjectInt(19);

}

}

 

 

Item

 

package stevekung.mods.moreplanets.common.items;

 

import java.util.Calendar;

import java.util.List;

 

import net.minecraft.creativetab.CreativeTabs;

import net.minecraft.entity.player.EntityPlayer;

import net.minecraft.item.EnumAction;

import net.minecraft.item.Item;

import net.minecraft.item.ItemStack;

import net.minecraft.util.AxisAlignedBB;

import net.minecraft.util.ChatComponentText;

import net.minecraft.util.MovingObjectPosition;

import net.minecraft.util.MovingObjectPosition.MovingObjectType;

import net.minecraft.util.StatCollector;

import net.minecraft.world.World;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

import stevekung.mods.moreplanets.common.config.ConfigManagerMP;

import stevekung.mods.moreplanets.common.entities.EntityFlagMP;

import stevekung.mods.moreplanets.core.MorePlanetsCore;

 

public class ItemFlagMP extends ItemBaseMP /*implements IHoldableItem*/

{

private Calendar calendar = Calendar.getInstance();

 

public ItemFlagMP(String name)

{

super();

this.setMaxStackSize(1);

this.setUnlocalizedName(name);

 

if (this.calendar.get(2) + 1 >= 1 && this.calendar.get(5) >= 1)

{

this.setHasSubtypes(true);

}

else

{

this.setHasSubtypes(false);

}

}

 

@Override

public CreativeTabs getCreativeTab()

{

if (!ConfigManagerMP.enableThaiFlagAndCanvas)

{

return null;

}

else

{

return MorePlanetsCore.mpItemsTab;

}

}

 

@Override

@SideOnly(Side.CLIENT)

public void getSubItems(Item item, CreativeTabs creativeTabs, List list)

{

if (this.calendar.get(2) + 1 >= 1 && this.calendar.get(5) >= 1)

{

for (int i = 0; i < this.getItemVariantsName().length; i++)

{

list.add(new ItemStack(this, 1, i));

}

}

else

{

for (int i = 0; i < 1; i++)

{

list.add(new ItemStack(this, 1, i));

}

}

}

 

@Override

public void onPlayerStoppedUsing(ItemStack itemStack, World world, EntityPlayer player, int tick)

{

int useTime = this.getMaxItemUseDuration(itemStack) - tick;

boolean placed = false;

MovingObjectPosition moving = this.getMovingObjectPositionFromPlayer(world, player, true);

float usingTime = useTime / 20.0F;

 

usingTime = (usingTime * usingTime + usingTime * 2.0F) / 3.0F;

 

if (usingTime > 1.0F)

{

usingTime = 1.0F;

}

 

if (usingTime == 1.0F && moving != null && moving.typeOfHit == MovingObjectType.BLOCK)

{

int x = moving.getBlockPos().getX();

int y = moving.getBlockPos().getY();

int z = moving.getBlockPos().getZ();

 

if (!world.isRemote)

{

EntityFlagMP flag = new EntityFlagMP(world, x + 0.5F, y + 1.0F, z + 0.5F, (int) (player.rotationYaw - 90));

 

if (world.getEntitiesWithinAABB(EntityFlagMP.class, AxisAlignedBB.fromBounds(x, y, z, x + 1, y + 3, z + 1)).isEmpty())

{

world.spawnEntityInWorld(flag);

flag.setType(itemStack.getItemDamage());

placed = true;

}

else

{

player.addChatMessage(new ChatComponentText(StatCollector.translateToLocal("gui.flag.alreadyPlaced")));

}

}

 

if (placed)

{

int i = this.getInventorySlotContainItem(player, itemStack);

 

if (i >= 0 && !player.capabilities.isCreativeMode)

{

if (--player.inventory.mainInventory.stackSize <= 0)

{

player.inventory.mainInventory = null;

}

}

}

}

}

 

private int getInventorySlotContainItem(EntityPlayer player, ItemStack itemStack)

{

for (int i = 0; i < player.inventory.mainInventory.length; ++i)

{

if (player.inventory.mainInventory != null && player.inventory.mainInventory.isItemEqual(itemStack))

{

return i;

}

}

return -1;

}

 

@Override

public int getMaxItemUseDuration(ItemStack itemStack)

{

return 72000;

}

 

@Override

public EnumAction getItemUseAction(ItemStack itemStack)

{

return EnumAction.NONE;

}

 

@Override

public ItemStack onItemRightClick(ItemStack itemStack, World world, EntityPlayer player)

{

player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));

return itemStack;

}

 

/*@Override

public boolean shouldHoldLeftHandUp(EntityPlayer player)

{

return false;

}

 

@Override

public boolean shouldHoldRightHandUp(EntityPlayer player)

{

return true;

}

 

@Override

public boolean shouldCrouch(EntityPlayer player)

{

return false;

}*/

 

@Override

public String[] getItemVariantsName()

{

return new String[] { "thai", "laos", "singapore", "myanmar", "marlaysia", "vietnam", "indonesia", "philippines", "cambodia", "brunei" };

}

}

 

 

Render

 

package stevekung.mods.moreplanets.client.render.entities;

 

import net.minecraft.client.renderer.GlStateManager;

import net.minecraft.client.renderer.entity.Render;

import net.minecraft.client.renderer.entity.RenderManager;

import net.minecraft.entity.Entity;

import net.minecraft.util.ResourceLocation;

import net.minecraftforge.fml.relauncher.Side;

import net.minecraftforge.fml.relauncher.SideOnly;

import stevekung.mods.moreplanets.client.model.ModelFlagMP;

import stevekung.mods.moreplanets.common.entities.EntityFlagMP;

 

@SideOnly(Side.CLIENT)

public class RenderFlagMP extends Render

{

static ResourceLocation[] flagTexture;

static String[] flag = { "thai", "laos", "singapore", "myanmar", "marlaysia", "vietnam", "indonesia", "philippines", "cambodia", "brunei" };

private ModelFlagMP modelFlag;

 

static

{

flagTexture = new ResourceLocation[flag.length];

 

for (int i = 0; i < flag.length; i++)

{

RenderFlagMP.flagTexture = new ResourceLocation("moreplanets:textures/entity/flag/" + flag + ".png");

}

}

 

public RenderFlagMP(RenderManager render)

{

super(render);

this.shadowSize = 1F;

this.modelFlag = new ModelFlagMP();

}

 

@Override

protected ResourceLocation getEntityTexture(Entity entity)

{

if (((EntityFlagMP)entity).getType() == -1)

{

return null;

}

return RenderFlagMP.flagTexture[((EntityFlagMP)entity).getType()];

}

 

public void renderFlag(EntityFlagMP entity, double par2, double par4, double par6)

{

GlStateManager.pushMatrix();

long var10 = entity.getEntityId() * 493286711L;

var10 = var10 * var10 * 4392167121L + var10 * 98761L;

float var12 = (((var10 >> 16 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;

float var13 = (((var10 >> 20 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;

float var14 = (((var10 >> 24 & 7L) + 0.5F) / 8.0F - 0.5F) * 0.004F;

GlStateManager.translate(var12, var13, var14);

GlStateManager.translate((float) par2, (float) par4, (float) par6);

GlStateManager.rotate(180.0F - entity.getFacingAngle(), 0.0F, 1.0F, 0.0F);

this.bindEntityTexture(entity);

GlStateManager.scale(-1.0F, -1.0F, 1.0F);

this.modelFlag.render(entity, 0.0F, 0.0F, -0.1F, 0.0F, 0.0F, 0.0625F);

GlStateManager.popMatrix();

}

 

@Override

public void doRender(Entity entity, double par2, double par4, double par6, float par8, float par9)

{

this.renderFlag((EntityFlagMP)entity, par2, par4, par6);

}

}

 

Link to comment
Share on other sites

public EntityFlagMP(World world)
   {
      super(world);
      this.setSize(0.4F, 3F);
      this.ignoreFrustumCheck = true;
      this.preventEntitySpawning = true;
   }

 

When you set the size 1F = 1 Block (Or 16 Pixels), you are setting it to be 3 blocks tall, Do you want it to be 3 blocks tall or do you want the bounding box to be the correct size? If you want the flag to be taller you should go back to techne or whatever you used to make the model and edit the size, if you want the bounding box to be the right size change "3F" to "1F"

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • For the moment it seems fixed. I deleted the JEI Config file, the Journeymap Server Config file, and disabled both the mods (even while disabled, it would still crash until those config files were gone). They're useful mods and I'd hate to not use it, would just deleting and redownloading the mods work?
    • For hours I have been trying to just instal Mr. Crayfish's Refurbished Furniture Mod, but each step to fix the error codes, the more problems arise. The farthest I got through the steps was getting to the Forge Installer, but once I had selected the file, an error saying "The directory is missing a launcher profile. Please run the minecraft launcher first". At this point I don;'t know what more I can do. Please help.
    • I create my mod pack,yesterday my mod pack is fine but i add one mod and error. I'm delete this mmod but minecraft is still stop on CONFIG_LOAD then I tried to delete config and restart it but again. If you can pleace help me. https://imgur.com/ngZBzuv
    • game crashes before even opening (log:https://mclo.gs/M8xvX7c)
    • I have created a custom entity that extends "TamableAnimal", but I am wanting to have it spawn in the ocean. I have it spawning right now, but it spawns way too frequently even with weight set to 1. I am guessing it is because it is rolling in the spawn pool of land animals since TameableAnimal extends Animal and is different than WaterAnimal, and since no land animals spawn in the ocean it just fills every inch up with my custom entity. I have followed basic tutorials for spawning entities with Forge, but I feel like I am missing something about how to change what spawn pool this custom entity ends up in. Is it possible to change that or do I need to refactor it to be based off of WaterAnimal to get those spawn? My biome modifier JSON file: { "type": "forge:add_spawns", "biomes": "#minecraft:is_ocean", "spawners": { "type": "darwinsmysticalmounts:water_animal", "weight": 20, "minCount": 1, "maxCount": 1 } } My client event: event.register(ModEntityTypes.WATER_ANIMAL.get(), SpawnPlacements.Type.NO_RESTRICTIONS, Heightmap.Types.MOTION_BLOCKING_NO_LEAVES, WaterWyvernEntity::checkCustomWaterAnimalSpawnRules, SpawnPlacementRegisterEvent.Operation.REPLACE); And the actual custom spawn rule that makes it spawn in the water: public static boolean checkCustomWaterAnimalSpawnRules(EntityType<WaterAnimalEntity> pAnimal, LevelAccessor pLevel, MobSpawnType pSpawnType, BlockPos pPos, RandomSource pRandom) { return pPos.getY() > pLevel.getSeaLevel() - 16 && pLevel.getFluidState(pPos.below()).is(FluidTags.WATER); }  
  • Topics

×
×
  • Create New...

Important Information

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