Skip to content

Commit

Permalink
Added
Browse files Browse the repository at this point in the history
  • Loading branch information
Qzimyion committed Aug 14, 2024
1 parent 1ee2310 commit 4e8acae
Show file tree
Hide file tree
Showing 42 changed files with 1,002 additions and 49 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ loader_version=0.15.11
fabric_version=0.100.1+1.21

# Mod Properties
mod_version=1.1.2
mod_version=1.1.3
maven_group=com.qzimyion.bucketem
archives_base_name=bucketem
modid=bucketem
89 changes: 72 additions & 17 deletions src/main/java/com/qzimyion/bucketem/BucketemClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,15 @@

import java.util.concurrent.atomic.AtomicBoolean;

import static com.qzimyion.bucketem.items.ModItems.*;

@SuppressWarnings("deprecation")
public class BucketemClient implements ClientModInitializer {

public static void modelPredicates(){

//==Turtles==//
FabricModelPredicateProviderRegistry.register(ModItems.TURTLE_BUCKET, Identifier.ofVanilla("age"), (itemStack, clientWorld, livingEntity, i) -> {
FabricModelPredicateProviderRegistry.register(TURTLE_BUCKET, Identifier.ofVanilla("age"), (itemStack, clientWorld, livingEntity, i) -> {
AtomicBoolean ageBL = new AtomicBoolean(false);
NbtComponent.set(DataComponentTypes.BUCKET_ENTITY_DATA, itemStack, nbt -> {
nbt.get("Age");
Expand All @@ -31,32 +33,85 @@ public static void modelPredicates(){
});

//==Slimes==//
FabricModelPredicateProviderRegistry.register(ModItems.SLIME_BOTTLE, Identifier.ofVanilla("slime_chunk"), (itemStack, clientWorld, livingEntity, i) -> {
if (livingEntity instanceof PlayerEntity player) {
FabricModelPredicateProviderRegistry.register(SLIME_BOTTLE, Identifier.ofVanilla("slime_chunk"), (itemStack, clientWorld, livingEntity, i) -> {
if (livingEntity instanceof PlayerEntity) {
boolean inSlimeChunk = Boolean.TRUE.equals(itemStack.get(ModDataComponents.SLIME_CHUNK_F));
return inSlimeChunk ? 1 : 0;
} else {
return 0;
}
});


//==Axolotls==//
//Age
// FabricModelPredicateProviderRegistry.register(Items.AXOLOTL_BUCKET, Identifier.ofVanilla("age"), (itemStack, clientWorld, livingEntity, i) -> {
// AtomicBoolean ageBL = new AtomicBoolean(false);
// NbtComponent.set(DataComponentTypes.BUCKET_ENTITY_DATA, itemStack, nbt -> {
// nbt.get("Age");
// ageBL.set(nbt.getInt("Age") < 0);
// });
// float age = 1;
// if (itemStack.getComponents() != null && itemStack.contains(DataComponentTypes.BUCKET_ENTITY_DATA) && ageBL.get())
// age = 0;
// return age;
//==Golden Buckets==//
//Water
// FabricModelPredicateProviderRegistry.register(GOLDEN_WATER_BUCKET, Identifier.ofVanilla("fluidlevel"), (itemStack, clientWorld, livingEntity, i) -> {
// if (livingEntity instanceof PlayerEntity) {
// return 0;
// }
// });

//Variant

//==Axolotls==//
//Pink
FabricModelPredicateProviderRegistry.register(Items.AXOLOTL_BUCKET, Identifier.ofVanilla("age"), (itemStack, clientWorld, livingEntity, i) -> {
AtomicBoolean ageBL = new AtomicBoolean(false);
NbtComponent.set(DataComponentTypes.BUCKET_ENTITY_DATA, itemStack, nbt -> {
nbt.get("Age");
ageBL.set(nbt.getInt("Age") < 0);
});
float age = 1;
if (itemStack.getComponents() != null && itemStack.contains(DataComponentTypes.BUCKET_ENTITY_DATA) && ageBL.get())
age = 0;
return age;
});
//Brown
FabricModelPredicateProviderRegistry.register(BROWN_AXOLOTL_BUCKET, Identifier.ofVanilla("age"), (itemStack, clientWorld, livingEntity, i) -> {
AtomicBoolean ageBL = new AtomicBoolean(false);
NbtComponent.set(DataComponentTypes.BUCKET_ENTITY_DATA, itemStack, nbt -> {
nbt.get("Age");
ageBL.set(nbt.getInt("Age") < 0);
});
float age = 1;
if (itemStack.getComponents() != null && itemStack.contains(DataComponentTypes.BUCKET_ENTITY_DATA) && ageBL.get())
age = 0;
return age;
});
//Gold
FabricModelPredicateProviderRegistry.register(GOLD_AXOLOTL_BUCKET, Identifier.ofVanilla("age"), (itemStack, clientWorld, livingEntity, i) -> {
AtomicBoolean ageBL = new AtomicBoolean(false);
NbtComponent.set(DataComponentTypes.BUCKET_ENTITY_DATA, itemStack, nbt -> {
nbt.get("Age");
ageBL.set(nbt.getInt("Age") < 0);
});
float age = 1;
if (itemStack.getComponents() != null && itemStack.contains(DataComponentTypes.BUCKET_ENTITY_DATA) && ageBL.get())
age = 0;
return age;
});
//Cyan
FabricModelPredicateProviderRegistry.register(CYAN_AXOLOTL_BUCKET, Identifier.ofVanilla("age"), (itemStack, clientWorld, livingEntity, i) -> {
AtomicBoolean ageBL = new AtomicBoolean(false);
NbtComponent.set(DataComponentTypes.BUCKET_ENTITY_DATA, itemStack, nbt -> {
nbt.get("Age");
ageBL.set(nbt.getInt("Age") < 0);
});
float age = 1;
if (itemStack.getComponents() != null && itemStack.contains(DataComponentTypes.BUCKET_ENTITY_DATA) && ageBL.get())
age = 0;
return age;
});
//Blue
FabricModelPredicateProviderRegistry.register(BLUE_AXOLOTL_BUCKET, Identifier.ofVanilla("age"), (itemStack, clientWorld, livingEntity, i) -> {
AtomicBoolean ageBL = new AtomicBoolean(false);
NbtComponent.set(DataComponentTypes.BUCKET_ENTITY_DATA, itemStack, nbt -> {
nbt.get("Age");
ageBL.set(nbt.getInt("Age") < 0);
});
float age = 1;
if (itemStack.getComponents() != null && itemStack.contains(DataComponentTypes.BUCKET_ENTITY_DATA) && ageBL.get())
age = 0;
return age;
});
}


Expand Down
71 changes: 53 additions & 18 deletions src/main/java/com/qzimyion/bucketem/ModEvents.java
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
package com.qzimyion.bucketem;

import com.qzimyion.bucketem.items.ModItems;
import net.fabricmc.fabric.api.event.player.UseEntityCallback;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.NbtComponent;
import net.minecraft.entity.Bucketable;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.mob.SlimeEntity;
import net.minecraft.entity.passive.AllayEntity;
import net.minecraft.entity.passive.BeeEntity;
import net.minecraft.entity.passive.FrogEntity;
import net.minecraft.entity.passive.FrogVariant;
import net.minecraft.entity.passive.*;
import net.minecraft.item.*;
import net.minecraft.registry.RegistryKeys;
import net.minecraft.registry.entry.RegistryEntry;
Expand All @@ -19,12 +15,12 @@
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.MathHelper;

import static com.qzimyion.bucketem.items.ModItems.*;
import static net.minecraft.item.Items.*;

@SuppressWarnings("deprecation")
@SuppressWarnings("deprecation, OptionalGetWithoutIsPresent")
public class ModEvents {

@SuppressWarnings("OptionalGetWithoutIsPresent")
public static void registerEvents() {

UseEntityCallback.EVENT.register(((player, world, hand, entity, hitResult) -> {
Expand All @@ -38,27 +34,66 @@ public static void registerEvents() {
RegistryEntry<FrogVariant> tropicalVariant = world.getRegistryManager().get(RegistryKeys.FROG_VARIANT).getEntry(FrogVariant.WARM).get();
RegistryEntry<FrogVariant> tundraVariant = world.getRegistryManager().get(RegistryKeys.FROG_VARIANT).getEntry(FrogVariant.COLD).get();
if (frog.getVariant()==temperateVariant){
bucket = new ItemStack(ModItems.TEMPERATE_FROG_BUCKET);
bucket = new ItemStack(TEMPERATE_FROG_BUCKET);
Bucketable.copyDataToStack(frog, bucket);
ItemStack itemstack = ItemUsage.exchangeStack(heldItem ,player, bucket, false);
player.setStackInHand(hand, itemstack);
entity.discard();
}
if (frog.getVariant()==tundraVariant){
bucket = new ItemStack(ModItems.TUNDRA_FROG_BUCKET);
bucket = new ItemStack(TUNDRA_FROG_BUCKET);
Bucketable.copyDataToStack(frog, bucket);
ItemStack itemstack = ItemUsage.exchangeStack(heldItem ,player, bucket, false);
player.setStackInHand(hand, itemstack);
entity.discard();
}
if (frog.getVariant()==tropicalVariant){
bucket = new ItemStack(ModItems.TROPICAL_FROG_BUCKET);
bucket = new ItemStack(TROPICAL_FROG_BUCKET);
Bucketable.copyDataToStack(frog, bucket);
ItemStack itemstack = ItemUsage.exchangeStack(heldItem ,player, bucket, false);
player.setStackInHand(hand, itemstack);
entity.discard();
}
}

//Axolotl Buckets
if (heldItem.getItem() == WATER_BUCKET && entity.isAlive() && entity instanceof AxolotlEntity axolotlEntity){
player.playSound(SoundEvents.ITEM_BUCKET_FILL_FISH, 1.0f, 1.0f);
ItemStack bucket;
if (axolotlEntity.getVariant()==AxolotlEntity.Variant.WILD){
bucket = new ItemStack(BROWN_AXOLOTL_BUCKET);
NbtComponent.set(DataComponentTypes.BUCKET_ENTITY_DATA, bucket, nbt -> nbt.putInt("Age", axolotlEntity.getBreedingAge()));
Bucketable.copyDataToStack(axolotlEntity, bucket);
ItemStack itemstack = ItemUsage.exchangeStack(heldItem ,player, bucket, false);
player.setStackInHand(hand, itemstack);
entity.discard();
}
if (axolotlEntity.getVariant()==AxolotlEntity.Variant.CYAN){
bucket = new ItemStack(CYAN_AXOLOTL_BUCKET);
NbtComponent.set(DataComponentTypes.BUCKET_ENTITY_DATA, bucket, nbt -> nbt.putInt("Age", axolotlEntity.getBreedingAge()));
Bucketable.copyDataToStack(axolotlEntity, bucket);
ItemStack itemstack = ItemUsage.exchangeStack(heldItem ,player, bucket, false);
player.setStackInHand(hand, itemstack);
entity.discard();
}
if (axolotlEntity.getVariant()==AxolotlEntity.Variant.BLUE){
bucket = new ItemStack(BLUE_AXOLOTL_BUCKET);
NbtComponent.set(DataComponentTypes.BUCKET_ENTITY_DATA, bucket, nbt -> nbt.putInt("Age", axolotlEntity.getBreedingAge()));
Bucketable.copyDataToStack(axolotlEntity, bucket);
ItemStack itemstack = ItemUsage.exchangeStack(heldItem ,player, bucket, false);
player.setStackInHand(hand, itemstack);
entity.discard();
}
if (axolotlEntity.getVariant()==AxolotlEntity.Variant.GOLD){
bucket = new ItemStack(GOLD_AXOLOTL_BUCKET);
NbtComponent.set(DataComponentTypes.BUCKET_ENTITY_DATA, bucket, nbt -> nbt.putInt("Age", axolotlEntity.getBreedingAge()));
Bucketable.copyDataToStack(axolotlEntity, bucket);
ItemStack itemstack = ItemUsage.exchangeStack(heldItem ,player, bucket, false);
player.setStackInHand(hand, itemstack);
entity.discard();
}
}

//Dry variant
if (heldItem.getItem() == BUCKET && entity.isAlive() && entity instanceof FrogEntity frog){
if (!player.isCreative()) heldItem.decrement(1);
Expand All @@ -68,21 +103,21 @@ public static void registerEvents() {
RegistryEntry<FrogVariant> tropicalVariant = world.getRegistryManager().get(RegistryKeys.FROG_VARIANT).getEntry(FrogVariant.WARM).get();
RegistryEntry<FrogVariant> tundraVariant = world.getRegistryManager().get(RegistryKeys.FROG_VARIANT).getEntry(FrogVariant.COLD).get();
if (frog.getVariant()==temperateVariant){
bucket = new ItemStack(ModItems.DRY_TEMPERATE_FROG_BUCKET);
bucket = new ItemStack(DRY_TEMPERATE_FROG_BUCKET);
Bucketable.copyDataToStack(frog, bucket);
ItemStack itemstack = ItemUsage.exchangeStack(heldItem ,player, bucket, false);
player.setStackInHand(hand, itemstack);
entity.discard();
}
if (frog.getVariant()==tundraVariant){
bucket = new ItemStack(ModItems.DRY_TUNDRA_FROG_BUCKET);
bucket = new ItemStack(DRY_TUNDRA_FROG_BUCKET);
Bucketable.copyDataToStack(frog, bucket);
ItemStack itemstack = ItemUsage.exchangeStack(heldItem ,player, bucket, false);
player.setStackInHand(hand, itemstack);
entity.discard();
}
if (frog.getVariant()==tropicalVariant){
bucket = new ItemStack(ModItems.DRY_TROPICAL_FROG_BUCKET);
bucket = new ItemStack(DRY_TROPICAL_FROG_BUCKET);
Bucketable.copyDataToStack(frog, bucket);
ItemStack itemstack = ItemUsage.exchangeStack(heldItem ,player, bucket, false);
player.setStackInHand(hand, itemstack);
Expand All @@ -92,7 +127,7 @@ public static void registerEvents() {

//Slimes
if (heldItem.getItem() == GLASS_BOTTLE && entity.isAlive() && entity instanceof SlimeEntity slime) {
ItemStack bottle = new ItemStack(ModItems.SLIME_BOTTLE);
ItemStack bottle = new ItemStack(SLIME_BOTTLE);
if (!player.isCreative()) heldItem.decrement(1);
int i = MathHelper.clamp(slime.getSize(), 2, 127);
if (slime.getType() == EntityType.SLIME && slime.getSize() == 1) {
Expand All @@ -108,7 +143,7 @@ public static void registerEvents() {
}
if (slime.getType() == EntityType.MAGMA_CUBE && slime.getSize() == 1) {
player.playSound(SoundEvents.ITEM_BOTTLE_FILL_DRAGONBREATH, 1.0f, 1.0f);
bottle = new ItemStack(ModItems.MAGMA_CUBE_BOTTLE);
bottle = new ItemStack(MAGMA_CUBE_BOTTLE);
Bucketable.copyDataToStack(slime, bottle);
ItemStack itemstack2 = ItemUsage.exchangeStack(heldItem, player, bottle, false);
player.setStackInHand(hand, itemstack2);
Expand All @@ -125,8 +160,7 @@ public static void registerEvents() {
if (heldItem.getItem() == GLASS_BOTTLE && entity.isAlive() && entity instanceof BeeEntity bee){
player.playSound(SoundEvents.ITEM_BOTTLE_FILL_DRAGONBREATH, 1.0f, 1.0f);
if (!player.isCreative()) heldItem.decrement(1);
Item bottle = ModItems.BEE_BOTTLE;
ItemStack bottleItem = new ItemStack(bottle);
ItemStack bottleItem = new ItemStack(BEE_BOTTLE);
NbtComponent.set(DataComponentTypes.BUCKET_ENTITY_DATA, bottleItem, nbt ->
{
nbt.putBoolean("HasNectar", bee.hasNectar());
Expand All @@ -146,10 +180,11 @@ public static void registerEvents() {
}

//Allay
//RegistryEntry<Enchantment> cursed = world.getRegistryManager().get(RegistryKeys.ENCHANTMENT).getEntry(Enchantments.BINDING_CURSE).get();
if (heldItem.getItem() == BOOK && player.isSneaking() && entity.isAlive() && entity instanceof AllayEntity allay){
player.playSound(SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE, 1.0f, 1.0f);
if (!player.isCreative()) heldItem.decrement(1);
ItemStack newStack = ModItems.ALLAY_POSSESSED_BOOK.getDefaultStack();
ItemStack newStack = ALLAY_POSSESSED_BOOK.getDefaultStack();
NbtComponent.set(DataComponentTypes.BUCKET_ENTITY_DATA, newStack, nbt ->
{
allay.writeInventory(nbt, allay.getRegistryManager());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,10 @@ protected ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
DispenserBlock.registerBehavior(TROPICAL_FROG_BUCKET, new ItemDispenserBehavior());
DispenserBlock.registerBehavior(TUNDRA_FROG_BUCKET, new ItemDispenserBehavior());
DispenserBlock.registerBehavior(TURTLE_BUCKET, new ItemDispenserBehavior());
DispenserBlock.registerBehavior(BROWN_AXOLOTL_BUCKET, new ItemDispenserBehavior());
DispenserBlock.registerBehavior(CYAN_AXOLOTL_BUCKET, new ItemDispenserBehavior());
DispenserBlock.registerBehavior(GLOW_SQUID_BUCKET, new ItemDispenserBehavior());
DispenserBlock.registerBehavior(BLUE_AXOLOTL_BUCKET, new ItemDispenserBehavior());

//Books
DispenserBlock.registerBehavior(ALLAY_POSSESSED_BOOK, BookDispenserBehavior);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.registry.Registries;
import net.minecraft.registry.Registry;
import net.minecraft.util.Identifier;
import net.minecraft.util.dynamic.Codecs;

public class ModDataComponents {

Expand All @@ -15,6 +16,12 @@ public class ModDataComponents {
ComponentType.<Boolean>builder().codec(Codec.BOOL).build()
);

public static final ComponentType<Integer> FLUID_LEVEL = Registry.register(
Registries.DATA_COMPONENT_TYPE,
Identifier.of(Bucketem.MOD_ID, "fluidlevel"),
ComponentType.<Integer>builder().codec(Codecs.rangedInt(0, 2)).codec(Codec.INT).build()
);

public static void registerComponents() {
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ public static void registerItemGroups(){
content.addAfter(TADPOLE_BUCKET, DRY_TEMPERATE_FROG_BUCKET, DRY_TUNDRA_FROG_BUCKET, DRY_TROPICAL_FROG_BUCKET, TEMPERATE_FROG_BUCKET, TUNDRA_FROG_BUCKET, TROPICAL_FROG_BUCKET,
DRY_TEMPERATE_FROG_BUCKET, DRY_TROPICAL_FROG_BUCKET, DRY_TUNDRA_FROG_BUCKET, GLOW_SQUID_BUCKET, SQUID_BUCKET, TURTLE_BUCKET);
content.addAfter(MILK_BUCKET, BEE_BOTTLE, SILVERFISH_BOTTLE, ENDERMITE_BOTTLE, SLIME_BOTTLE, MAGMA_CUBE_BOTTLE, ALLAY_POSSESSED_BOOK, VEX_POSSESSED_BOOK);
content.addAfter(AXOLOTL_BUCKET, BROWN_AXOLOTL_BUCKET, CYAN_AXOLOTL_BUCKET, GOLD_AXOLOTL_BUCKET, BLUE_AXOLOTL_BUCKET);
});


Expand Down
Loading

0 comments on commit 4e8acae

Please sign in to comment.