Skip to content

Commit

Permalink
Make crabs and horseshoe crabs bucketable
Browse files Browse the repository at this point in the history
  • Loading branch information
itsmeow committed Dec 28, 2021
1 parent bd13742 commit 441ffff
Show file tree
Hide file tree
Showing 14 changed files with 130 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import dev.itsmeow.betteranimalsplus.common.entity.util.abstracts.EntityCrabLikeBase;
import dev.itsmeow.betteranimalsplus.init.ModEntities;
import dev.itsmeow.imdlib.entity.EntityTypeContainer;
import dev.itsmeow.imdlib.entity.util.EntityTypeContainerContainable;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.syncher.EntityDataAccessor;
import net.minecraft.network.syncher.EntityDataSerializers;
Expand Down Expand Up @@ -143,4 +144,8 @@ public EntityTypeContainer<EntityCrab> getContainer() {
return ModEntities.CRAB;
}

@Override
public EntityTypeContainerContainable<?, ?> getContainableContainer() {
return ModEntities.CRAB;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import dev.itsmeow.betteranimalsplus.init.ModEntities;
import dev.itsmeow.betteranimalsplus.init.ModItems;
import dev.itsmeow.imdlib.entity.EntityTypeContainer;
import dev.itsmeow.imdlib.entity.interfaces.IContainable;
import dev.itsmeow.imdlib.entity.util.EntityTypeContainerContainable;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.DifficultyInstance;
import net.minecraft.world.InteractionHand;
Expand Down Expand Up @@ -72,9 +74,32 @@ public void addAdditionalSaveData(CompoundTag compound) {
compound.putInt("BloodLeft", this.bloodLeft);
}

@Override
public void setContainerData(ItemStack bucket) {
super.setContainerData(bucket);
CompoundTag tag = bucket.getTag();
if(bucket.getTag() == null) {
tag = new CompoundTag();
}
tag.putInt("HorseshoeCrabBloodLeft", this.bloodLeft);
bucket.setTag(tag);
}

@Override
public void readFromContainerTag(CompoundTag tag) {
super.readFromContainerTag(tag);
if(tag.contains("HorseshoeCrabBloodLeft")) {
this.bloodLeft = tag.getInt("HorseshoeCrabBloodLeft");
}
}

@Override
public EntityTypeContainer<EntityHorseshoeCrab> getContainer() {
return ModEntities.HORSESHOE_CRAB;
}

@Override
public EntityTypeContainerContainable<?, ?> getContainableContainer() {
return ModEntities.HORSESHOE_CRAB;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package dev.itsmeow.betteranimalsplus.common.entity.util.abstracts;

import dev.itsmeow.imdlib.entity.interfaces.IContainable;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;

public abstract class EntityAnimalWithTypesContainable extends EntityAnimalWithTypes implements IContainable {

public EntityAnimalWithTypesContainable(EntityType<? extends EntityAnimalWithTypesContainable> entityType, Level worldIn) {
super(entityType, worldIn);
}

@Override
protected void defineSynchedData() {
super.defineSynchedData();
this.registerFromContainerKey();
}

@Override
public void addAdditionalSaveData(CompoundTag compound) {
super.addAdditionalSaveData(compound);
this.writeFromContainerToEntity(compound);
}

@Override
public void readAdditionalSaveData(CompoundTag compound) {
super.readAdditionalSaveData(compound);
this.readFromContainerToEntity(compound);
}

@Override
public boolean removeWhenFarAway(double distanceToClosestPlayer) {
return !this.isFromContainer() && despawn(distanceToClosestPlayer);
}

@Override
public boolean requiresCustomPersistence() {
return this.isFromContainer();
}

@Override
public void setContainerData(ItemStack bucket) {
IContainable.super.setContainerData(bucket);
CompoundTag tag = bucket.getTag();
if(bucket.getTag() == null) {
tag = new CompoundTag();
}
tag.putString("BucketVariantTag", this.getVariantNameOrEmpty());
bucket.setTag(tag);
}

@Override
public InteractionResult mobInteract(Player player, InteractionHand hand) {
if(this.processContainerInteract(player, hand)) {
return InteractionResult.SUCCESS;
}
return super.mobInteract(player, hand);
}

@Override
public void readFromContainerTag(CompoundTag tag) {
if(tag.contains("BucketVariantTag")) {
this.setType(tag.getString("BucketVariantTag"));
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@

import java.util.Random;

public abstract class EntityCrabLikeBase extends EntityAnimalWithTypes {
public abstract class EntityCrabLikeBase extends EntityAnimalWithTypesContainable {

public int snipTime = 0;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public class ModEntities {
.size(0.8F, 0.8F)
.biomesOverworld(BiomeTypes.FOREST, BiomeTypes.PLAINS, BiomeTypes.SAVANNA)
.variants("american", "european", "honey"));
public static final EntityTypeContainer<EntityCrab> CRAB = H.add(EntityCrab.class, EntityCrab::new, "crab", () -> Mob.createMobAttributes()
public static final EntityTypeContainerContainable<EntityCrab, ItemModFishBucket<EntityCrab>> CRAB = H.addContainableB(EntityCrab.class, EntityCrab::new, "crab", () -> Mob.createMobAttributes()
.add(Attributes.MAX_HEALTH, 6.5D)
.add(Attributes.MOVEMENT_SPEED, 0.3D)
.add(Attributes.ATTACK_DAMAGE)
Expand All @@ -117,8 +117,9 @@ public class ModEntities {
.egg(0xe21d16, 0x2d0504)
.size(1F, 0.65F)
.biomesOverworld(BiomeTypes.BEACH, BiomeTypes.SWAMP)
.variants(4));
public static final EntityTypeContainer<EntityHorseshoeCrab> HORSESHOE_CRAB = H.add(EntityHorseshoeCrab.class, EntityHorseshoeCrab::new, "horseshoecrab", () -> Mob.createMobAttributes()
.variants("red", "pink", "brown", "blue")
.containers("%s_bucket", ItemModFishBucket.waterBucket(G), "", c -> Items.WATER_BUCKET));
public static final EntityTypeContainerContainable<EntityHorseshoeCrab, ItemModFishBucket<EntityHorseshoeCrab>> HORSESHOE_CRAB = H.addContainableB(EntityHorseshoeCrab.class, EntityHorseshoeCrab::new, "horseshoecrab", () -> Mob.createMobAttributes()
.add(Attributes.MAX_HEALTH, 6.5D)
.add(Attributes.MOVEMENT_SPEED, 0.3D)
.add(Attributes.ATTACK_DAMAGE)
Expand All @@ -128,7 +129,8 @@ public class ModEntities {
.egg(0xba1111, 0x520807)
.size(1F, 0.65F)
.biomesOverworld(BiomeTypes.BEACH)
.variants("brown", "dark_brown", "green", "orange"));
.variants("brown", "dark_brown", "green", "orange")
.containers("%s_bucket", ItemModFishBucket.waterBucket(G), "", c -> Items.WATER_BUCKET));
public static final EntityTypeContainer<EntityShark> SHARK = H.add(EntityShark.class, EntityShark::new, "shark", () -> Mob.createMobAttributes()
.add(Attributes.MAX_HEALTH, 30D)
.add(Attributes.MOVEMENT_SPEED, 1.5D)
Expand Down
10 changes: 10 additions & 0 deletions common/src/main/resources/assets/betteranimalsplus/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,8 @@
"item.betteranimalsplus.calamari_cooked": "Cooked Calamari",
"item.betteranimalsplus.piranha_bucket": "Bucket of Piranha",
"item.betteranimalsplus.horseshoe_crab_blood": "Horseshoe Crab Blood",
"item.betteranimalsplus.crab_bucket": "Bucket of Crab",
"item.betteranimalsplus.horseshoecrab_bucket": "Bucket of Horseshoe Crab",

"block.betteranimalsplus.trillium": "Trillium",
"block.betteranimalsplus.feralwolfhead": "Feral Wolf Head",
Expand Down Expand Up @@ -133,6 +135,14 @@
"entity.betteranimalsplus.dragonfly.type.yellow_winged_darter": "Yellow Winged Darter",
"entity.betteranimalsplus.flying_fish.type.yellow": "Yellow",
"entity.betteranimalsplus.flying_fish.type.purple": "Purple",
"entity.betteranimalsplus.crab.type.red": "Red",
"entity.betteranimalsplus.crab.type.pink": "Pink",
"entity.betteranimalsplus.crab.type.brown": "Brown",
"entity.betteranimalsplus.crab.type.blue": "Blue",
"entity.betteranimalsplus.horseshoecrab.type.brown": "Brown",
"entity.betteranimalsplus.horseshoecrab.type.dark_brown": "Dark Brown",
"entity.betteranimalsplus.horseshoecrab.type.green": "Green",
"entity.betteranimalsplus.horseshoecrab.type.orange": "Orange",

"entity.betteranimalsplus.coyote.message.currently_hostile": "This coyote is currently hostile. Perhaps it could be tamed outside of its hunting hours?",
"entity.betteranimalsplus.coyote.message.always_hostile": "This coyote is always hostile. It cannot be tamed (server configuration)",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "betteranimalsplus:items/crab_bucket"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "betteranimalsplus:items/horseshoecrab_bucket"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 441ffff

Please sign in to comment.