Skip to content

Commit

Permalink
[FIX] Tidied up some of the butterfly net code.
Browse files Browse the repository at this point in the history
  • Loading branch information
doc-bok committed Jul 19, 2023
1 parent bbc88d8 commit b6cdaad
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 17 deletions.
5 changes: 5 additions & 0 deletions README.md
Expand Up @@ -3,6 +3,11 @@

## Changelog

### [0.2.1] 2023-07-19
- Fixed butterfly release code.
- Reduced butterfly speed to make them easier to catch.
- Made fishing rod recipe a bit more readable.

### [0.1.12] 2023-07-17
- Added the butterfly net.

Expand Down
2 changes: 1 addition & 1 deletion build.gradle
Expand Up @@ -4,7 +4,7 @@ plugins {
id 'net.minecraftforge.gradle' version '5.1.+'
}

version = '0.1.12'
version = '0.2.1'
group = 'com.bokmcdok.butterflies' // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = 'butterflies'

Expand Down
Expand Up @@ -74,6 +74,9 @@ public enum Size {
// The name of the "respawned" attribute in the save data.
private static final String PLACED_BY_PLAYER = "butterflyPlacedByPlayer";

// Helper constant to modify butterfly speed
private static final double BUTTERFLY_SPEED = 0.0325d;

// The size of the butterfly
private final Size size;

Expand Down Expand Up @@ -304,38 +307,39 @@ public static Butterfly createBuckeyeButterfly(EntityType<? extends Butterfly> e

/**
* Used to release a butterfly from an item back into the world.
* @param level The current level.
* @param player The player releasing the butterfly.
* @param entityId The type of butterfly to release.
* @param position The current position of the player.
*/
public static void release(@NotNull Level level,
@NotNull Player player,
public static void release(@NotNull Player player,
String entityId,
BlockPos position) {

Level level = player.level;
if (level instanceof ServerLevel) {

// Move the target position slightly in front of the player
Vec3 lookAngle = player.getLookAngle();
position = position.offset((int) lookAngle.x, (int) lookAngle.y + 1, (int) lookAngle.z);

ResourceLocation key = new ResourceLocation(entityId);
EntityType<?> entityType = ForgeRegistries.ENTITY_TYPES.getValue(key);
if (entityType != null) {
Butterfly butterfly = (Butterfly) entityType.create(player.level);
if (butterfly != null) {
Entity entity = entityType.create(player.level);
if (entity instanceof Butterfly butterfly) {

butterfly.moveTo(position.getX() + 0.45D,
position.getY() + 0.2D,
position.getZ() + 0.5D,
0.0F, 0.0F);

butterfly.finalizeSpawn((ServerLevel) level,
level.getCurrentDifficultyAt(player.getOnPos()),
MobSpawnType.NATURAL,
null,
null);

butterfly.setPlacedByPlayer();
player.level.addFreshEntity(butterfly);
level.addFreshEntity(butterfly);
}
}
} else {
Expand Down Expand Up @@ -523,9 +527,9 @@ protected void customServerAiStep() {
double dz = this.targetPosition.getZ() + 0.5d - this.getZ();

Vec3 deltaMovement = this.getDeltaMovement();
Vec3 updatedDeltaMovement = deltaMovement.add((Math.signum(dx) * 0.5d - deltaMovement.x) * 0.1d,
Vec3 updatedDeltaMovement = deltaMovement.add((Math.signum(dx) * 0.5d - deltaMovement.x) * BUTTERFLY_SPEED,
(Math.signum(dy) * 0.7d - deltaMovement.y) * 0.1d,
(Math.signum(dz) * 0.5d - deltaMovement.z) * 0.1d);
(Math.signum(dz) * 0.5d - deltaMovement.z) * BUTTERFLY_SPEED);
this.setDeltaMovement(updatedDeltaMovement);

this.zza = 0.5f;
Expand Down
@@ -1,6 +1,5 @@
package com.bokmcdok.butterflies.world.item;

import com.bokmcdok.butterflies.registries.ItemRegistry;
import com.bokmcdok.butterflies.world.entity.ambient.Butterfly;
import net.minecraft.ChatFormatting;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -105,7 +104,7 @@ public InteractionResultHolder<ItemStack> use(@NotNull Level level,
CompoundTag tag = stack.getOrCreateTag();
if (tag.contains("EntityId")) {
String entityId = tag.getString("EntityId");
Butterfly.release(level, player, entityId, player.blockPosition());
Butterfly.release(player, entityId, player.blockPosition());
tag.remove("CustomModelData");
tag.remove("EntityId");

Expand Down
10 changes: 5 additions & 5 deletions src/main/resources/data/butterflies/recipes/butterfly_net.json
@@ -1,15 +1,15 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
" #",
" #X",
"#XX"
" /",
" /s",
"/ss"
],
"key": {
"#": {
"/": {
"item": "minecraft:stick"
},
"X": {
"s": {
"item": "minecraft:string"
}
},
Expand Down

0 comments on commit b6cdaad

Please sign in to comment.