Skip to content
This repository has been archived by the owner on Dec 16, 2023. It is now read-only.

Commit

Permalink
Small clean up
Browse files Browse the repository at this point in the history
  • Loading branch information
percivalalb committed Sep 13, 2020
1 parent 5632e21 commit a5f643c
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/main/java/doggytalents/DoggyItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public class DoggyItems {
public static final RegistryObject<Item> TINY_BONE = registerSizeBone("tiny_bone", SizeBoneItem.Type.TINY);
public static final RegistryObject<Item> BIG_BONE = registerSizeBone("big_bone", SizeBoneItem.Type.BIG);
public static final RegistryObject<Item> OWNER_CHANGE = registerWith("owner_change", ChangeOwnerItem::new, 1);
public static final RegistryObject<Item> PATROl = registerWith("patrol_item", PatrolItem::new, 1);
//public static final RegistryObject<Item> PATROL = registerWith("patrol_item", PatrolItem::new, 1);

private static Item.Properties createInitialProp() {
return new Item.Properties().group(DoggyItemGroups.GENERAL);
Expand Down
2 changes: 0 additions & 2 deletions src/main/java/doggytalents/common/data/DTRecipeProvider.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,6 @@ protected void registerRecipes(Consumer<IFinishedRecipe> consumer) {
// ShapedRecipeBuilder.shapedRecipe(ModItems.RADIO_COLLAR.get(), 1).patternLine("XX").patternLine("YX").key('X', Items.IRON_INGOT).key('Y', Items.REDSTONE).addCriterion("has_redstone", this.hasItem(Items.REDSTONE)).build(consumer);
// ShapelessRecipeBuilder.shapelessRecipe(ModItems.RADAR.get(), 1).addIngredient(Items.MAP, 1).addIngredient(Items.REDSTONE, 1).addIngredient(ModItems.RADIO_COLLAR.get(), 1).addCriterion("has_redstone", this.hasItem(Items.REDSTONE)).build(consumer);
//
// CustomRecipeBuilder.customRecipe(ModRecipes.CAPE_COLOURING.get()).build(consumer, Reference.MOD_ID + ":cape_colouring");
// CustomRecipeBuilder.customRecipe(ModRecipes.COLLAR_COLOURING.get()).build(consumer, Reference.MOD_ID + ":collar_colouring");
CustomRecipeBuilder.customRecipe(DoggyRecipeSerializers.DOG_BED.get()).build(consumer, Util.getResourcePath("dog_bed"));
}

Expand Down
4 changes: 3 additions & 1 deletion src/main/java/doggytalents/common/entity/DogEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -1597,11 +1597,13 @@ public void setTalentLevel(Talent talent, int level) {
boolean existed = map.containsKey(talent);
if (level > 0) {
map.put(talent, level);
talent.set(this, level);

if (!existed) {
talent.init(this);
}

talent.set(this, level);

} else {
int preLevel = map.getOrDefault(talent, 0);
map.remove(talent);
Expand Down
108 changes: 108 additions & 0 deletions src/main/java/doggytalents/common/entity/ai/WanderModeGoal.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package doggytalents.common.entity.ai;

import java.util.EnumSet;
import java.util.Optional;
import java.util.Random;

import javax.annotation.Nullable;

import doggytalents.api.feature.EnumMode;
import doggytalents.common.entity.DogEntity;
import net.minecraft.entity.ai.goal.Goal;
import net.minecraft.pathfinding.PathNavigator;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;

public class WanderModeGoal extends Goal {

protected final DogEntity dog;
protected boolean wandering;

protected double x;
protected double y;
protected double z;
protected final double speed;
protected int executionChance;
protected boolean mustUpdate;

public WanderModeGoal(DogEntity dogIn, double speedIn) {
this.dog = dogIn;
this.speed = speedIn;
this.wandering = false;
this.executionChance = 60;
this.setMutexFlags(EnumSet.of(Goal.Flag.MOVE));
}

@Override
public boolean shouldExecute() {
if (this.dog.isBeingRidden()) {
return false;
} else {
if(this.dog.getIdleTime() >= 100) {
return false;
} else if(this.dog.getRNG().nextInt(this.executionChance) != 0) {
return false;
} else if(!(this.dog.isTamed() && this.dog.isMode(EnumMode.WANDERING) && this.dog.getBowlPos().isPresent() && this.dog.getBowlPos().get().withinDistance(this.getPosition(), 20D))) {
return false;
}

Vec3d vec3d = this.getPosition();
if (vec3d == null) {
return false;
} else {
this.x = vec3d.x;
this.y = vec3d.y;
this.z = vec3d.z;
return true;
}
}
}

@Nullable
protected Vec3d getPosition() {
PathNavigator pathnavigate = dog.getNavigator();
Random random = dog.getRNG();

int xzRange = 5;
int yRange = 3;

float bestWeight = -99999.0F;
Optional<BlockPos> bowlPosOptional = this.dog.getBowlPos();

if (bowlPosOptional.isPresent()) {
BlockPos bowlPos = bowlPosOptional.get();
BlockPos bestPos = bowlPos;

for(int attempt = 0; attempt < 10; ++attempt) {
int l = random.nextInt(2 * xzRange + 1) - xzRange;
int i1 = random.nextInt(2 * yRange + 1) - yRange;
int j1 = random.nextInt(2 * xzRange + 1) - xzRange;

BlockPos testPos = bowlPos.add(l, i1, j1);

if(pathnavigate.canEntityStandOnPos(testPos)) {
float weight = this.dog.getBlockPathWeight(testPos);

if(weight > bestWeight) {
bestWeight = weight;
bestPos = testPos;
}
}
}

return new Vec3d(bestPos.getX(), bestPos.getY(), bestPos.getZ());
}

return null;
}

@Override
public boolean shouldContinueExecuting() {
return !this.dog.getNavigator().noPath();
}

@Override
public void startExecuting() {
this.dog.getNavigator().tryMoveToXYZ(this.x, this.y, this.z, this.speed);
}
}
4 changes: 2 additions & 2 deletions src/main/java/doggytalents/common/talent/BlackPeltTalent.java
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public double calculateDamage(int level) {
public void updateAttackDamage(AbstractDogEntity dogIn, double speed) {
IAttributeInstance damageInstance = dogIn.getAttribute(SharedMonsterAttributes.ATTACK_DAMAGE);

AttributeModifier speedModifier = this.createSpeedModifier(speed);
AttributeModifier speedModifier = this.createPeltModifier(speed);

if(damageInstance.getModifier(BLACK_PELT_DAMAGE_ID) != null) {
damageInstance.removeModifier(speedModifier);
Expand All @@ -64,7 +64,7 @@ public void updateAttackDamage(AbstractDogEntity dogIn, double speed) {
damageInstance.applyModifier(speedModifier);
}

public AttributeModifier createSpeedModifier(double speed) {
public AttributeModifier createPeltModifier(double speed) {
return new AttributeModifier(BLACK_PELT_DAMAGE_ID, "Black Pelt", speed, AttributeModifier.Operation.ADDITION);
}
}
9 changes: 5 additions & 4 deletions src/main/java/doggytalents/common/talent/DoggyDashTalent.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,13 @@ public double calculateSpeed(int level) {
public void updateSpeed(AbstractDogEntity dogIn, double speed) {
IAttributeInstance speedInstance = dogIn.getAttribute(SharedMonsterAttributes.MOVEMENT_SPEED);

AttributeModifier speedModifier = new AttributeModifier(DASH_BOOST_ID, "Doggy Dash", speed, AttributeModifier.Operation.ADDITION);

if(speedInstance.getModifier(DASH_BOOST_ID) != null) {
speedInstance.removeModifier(speedModifier);
speedInstance.removeModifier(DASH_BOOST_ID);
}

speedInstance.applyModifier(speedModifier);
if (speed != 0) {
AttributeModifier speedModifier = new AttributeModifier(DASH_BOOST_ID, "Doggy Dash", speed, AttributeModifier.Operation.ADDITION);
speedInstance.applyModifier(speedModifier);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ public static void onLootDrop(final LootingLevelEvent event) {
int level = dog.getLevel(DoggyTalents.HUNTER_DOG.get());

if(dog.getRNG().nextInt(6) < level + (level >= 5 ? 1 : 0)) {
DoggyTalents2.LOGGER.debug("Looting: {}", event.getLootingLevel() + level / 2);
event.setLootingLevel(event.getLootingLevel() + level / 2);
}

Expand Down

0 comments on commit a5f643c

Please sign in to comment.