Skip to content

Commit

Permalink
feat: clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
SiverDX authored and TheBv committed Dec 26, 2023
1 parent af22026 commit 4cdebd6
Show file tree
Hide file tree
Showing 11 changed files with 245 additions and 303 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,7 @@ public void playerDestroy(@NotNull Level worldIn, Player player, @NotNull BlockP
@Override
public void playerWillDestroy(Level worldIn, @NotNull BlockPos pos, @NotNull BlockState state, @NotNull Player player) {
if (worldIn.getBlockEntity(pos) != null) {
if (worldIn.getBlockEntity(pos) instanceof TileEntityEggInIce) {
TileEntityEggInIce tile = (TileEntityEggInIce) worldIn.getBlockEntity(pos);
if (worldIn.getBlockEntity(pos) instanceof TileEntityEggInIce tile) {
tile.spawnEgg();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.github.alexthe666.iceandfire.entity.EntityDragonEgg;
import com.github.alexthe666.iceandfire.entity.tile.TileEntityEggInIce;
import com.google.common.collect.ImmutableList;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.LivingEntity;

public class ModelDragonEgg<T extends LivingEntity> extends AdvancedEntityModel<T> {
Expand Down Expand Up @@ -53,15 +52,14 @@ public void setupAnim(LivingEntity entity, float f, float f1, float f2, float f3
this.resetToDefaultPose();
this.Egg1.setPos(0.0F, 19.6F, 0.0F);
this.Egg4.setPos(0.0F, -0.9F, 0.0F);
if (entity instanceof EntityDragonEgg) {
EntityDragonEgg dragon = (EntityDragonEgg) entity;
boolean flag = false;
if (dragon.getEggType().dragonType == DragonType.FIRE) {
flag = dragon.level().getBlockState(dragon.blockPosition()).isBurning(entity.level(), new BlockPos(entity.getBlockX(), entity.getBlockY(), entity.getBlockZ()));
} else if (dragon.getEggType().dragonType == DragonType.LIGHTNING) {
flag = dragon.level().isRainingAt(dragon.blockPosition());
if (entity instanceof EntityDragonEgg egg) {
boolean isLocationValid = false;
if (egg.getEggType().dragonType == DragonType.FIRE) {
isLocationValid = egg.level().getBlockState(egg.blockPosition()).isBurning(entity.level(), egg.blockPosition());
} else if (egg.getEggType().dragonType == DragonType.LIGHTNING) {
isLocationValid = egg.level().isRainingAt(egg.blockPosition());
}
if (flag) {
if (isLocationValid) {
this.walk(Egg1, 0.3F, 0.3F, true, 1, 0, f2, 1);
this.flap(Egg1, 0.3F, 0.3F, false, 0, 0, f2, 1);
}
Expand Down
113 changes: 10 additions & 103 deletions src/main/java/com/github/alexthe666/iceandfire/entity/DragonType.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,8 @@
package com.github.alexthe666.iceandfire.entity;

import com.github.alexthe666.iceandfire.IafConfig;
import com.github.alexthe666.iceandfire.block.BlockEggInIce;
import com.github.alexthe666.iceandfire.block.IafBlockRegistry;
import com.github.alexthe666.iceandfire.entity.tile.TileEntityEggInIce;
import com.github.alexthe666.iceandfire.misc.IafSoundRegistry;
import net.minecraft.core.BlockPos;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LightningBolt;
import net.minecraft.world.level.block.Blocks;
import org.jetbrains.annotations.Nullable;

public class DragonType {

public static final DragonType FIRE = new DragonType("fire");
public static final DragonType ICE = new DragonType("ice").setPiscivore();
public static final DragonType LIGHTNING = new DragonType("lightning");
Expand All @@ -36,26 +24,24 @@ public static String getNameFromInt(int type){
}
}

public static int getIntFromType(DragonType type){
if(type == LIGHTNING){
public int getIntFromType() {
if (this == LIGHTNING) {
return 2;
}else if (type == ICE){
} else if (this == ICE) {
return 1;
}else{
} else {
return 0;
}
}

public static @Nullable DragonType getType(final EntityType<?> type) {
if (type == IafEntityRegistry.LIGHTNING_DRAGON.get()) {
return DragonType.LIGHTNING;
} else if (type == IafEntityRegistry.ICE_DRAGON.get()) {
return DragonType.ICE;
} else if (type == IafEntityRegistry.FIRE_DRAGON.get()) {
return DragonType.FIRE;
public EntityType<? extends EntityDragonBase> getEntity() {
if (this == LIGHTNING) {
return IafEntityRegistry.LIGHTNING_DRAGON.get();
} else if (this == ICE) {
return IafEntityRegistry.ICE_DRAGON.get();
}

return null;
return IafEntityRegistry.FIRE_DRAGON.get();
}

public String getName() {
Expand All @@ -74,83 +60,4 @@ public DragonType setPiscivore() {
piscivore = true;
return this;
}

public void updateEggCondition(EntityDragonEgg egg) {
BlockPos pos = new BlockPos(egg.blockPosition());
if (this == FIRE) {
if (egg.level().getBlockState(pos).isBurning(egg.level(), pos)) {
egg.setDragonAge(egg.getDragonAge() + 1);
}
if (egg.getDragonAge() > IafConfig.dragonEggTime) {
egg.level().setBlockAndUpdate(pos, Blocks.AIR.defaultBlockState());
EntityFireDragon dragon = new EntityFireDragon(egg.level());
if (egg.hasCustomName()) {
dragon.setCustomName(egg.getCustomName());
}
dragon.setVariant(egg.getEggType().ordinal());
dragon.setGender(egg.getRandom().nextBoolean());
dragon.setPos(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5);
dragon.setHunger(50);
if (!egg.level().isClientSide) {
egg.level().addFreshEntity(dragon);
}
if (egg.hasCustomName()) {
dragon.setCustomName(egg.getCustomName());
}
dragon.setTame(true);
dragon.setOwnerUUID(egg.getOwnerId());
egg.level().playLocalSound(egg.getX(), egg.getY() + egg.getEyeHeight(), egg.getZ(), SoundEvents.FIRE_EXTINGUISH, egg.getSoundSource(), 2.5F, 1.0F, false);
egg.level().playLocalSound(egg.getX(), egg.getY() + egg.getEyeHeight(), egg.getZ(), IafSoundRegistry.EGG_HATCH, egg.getSoundSource(), 2.5F, 1.0F, false);
egg.remove(Entity.RemovalReason.DISCARDED);
}
}
if (this == ICE) {
if (egg.level().getBlockState(pos).is(Blocks.WATER) && egg.getRandom().nextInt(500) == 0) {
egg.level().setBlockAndUpdate(pos, IafBlockRegistry.EGG_IN_ICE.get().defaultBlockState());
egg.level().playLocalSound(egg.getX(), egg.getY() + egg.getEyeHeight(), egg.getZ(), SoundEvents.GLASS_BREAK, egg.getSoundSource(), 2.5F, 1.0F, false);
if (egg.level().getBlockState(pos).getBlock() instanceof BlockEggInIce) {
((TileEntityEggInIce) egg.level().getBlockEntity(pos)).type = egg.getEggType();
((TileEntityEggInIce) egg.level().getBlockEntity(pos)).ownerUUID = egg.getOwnerId();
}
egg.remove(Entity.RemovalReason.DISCARDED);
}
}
if (this == LIGHTNING) {
boolean flag;
BlockPos.MutableBlockPos blockpos$pooledmutable = new BlockPos.MutableBlockPos(egg.getX(), egg.getY(), egg.getZ());
flag = egg.level().isRainingAt(blockpos$pooledmutable) || egg.level().isRainingAt(blockpos$pooledmutable.set(egg.getX(), egg.getY() + (double) egg.getBbHeight(), egg.getZ()));
if (egg.level().canSeeSky(egg.blockPosition().above()) && flag) {
egg.setDragonAge(egg.getDragonAge() + 1);
}
if (egg.getDragonAge() > IafConfig.dragonEggTime) {
EntityLightningDragon dragon = new EntityLightningDragon(egg.level());
if (egg.hasCustomName()) {
dragon.setCustomName(egg.getCustomName());
}
dragon.setVariant(egg.getEggType().ordinal() - 8);
dragon.setGender(egg.getRandom().nextBoolean());
dragon.setPos(pos.getX() + 0.5, pos.getY() + 1, pos.getZ() + 0.5);
dragon.setHunger(50);
if (!egg.level().isClientSide) {
egg.level().addFreshEntity(dragon);
}
if (egg.hasCustomName()) {
dragon.setCustomName(egg.getCustomName());
}
dragon.setTame(true);
dragon.setOwnerUUID(egg.getOwnerId());
LightningBolt lightningboltentity = EntityType.LIGHTNING_BOLT.create(egg.level());
lightningboltentity.setPos(egg.getX(), egg.getY(), egg.getZ());
lightningboltentity.setVisualOnly(true);
if (!egg.level().isClientSide) {
egg.level().addFreshEntity(lightningboltentity);
}
egg.level().playLocalSound(egg.getX(), egg.getY() + egg.getEyeHeight(), egg.getZ(), SoundEvents.LIGHTNING_BOLT_THUNDER, egg.getSoundSource(), 2.5F, 1.0F, false);
egg.level().playLocalSound(egg.getX(), egg.getY() + egg.getEyeHeight(), egg.getZ(), IafSoundRegistry.EGG_HATCH, egg.getSoundSource(), 2.5F, 1.0F, false);
egg.remove(Entity.RemovalReason.DISCARDED);


}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,6 @@
import net.minecraft.world.entity.ai.navigation.WallClimberNavigation;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.*;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
Expand Down Expand Up @@ -355,7 +354,7 @@ public void aiStep() {
if (this.isOrderedToSit()) {
this.getNavigation().stop();
//TODO
//this.getMoveHelper().action = MovementController.Action.WAIT;
// this.getMoveHelper().action = MovementController.Action.WAIT;
}
if (flying) {
ticksFlying++;
Expand Down Expand Up @@ -747,20 +746,20 @@ public boolean doHurtTarget(@NotNull Entity entityIn) {
return false;
}

// FIXME :: Unused
public boolean isRidingPlayer(Player player) {
return getRidingPlayer() != null && player != null && getRidingPlayer().getUUID().equals(player.getUUID());
}

@Override
@Nullable
public Player getRidingPlayer() {
if (this.getControllingPassenger() instanceof Player) {
return (Player) this.getControllingPassenger();
public @Nullable Player getRidingPlayer() {
if (this.getControllingPassenger() instanceof Player player) {
return player;
}

return null;
}


@Override
public boolean isFlying() {
if (level().isClientSide) {
Expand All @@ -777,7 +776,7 @@ public void setFlying(boolean flying) {
}

public int getVariant() {
return this.entityData.get(VARIANT).intValue();
return this.entityData.get(VARIANT);
}

public void setVariant(int variant) {
Expand All @@ -786,20 +785,20 @@ public void setVariant(int variant) {

@Override
public boolean isGoingUp() {
return (entityData.get(CONTROL_STATE).byteValue() & 1) == 1;
return (entityData.get(CONTROL_STATE) & 1) == 1;
}

@Override
public boolean isGoingDown() {
return (entityData.get(CONTROL_STATE).byteValue() >> 1 & 1) == 1;
return (entityData.get(CONTROL_STATE) >> 1 & 1) == 1;
}

public boolean attack() {
return (entityData.get(CONTROL_STATE).byteValue() >> 2 & 1) == 1;
return (entityData.get(CONTROL_STATE) >> 2 & 1) == 1;
}

public boolean dismountIAF() {
return (entityData.get(CONTROL_STATE).byteValue() >> 3 & 1) == 1;
return (entityData.get(CONTROL_STATE) >> 3 & 1) == 1;
}

@Override
Expand Down Expand Up @@ -828,7 +827,7 @@ public void dismount(boolean dismount) {
}

private void setStateField(int i, boolean newState) {
byte prevState = entityData.get(CONTROL_STATE).byteValue();
byte prevState = entityData.get(CONTROL_STATE);
if (newState) {
entityData.set(CONTROL_STATE, (byte) (prevState | (1 << i)));
} else {
Expand All @@ -838,7 +837,7 @@ private void setStateField(int i, boolean newState) {

@Override
public byte getControlState() {
return entityData.get(CONTROL_STATE).byteValue();
return entityData.get(CONTROL_STATE);
}

@Override
Expand Down Expand Up @@ -930,10 +929,6 @@ public SpawnGroupData finalizeSpawn(@NotNull ServerLevelAccessor worldIn, @NotNu
return spawnDataIn;
}


public void fall(float distance, float damageMultiplier) {
}

@Override
public boolean canPhaseThroughBlock(LevelAccessor world, BlockPos pos) {
return world.getBlockState(pos).getBlock() instanceof LeavesBlock;
Expand All @@ -953,7 +948,6 @@ public boolean canMove() {
}

@Override

public void handleEntityEvent(byte id) {
if (id == 45) {
this.playEffect();
Expand Down Expand Up @@ -983,11 +977,6 @@ public boolean isPersistenceRequired() {
return true;
}

@Override
public boolean removeWhenFarAway(double distanceToClosestPlayer) {
return false;
}

@Override
public double getFlightSpeedModifier() {
return 0.555D;
Expand Down
Loading

0 comments on commit 4cdebd6

Please sign in to comment.