Skip to content

Commit

Permalink
fix crown
Browse files Browse the repository at this point in the history
  • Loading branch information
FuGu0416 committed Aug 21, 2022
1 parent 27f8cfc commit 4c6fb06
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 117 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ public ILivingEntityData finalizeSpawn(IServerWorld p_213386_1_, DifficultyInsta
this.setItemSlot(EquipmentSlotType.MAINHAND, new ItemStack(Items.IRON_SWORD));
break;
case 2:
default:
this.setItemSlot(EquipmentSlotType.MAINHAND, new ItemStack(Items.BOW));
break;
/*case 3:
Expand All @@ -160,10 +161,7 @@ public ILivingEntityData finalizeSpawn(IServerWorld p_213386_1_, DifficultyInsta
skeletonhorseentity.level.addFreshEntity(skeletonhorseentity);
this.startRiding(skeletonhorseentity);
break;*/
default:
break;

break;*/
}
this.reassessWeaponGoal();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,7 @@ public class EntityAIFollowEntity extends Goal
float minDist;
private float oldWaterCost;

public EntityAIFollowEntity(MobEntity tameableIn, UUID uniqueIDIn, double followSpeedIn, float minDistIn, float maxDistIn)
{
public EntityAIFollowEntity(MobEntity tameableIn, UUID uniqueIDIn, double followSpeedIn, float minDistIn, float maxDistIn) {
this.tameable = tameableIn;
this.ownerID = uniqueIDIn;
this.world = tameableIn.level;
Expand All @@ -42,53 +41,44 @@ public EntityAIFollowEntity(MobEntity tameableIn, UUID uniqueIDIn, double follow
this.minDist = minDistIn;
this.maxDist = maxDistIn;

if (!(tameableIn.getNavigation() instanceof GroundPathNavigator) && !(tameableIn.getNavigation() instanceof FlyingPathNavigator))
{
if (!(tameableIn.getNavigation() instanceof GroundPathNavigator) && !(tameableIn.getNavigation() instanceof FlyingPathNavigator)) {
throw new IllegalArgumentException("Unsupported mob type for FollowOwnerGoal");
}
}

/**
* Returns whether the EntityAIBase should begin execution.
*/
public boolean canUse()
{
public boolean canUse() {
if(this.world instanceof ServerWorld) {
LivingEntity LivingEntity = SpawnUtil.getEntityByUniqueId(this.ownerID, (ServerWorld) this.world);

if (LivingEntity == null)
{
if (LivingEntity == null) {
return false;
}
else if (LivingEntity instanceof PlayerEntity && ((PlayerEntity)LivingEntity).isSpectator())
{
} else if (LivingEntity instanceof PlayerEntity && ((PlayerEntity)LivingEntity).isSpectator()) {
return false;
}
else if (this.tameable.distanceToSqr(LivingEntity) < (double)(this.minDist * this.minDist))
{
} else if (this.tameable.distanceToSqr(LivingEntity) < (double)(this.minDist * this.minDist)) {
return false;
}
else
{
} else {
this.owner = LivingEntity;
return true;
}
} else return false;
}

return false;
}

/**
* Returns whether an in-progress EntityAIBase should continue executing
*/
public boolean canContinueToUse()
{
public boolean canContinueToUse() {
return !this.petPathfinder.isDone() && this.tameable.distanceToSqr(this.owner) > (double)(this.maxDist * this.maxDist);
}

/**
* Execute a one shot task or start executing a continuous task
*/
public void start()
{
public void start() {
this.timeToRecalcPath = 0;
this.oldWaterCost = this.tameable.getPathfindingMalus(PathNodeType.WATER);
this.tameable.setPathfindingMalus(PathNodeType.WATER, 0.0F);
Expand All @@ -97,8 +87,7 @@ public void start()
/**
* Reset the task's internal state. Called when this task is interrupted by another one
*/
public void stop()
{
public void stop() {
this.owner = null;
this.petPathfinder.stop();
this.tameable.setPathfindingMalus(PathNodeType.WATER, this.oldWaterCost);
Expand All @@ -107,16 +96,13 @@ public void stop()
/**
* Keep ticking a continuous task that has already been started
*/
public void tick()
{
public void tick() {
this.tameable.getLookControl().setLookAt(this.owner, 10.0F, (float)this.tameable.getMaxHeadXRot());

if (--this.timeToRecalcPath <= 0)
{
if (--this.timeToRecalcPath <= 0) {
this.timeToRecalcPath = 10;

if (!this.tameable.isLeashed() && !this.tameable.isPassenger())
{
if (!this.tameable.isLeashed() && !this.tameable.isPassenger()) {
if (this.tameable.distanceToSqr(this.owner) >= 144.0D) {
this.teleportToOwner();
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingJumpEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingVisibilityEvent;
import net.minecraftforge.event.entity.living.LivingFallEvent;
import net.minecraftforge.event.entity.player.PlayerWakeUpEvent;
import net.minecraftforge.event.village.VillagerTradesEvent;
Expand Down Expand Up @@ -478,6 +477,10 @@ public void onEntityJoinWorld(EntityJoinWorldEvent event) {

if(event.getEntity() != null && event.getEntity().getType().equals(EntityType.HOGLIN))
((HoglinEntity)event.getEntity()).goalSelector.addGoal(3, new AvoidEntityGoal<>(((HoglinEntity)event.getEntity()), WarpedFireflyEntity.class, 6.0F, 1.0D, 1.2D));

if(event.getEntity() != null && event.getEntity() instanceof AbstractSkeletonEntity && event.getEntity().getTags().contains("FUR_tameSkeleton")) {
event.getEntity().removeTag("FUR_tameSkeleton");
}
}

@SubscribeEvent
Expand Down Expand Up @@ -720,13 +723,6 @@ public void onWanderingTradeSetup(WandererTradesEvent event) {
}
}

@SubscribeEvent
public void onEVisibility(LivingVisibilityEvent event) {
if (event.getLookingEntity() instanceof AbstractSkeletonEntity)
if (event.getEntityLiving() instanceof PlayerEntity && event.getEntityLiving().getItemBySlot(EquipmentSlotType.HEAD).getItem().equals(FURItemRegistry.SKELETONKING_CROWN))
event.modifyVisibility(0.0D);
}

@SubscribeEvent
public void onEJump(LivingJumpEvent event) {
int Armor_Chitin_lvl = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.Fishmod.mod_LavaCow.item;

import java.lang.reflect.Field;
import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import javax.annotation.Nullable;

import com.Fishmod.mod_LavaCow.client.model.armor.ModelCrown;
Expand All @@ -17,10 +15,8 @@
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.ai.goal.Goal;
import net.minecraft.entity.ai.goal.NearestAttackableTargetGoal;
import net.minecraft.entity.ai.goal.PrioritizedGoal;
import net.minecraft.entity.monster.AbstractSkeletonEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.inventory.EquipmentSlotType;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.ArmorMaterial;
Expand All @@ -36,7 +32,8 @@
import net.minecraftforge.api.distmarker.OnlyIn;

public class SkeletonKingCrownItem extends ArmorItem {

private List<Goal> remove = new ArrayList<Goal>();

public SkeletonKingCrownItem(Item.Properties p_i48534_3_) {
super(ArmorMaterial.DIAMOND, EquipmentSlotType.HEAD, p_i48534_3_);
}
Expand All @@ -62,82 +59,39 @@ public boolean isValidRepairItem(ItemStack armour, ItemStack material) {
/**
* Called to tick armor in the armor slot. Override to do something
*/
@SuppressWarnings("unchecked")
@Override
public void onArmorTick(ItemStack itemStack, World world, PlayerEntity player){
if(player.tickCount % 20 == 0) {
boolean modified = false;

for (AbstractSkeletonEntity Skeleton : world.getEntitiesOfClass(AbstractSkeletonEntity.class, player.getBoundingBox().inflate(16.0D))) {
Field goals;
Goal remove = null;
public void onArmorTick(ItemStack itemStack, World world, PlayerEntity player) {
if(player.tickCount % 20 == 0) {
for (AbstractSkeletonEntity Skeleton : world.getEntitiesOfClass(AbstractSkeletonEntity.class, player.getBoundingBox().inflate(16.0D))) {
this.remove.clear();

if(Skeleton.getTarget() != null && Skeleton.getTarget().equals(player))
Skeleton.setTarget(null);

try {
goals = Skeleton.targetSelector.getClass().getDeclaredField("availableGoals");
goals.setAccessible(true);
Set<PrioritizedGoal> goalSet;
try {
goalSet = (Set<PrioritizedGoal>) goals.get(Skeleton.targetSelector);
for(PrioritizedGoal task : goalSet) {
if(task.getGoal() instanceof EntityAIFollowEntity) {
modified = true;
}

if(task.getGoal() instanceof NearestAttackableTargetGoal<?>) {
Field targetClassField;
try {
targetClassField = task.getGoal().getClass().getDeclaredField("targetType");
targetClassField.setAccessible(true);
Class<?> targetClass;
try {
targetClass = (Class<?>) targetClassField.get(task.getGoal());
if(targetClass.equals(PlayerEntity.class) || targetClass.equals(ServerPlayerEntity.class)) {
remove = task.getGoal();
break;
}
} catch (IllegalArgumentException e) {
continue;
} catch (IllegalAccessException e) {
continue;
}
} catch (NoSuchFieldException e) {
continue;
} catch (SecurityException e) {
continue;
}
}
}

if(!modified && remove != null) {
Skeleton.setTarget(null);
Skeleton.playSound(SoundEvents.EVOKER_CAST_SPELL, 1.0F, 1.0F);

for(int i = 0; i < 16; ++i) {
double d0 = Item.random.nextGaussian() * 0.02D;
double d1 = Item.random.nextGaussian() * 0.02D;
double d2 = Item.random.nextGaussian() * 0.02D;
player.level.addParticle(ParticleTypes.ENTITY_EFFECT, Skeleton.getRandomX(1.0D), Skeleton.getRandomY() + 1.0D, Skeleton.getRandomZ(1.0D), d0, d1, d2);
}

Skeleton.goalSelector.addGoal(6, new EntityAIFollowEntity(Skeleton, player.getUUID(), 1.0D, 10.0F, 2.0F));
Skeleton.targetSelector.addGoal(1, new SkeletonOwnerHurtByTargetGoal(Skeleton, player.getUUID()));
Skeleton.targetSelector.addGoal(2, new SkeletonOwnerHurtTargetGoal(Skeleton, player.getUUID()));
Skeleton.targetSelector.removeGoal(remove);
}
} catch (IllegalArgumentException e1) {
e1.printStackTrace();
} catch (IllegalAccessException e1) {
e1.printStackTrace();
Skeleton.targetSelector.getRunningGoals().forEach((k) -> {
if(k.getGoal() instanceof NearestAttackableTargetGoal<?>) {
this.remove.add(k.getGoal());
}
});

for(Goal e : this.remove) {
Skeleton.targetSelector.removeGoal(e);
}

if(!Skeleton.getTags().contains("FUR_tameSkeleton")) {
Skeleton.playSound(SoundEvents.EVOKER_CAST_SPELL, 1.0F, 1.0F);
for(int i = 0; i < 16; ++i) {
double d0 = Item.random.nextGaussian() * 0.02D;
double d1 = Item.random.nextGaussian() * 0.02D;
double d2 = Item.random.nextGaussian() * 0.02D;
player.level.addParticle(ParticleTypes.ENTITY_EFFECT, Skeleton.getRandomX(1.0D), Skeleton.getRandomY() + 1.0D, Skeleton.getRandomZ(1.0D), d0, d1, d2);
}

} catch (NoSuchFieldException e1) {
e1.printStackTrace();
} catch (SecurityException e1) {
e1.printStackTrace();
}
Skeleton.goalSelector.addGoal(6, new EntityAIFollowEntity(Skeleton, player.getUUID(), 1.0D, 10.0F, 2.0F));
Skeleton.targetSelector.addGoal(1, new SkeletonOwnerHurtByTargetGoal(Skeleton, player.getUUID()));
Skeleton.targetSelector.addGoal(2, new SkeletonOwnerHurtTargetGoal(Skeleton, player.getUUID()));
Skeleton.addTag("FUR_tameSkeleton");
}
}
}
}
Expand Down

0 comments on commit 4c6fb06

Please sign in to comment.