Jump to content

someRandomKid

Members
  • Posts

    44
  • Joined

  • Last visited

Everything posted by someRandomKid

  1. SOLVED: instead of using this.movedDistance I used this.distanceWalkedModified and it works fine.
  2. so after taking a break from modding (sorry for not responding!) I finally figured out the problem. The problem is that this.movedDistance doesn't get updated on the server, but is getting updated on client. How would I fix that? EDIT: The data manager can't get the correct value to sync because this.movedDistance only gets updated on client. So I think I have to make a packet for this to all work.
  3. I guess that's fine, I was planning on making this mod open-source anyway
  4. So then how do I fix it? So far I have fixed the tick function.
  5. updated code: package com.new_swords.Entities; import net.minecraft.block.BlockState; import net.minecraft.client.Minecraft; import net.minecraft.client.world.ClientWorld; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; import net.minecraft.entity.SharedMonsterAttributes; import net.minecraft.entity.passive.horse.AbstractChestedHorseEntity; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; import net.minecraft.nbt.CompoundNBT; import net.minecraft.network.datasync.DataParameter; import net.minecraft.network.datasync.DataSerializers; import net.minecraft.network.datasync.EntityDataManager; import net.minecraft.particles.ParticleTypes; import net.minecraft.util.DamageSource; import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; public class Car extends AbstractChestedHorseEntity { public boolean outofgas; private boolean particle_reducer; public static final DataParameter<Float> Fuel = EntityDataManager.createKey(Car.class, DataSerializers.FLOAT); public Car(EntityType<? extends Car> type, World worldIn) { super(type, worldIn); this.outofgas = false; this.particle_reducer = false; } //forgot to do super.registerAttributes() [Sorry] @Override protected void registerAttributes() { this.getAttributes().registerAttribute(SharedMonsterAttributes.MAX_HEALTH); this.getAttributes().registerAttribute(SharedMonsterAttributes.MOVEMENT_SPEED); this.getAttributes().registerAttribute(SharedMonsterAttributes.FOLLOW_RANGE); this.getAttributes().registerAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE); this.getAttributes().registerAttribute(SharedMonsterAttributes.ARMOR); this.getAttributes().registerAttribute(LivingEntity.SWIM_SPEED); this.getAttributes().registerAttribute(LivingEntity.ENTITY_GRAVITY); this.getAttributes().registerAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS); this.getAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(1.0F); this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.4F); this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(40.0F); this.getAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(0.0F); this.getAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(2.0F); this.getAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS).setBaseValue(2.0F); this.getAttribute(LivingEntity.SWIM_SPEED).setBaseValue(0.05F); } @Override protected void registerData() { super.registerData(); this.dataManager.register(Fuel, this.movedDistance); } @Override protected void registerGoals() { } @Override public boolean canBeLeashedTo(PlayerEntity player) { return false; } @Override public void readAdditional(@NotNull CompoundNBT compound) { super.readAdditional(compound); this.setFuelValue(compound.getFloat("movedDistance")); } @Override public void writeAdditional(@NotNull CompoundNBT compound) { super.writeAdditional(compound); compound.putFloat("movedDistance", this.movedDistance); } @Override public void tick() { super.tick(); outofgas = this.movedDistance > 2000; this.particle_reducer = !this.particle_reducer; World world = this.getEntityWorld(); Vec3d vec = new Vec3d(this.getPosX(),this.getPosY(), this.getPosZ()); Vec3d speedvec = new Vec3d(-0.3d, 0.2d, 0d); vec.add(this.getLookVec()); this.getDataManager().set(Fuel, this.movedDistance); if(!this.outofgas && this.particle_reducer) world.addParticle(ParticleTypes.SQUID_INK, vec.x, vec.y, vec.z, speedvec.x, speedvec.y, speedvec.z); // this.setHealth(this.getDataManager().get(Car.health)); } public void Refuel(){ this.distanceWalkedModified = 0; this.distanceWalkedOnStepModified = 0; this.prevDistanceWalkedModified = 0; this.prevMovedDistance = 0; this.movedDistance = 0; LOGGER.info("REFUELED"); } public void setFuelValue(float value){ this.distanceWalkedModified = value; this.distanceWalkedOnStepModified = value; this.prevDistanceWalkedModified = value; this.prevMovedDistance = value; this.movedDistance = value; } @Override protected boolean canMate() { return false; } @Override public boolean canBreed() { return false; } @Nullable @Override protected SoundEvent getDeathSound() { return null; } @Nullable @Override protected SoundEvent getAmbientSound() { return null; } @Nullable @Override protected SoundEvent getHurtSound(DamageSource damageSourceIn) { return null; } @Override protected void playStepSound(BlockPos pos, BlockState blockIn) { // this.playSound(ModSoundEvents.MOVING_CAR, 0.5F, 1.0F); } @Override public void setMoveStrafing(float amount) {} @Override public boolean hasChest() { return true; } @Override public boolean isTame() { return true; } @Override public boolean canEatGrass() { return false; } @Override public boolean isHorseSaddled() { return !this.outofgas; } @Override public boolean canBeSteered() { return !this.outofgas; } @Override public boolean isBreedingItem(@NotNull ItemStack stack) { return false; } @Override public boolean wearsArmor() { return false; } @Override public boolean canDespawn(double distanceToClosestPlayer) { return false; } @Override public boolean canJump() { return false; } @Override public boolean canBeRiddenInWater() { return false; } @Override public boolean canBePushed() { return false; } @Override public boolean canBeSaddled() { return false; } @Override protected int getInventorySize() { return 29; } @Override public int getInventoryColumns() { return 9; } }
  6. I am syncing them in the tick function. It still is not working.
  7. oh wait I just realized how dumb I was this is what it should be: this.dataManager.register(Fuel, this.movedDistance);
  8. //updated code public class Car extends AbstractChestedHorseEntity { public boolean outofgas; private boolean particle_reducer; public static final DataParameter<Float> Fuel = EntityDataManager.createKey(Car.class, DataSerializers.FLOAT); public Car(EntityType<? extends Car> type, World worldIn) { super(type, worldIn); this.outofgas = false; this.particle_reducer = false; } //forgot to do super.registerAttributes() [Sorry] @Override protected void registerAttributes() { this.getAttributes().registerAttribute(SharedMonsterAttributes.MAX_HEALTH); this.getAttributes().registerAttribute(SharedMonsterAttributes.MOVEMENT_SPEED); this.getAttributes().registerAttribute(SharedMonsterAttributes.FOLLOW_RANGE); this.getAttributes().registerAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE); this.getAttributes().registerAttribute(SharedMonsterAttributes.ARMOR); this.getAttributes().registerAttribute(LivingEntity.SWIM_SPEED); this.getAttributes().registerAttribute(LivingEntity.ENTITY_GRAVITY); this.getAttributes().registerAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS); this.getAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(1.0F); this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.4F); this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(40.0F); this.getAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(0.0F); this.getAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(2.0F); this.getAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS).setBaseValue(2.0F); this.getAttribute(LivingEntity.SWIM_SPEED).setBaseValue(0.05F); } @Override protected void registerData() { super.registerData(); this.dataManager.register(Fuel, 0.0F); } @Override protected void registerGoals() { } @Override public boolean canBeLeashedTo(PlayerEntity player) { return false; } @Override public void readAdditional(@NotNull CompoundNBT compound) { super.readAdditional(compound); this.setFuelValue(compound.getFloat("movedDistance")); } @Override public void writeAdditional(@NotNull CompoundNBT compound) { super.writeAdditional(compound); compound.putFloat("movedDistance", this.movedDistance); } @Override public void tick() { super.tick(); outofgas = this.movedDistance > 2000; this.particle_reducer = !this.particle_reducer; ClientWorld world = Minecraft.getInstance().world; Vec3d vec = new Vec3d(this.getPosX(),this.getPosY(), this.getPosZ()); Vec3d speedvec = new Vec3d(-0.3d, 0.2d, 0d); vec.add(this.getLookVec()); this.getDataManager().set(Fuel, this.movedDistance); if(world != null && !this.outofgas && this.particle_reducer) world.addParticle(ParticleTypes.SQUID_INK, vec.x, vec.y, vec.z, speedvec.x, speedvec.y, speedvec.z); // this.setHealth(this.getDataManager().get(Car.health)); } public void Refuel(){ this.distanceWalkedModified = 0; this.distanceWalkedOnStepModified = 0; this.prevDistanceWalkedModified = 0; this.prevMovedDistance = 0; this.movedDistance = 0; LOGGER.info("REFUELED"); } public void setFuelValue(float value){ this.distanceWalkedModified = value; this.distanceWalkedOnStepModified = value; this.prevDistanceWalkedModified = value; this.prevMovedDistance = value; this.movedDistance = value; } @Override protected boolean canMate() { return false; } @Override public boolean canBreed() { return false; } @Nullable @Override protected SoundEvent getDeathSound() { return null; } @Nullable @Override protected SoundEvent getAmbientSound() { return null; } @Nullable @Override protected SoundEvent getHurtSound(DamageSource damageSourceIn) { return null; } @Override protected void playStepSound(BlockPos pos, BlockState blockIn) { // this.playSound(ModSoundEvents.MOVING_CAR, 0.5F, 1.0F); } @Override public void setMoveStrafing(float amount) {} @Override public boolean hasChest() { return true; } @Override public boolean isTame() { return true; } @Override public boolean canEatGrass() { return false; } @Override public boolean isHorseSaddled() { return !this.outofgas; } @Override public boolean canBeSteered() { return !this.outofgas; } @Override public boolean isBreedingItem(@NotNull ItemStack stack) { return false; } @Override public boolean wearsArmor() { return false; } @Override public boolean canDespawn(double distanceToClosestPlayer) { return false; } @Override public boolean canJump() { return false; } @Override public boolean canBeRiddenInWater() { return false; } @Override public boolean canBePushed() { return false; } @Override public boolean canBeSaddled() { return false; } @Override protected int getInventorySize() { return 29; } @Override public int getInventoryColumns() { return 9; } }
  9. what do you mean by that? that text is always rendering no matter if the horse gui is opened or not.
  10. are you sure about that, because its just text: @SubscribeEvent public void onRenderGui(RenderGameOverlayEvent.Post event){ Minecraft minecraft = Minecraft.getInstance(); if (event.isCancelable() || event.getType() != RenderGameOverlayEvent.ElementType.EXPERIENCE) { return; } FontRenderer font = minecraft.fontRenderer; PlayerEntity player = minecraft.player; if(player == null) return; LivingEntity RidingEntity = (LivingEntity)player.getRidingEntity(); if(RidingEntity != null) { if (RidingEntity instanceof Car) { Car car = (Car) RidingEntity; ChatFormatting chat = (car.getMovedDistance() > 1500) ? ChatFormatting.RED : ChatFormatting.GREEN; font.drawStringWithShadow(chat + "Fuel:" + (2000-car.getMovedDistance())/20 + "%", 5, 5, 0); } } Entity entity = minecraft.pointedEntity; if(entity instanceof PlaceholderEntity){ ChatFormatting chat = ChatFormatting.GREEN; font.drawStringWithShadow(chat+"Entity ID:"+entity.getEntityId(), 5,5, 0); } }
  11. public class Car extends AbstractChestedHorseEntity { public boolean outofgas; private boolean particle_reducer; // public static final DataParameter<Float> health = EntityDataManager.createKey(Car.class, DataSerializers.FLOAT); public Car(EntityType<? extends Car> type, World worldIn) { super(type, worldIn); this.outofgas = false; this.particle_reducer = false; } //forgot to do super.registerAttributes() [Sorry] @Override protected void registerAttributes() { this.getAttributes().registerAttribute(SharedMonsterAttributes.MAX_HEALTH); this.getAttributes().registerAttribute(SharedMonsterAttributes.MOVEMENT_SPEED); this.getAttributes().registerAttribute(SharedMonsterAttributes.FOLLOW_RANGE); this.getAttributes().registerAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE); this.getAttributes().registerAttribute(SharedMonsterAttributes.ARMOR); this.getAttributes().registerAttribute(LivingEntity.SWIM_SPEED); this.getAttributes().registerAttribute(LivingEntity.ENTITY_GRAVITY); this.getAttributes().registerAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS); this.getAttribute(SharedMonsterAttributes.KNOCKBACK_RESISTANCE).setBaseValue(1.0F); this.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED).setBaseValue(0.4F); this.getAttribute(SharedMonsterAttributes.MAX_HEALTH).setBaseValue(40.0F); this.getAttribute(SharedMonsterAttributes.FOLLOW_RANGE).setBaseValue(0.0F); this.getAttribute(SharedMonsterAttributes.ARMOR).setBaseValue(2.0F); this.getAttribute(SharedMonsterAttributes.ARMOR_TOUGHNESS).setBaseValue(2.0F); this.getAttribute(LivingEntity.SWIM_SPEED).setBaseValue(0.05F); } @Override protected void registerData() { super.registerData(); // this.dataManager.register(health, 20.0F); } @Override protected void registerGoals() { } @Override public boolean canBeLeashedTo(PlayerEntity player) { return false; } @Override public void readAdditional(@NotNull CompoundNBT compound) { super.readAdditional(compound); this.setFuelValue(compound.getFloat("movedDistance")); } @Override public void writeAdditional(@NotNull CompoundNBT compound) { super.writeAdditional(compound); compound.putFloat("movedDistance", this.movedDistance); } @Override public void tick() { super.tick(); outofgas = this.movedDistance > 2000; this.particle_reducer = !this.particle_reducer; ClientWorld world = Minecraft.getInstance().world; Vec3d vec = new Vec3d(this.getPosX(),this.getPosY(), this.getPosZ()); Vec3d speedvec = new Vec3d(-0.3d, 0.2d, 0d); vec.add(this.getLookVec()); if(world != null && !this.outofgas && this.particle_reducer) world.addParticle(ParticleTypes.SQUID_INK, vec.x, vec.y, vec.z, speedvec.x, speedvec.y, speedvec.z); // this.setHealth(this.getDataManager().get(Car.health)); } public float getMovedDistance(){ return this.movedDistance; } public void Refuel(){ this.distanceWalkedModified = 0; this.distanceWalkedOnStepModified = 0; this.prevDistanceWalkedModified = 0; this.prevMovedDistance = 0; this.movedDistance = 0; LOGGER.info("REFUELED"); } public void setFuelValue(float value){ this.distanceWalkedModified = value; this.distanceWalkedOnStepModified = value; this.prevDistanceWalkedModified = value; this.prevMovedDistance = value; this.movedDistance = value; } @Override protected boolean canMate() { return false; } @Override public boolean canBreed() { return false; } @Nullable @Override protected SoundEvent getDeathSound() { return null; } @Nullable @Override protected SoundEvent getAmbientSound() { return null; } @Nullable @Override protected SoundEvent getHurtSound(DamageSource damageSourceIn) { return null; } @Override protected void playStepSound(BlockPos pos, BlockState blockIn) { // this.playSound(ModSoundEvents.MOVING_CAR, 0.5F, 1.0F); } @Override public void setMoveStrafing(float amount) {} @Override public boolean hasChest() { return true; } @Override public boolean isTame() { return true; } @Override public boolean canEatGrass() { return false; } @Override public boolean isHorseSaddled() { return !this.outofgas; } @Override public boolean canBeSteered() { return !this.outofgas; } @Override public boolean isBreedingItem(@NotNull ItemStack stack) { return false; } @Override public boolean wearsArmor() { return false; } @Override public boolean canDespawn(double distanceToClosestPlayer) { return false; } @Override public boolean canJump() { return false; } @Override public boolean canBeRiddenInWater() { return false; } @Override public boolean canBePushed() { return false; } @Override public boolean canBeSaddled() { return false; } @Override protected int getInventorySize() { return 29; } @Override public int getInventoryColumns() { return 9; } }
  12. I have already done that and it seems to do nothing
  13. How would I make an entity save a float value? I have looked into capabilities, but they seem a little to complicated to save a single float.
  14. Works now, but since my fuse is 40 longer than the vanilla fuse, my tnt disappears too early.
  15. public class MegaTNTEntity extends Entity { private static final DataParameter<Integer> FUSE = EntityDataManager.createKey(MegaTNTEntity.class, DataSerializers.VARINT); @Nullable private LivingEntity tntPlacedBy; private int fuse; public MegaTNTEntity(EntityType<? extends MegaTNTEntity> type, World worldIn) { super(type, worldIn); } public MegaTNTEntity(World worldIn, double x, double y, double z, @Nullable LivingEntity igniter) { this(RegistryHandler.MEGA_TNT_ENTITY.get(),worldIn); this.setPosition(x, y, z); double d0 = worldIn.rand.nextDouble() * (double)((float)Math.PI * 2F); this.setMotion(-Math.sin(d0) * 0.02D, 0.2D, -Math.cos(d0) * 0.02D); this.prevPosX = x; this.prevPosY = y; this.prevPosZ = z; this.fuse = 120; this.tntPlacedBy = igniter; } @Nullable public LivingEntity getTntPlacedBy() { return this.tntPlacedBy; } public void setFuse(int fuse) { this.fuse = fuse; } public boolean canBeCollidedWith() { return false; } @Override protected void registerData() { this.dataManager.register(FUSE, 80); } @Override public void writeAdditional(CompoundNBT compound) { compound.putShort("Fuse", (short)this.getFuse()); } /** * (abstract) Protected helper method to read subclass entity data from NBT. */ @Override public void readAdditional(CompoundNBT compound) { this.setFuse(compound.getShort("Fuse")); } @Override public void tick() { //new_swords.LOGGER.info(this.fuse); //new_swords.LOGGER.info(this.getPosX() + "," + this.getPosY() + "," + this.getPosZ()); //new_swords.LOGGER.info("on ground? " + this.onGround); if (!this.hasNoGravity()) { this.setMotion(this.getMotion().add(0.0D, -0.04D, 0.0D)); } this.move(MoverType.SELF, this.getMotion()); this.setMotion(this.getMotion().scale(0.98D)); if (this.onGround) { this.setMotion(this.getMotion().mul(0.7D, -0.5D, 0.7D)); } --this.fuse; if (this.fuse <= 0) { this.remove(); if (!this.world.isRemote) { this.explode(); } } else { this.handleWaterMovement(); if (this.world.isRemote) { this.world.addParticle(ParticleTypes.SMOKE, this.getPosX(), this.getPosY() + 0.5D, this.getPosZ(), 0.0D, 0.0D, 0.0D); } } } protected void explode() { float f = 20.0f; new_swords.LOGGER.info("exploding?"); MinecraftServer server = this.getServer(); if(server == null) return; ServerWorld world = server.getWorld(this.dimension); world.createExplosion(this, this.getPosX(), this.getPosYHeight(0.0625D), this.getPosZ(), f, Explosion.Mode.BREAK); } public int getFuse() { return this.fuse; } public void notifyDataManagerChange(DataParameter<?> key) { if (FUSE.equals(key)) { this.fuse = this.getFuseDataManager(); } } /** * Gets the fuse from the data manager */ public int getFuseDataManager() { return this.dataManager.get(FUSE); } public @NotNull IPacket<?> createSpawnPacket() { return new SSpawnObjectPacket(this); } }
×
×
  • Create New...

Important Information

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