Skip to content

Commit

Permalink
treetap adjustments #796
Browse files Browse the repository at this point in the history
  • Loading branch information
MBatt1 committed May 7, 2024
1 parent c2104db commit 15eef6a
Show file tree
Hide file tree
Showing 8 changed files with 68 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package net.id.paradiselost.blocks.blockentity;

import net.id.paradiselost.blocks.mechanical.TreeTapBlock;
import net.id.paradiselost.recipe.ParadiseLostRecipeTypes;
import net.id.paradiselost.recipe.TreeTapRecipe;
import net.minecraft.block.BeehiveBlock;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.HopperBlockEntity;
import net.minecraft.block.entity.LootableContainerBlockEntity;
Expand All @@ -28,7 +32,6 @@
import net.minecraft.util.math.Direction;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Optional;

public class TreeTapBlockEntity extends LootableContainerBlockEntity implements SidedInventory {
Expand Down Expand Up @@ -134,12 +137,29 @@ public void tryCraft() {
Optional<TreeTapRecipe> recipe = this.world.getRecipeManager().getFirstMatch(ParadiseLostRecipeTypes.TREE_TAP_RECIPE_TYPE, this, this.world);
if (recipe.isPresent() && world.random.nextInt(recipe.get().getChance()) == 0) {
ItemStack output = recipe.get().craft(this);
stack.decrement(1);
Block convertBlock = recipe.get().getOutputBlock();
BlockPos attachedPos = this.pos.offset(world.getBlockState(this.pos).get(TreeTapBlock.FACING).getOpposite());
BlockState attachedBlock = world.getBlockState(attachedPos);
if (convertBlock != Blocks.BEE_NEST) {
stack.decrement(1);

if (!world.isClient) world.playSound(null, pos, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.BLOCKS, 0.5f, world.getRandom().nextFloat() * 0.4f + 0.8f);
if (convertBlock != world.getBlockState(this.pos).getBlock()) {
world.setBlockState(attachedPos, convertBlock.getDefaultState(), 0);
}
if (!world.isClient) world.playSound(null, pos, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.BLOCKS, 0.5f, world.getRandom().nextFloat() * 0.4f + 0.8f);

this.inventory.set(0, output);
inventoryChanged();
this.inventory.set(0, output);
inventoryChanged();
} else if (attachedBlock.get(BeehiveBlock.HONEY_LEVEL) == 5) {
stack.decrement(1);

world.setBlockState(attachedPos, attachedBlock.with(BeehiveBlock.HONEY_LEVEL, 0));

if (!world.isClient) world.playSound(null, pos, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.BLOCKS, 0.5f, world.getRandom().nextFloat() * 0.4f + 0.8f);

this.inventory.set(0, output);
inventoryChanged();
}
}
tryTansferItemsOut();
}
Expand Down
8 changes: 7 additions & 1 deletion src/main/java/net/id/paradiselost/recipe/TreeTapRecipe.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@ public class TreeTapRecipe implements Recipe<TreeTapBlockEntity> {
protected final Ingredient ingredient;
protected final ItemStack output;
protected final Block tappedBlock;
protected final Block resultBlock;
protected final int chance;

public TreeTapRecipe(Identifier id, String group, Ingredient ingredient, ItemStack output, Block tappedBlock, int chance) {
public TreeTapRecipe(Identifier id, String group, Ingredient ingredient, ItemStack output, Block tappedBlock, Block resultBlock, int chance) {
this.id = id;
this.group = group;
this.ingredient = ingredient;
this.output = output;
this.tappedBlock = tappedBlock;
this.resultBlock = resultBlock;
this.chance = chance;
}

Expand Down Expand Up @@ -53,6 +55,10 @@ public ItemStack getOutput() {
return output;
}

public Block getOutputBlock() {
return resultBlock;
}

@Override
public String getGroup() {
return group;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,25 +14,27 @@
public record TreeTapRecipeSerializer(TreeTapRecipeSerializer.RecipeFactory recipeFactory) implements RecipeSerializer<TreeTapRecipe> {

public interface RecipeFactory {
TreeTapRecipe create(Identifier id, String group, Ingredient ingredient, ItemStack output, Block tappedBlock, int chance);
TreeTapRecipe create(Identifier id, String group, Ingredient ingredient, ItemStack output, Block tappedBlock, Block resultBlock, int chance);
}

@Override
public TreeTapRecipe read(Identifier identifier, JsonObject jsonObject) {
String group = JsonHelper.getString(jsonObject, "group", "");
Ingredient ingredient = Ingredient.fromJson(JsonHelper.getObject(jsonObject, "ingredient"));
Block tappedBlock = Registry.BLOCK.get(Identifier.tryParse(JsonHelper.getString(jsonObject, "tapped_block")));
Block tappedBlock = Registry.BLOCK.get(Identifier.tryParse(JsonHelper.getString(jsonObject, "tapped_block")));
Block resultBlock = Registry.BLOCK.get(Identifier.tryParse(JsonHelper.getString(jsonObject, "result_block")));
ItemStack output = RecipeParser.getItemStackWithNbtFromJson(JsonHelper.getObject(jsonObject, "result"));
int chance = JsonHelper.getInt(jsonObject, "chance");

return this.recipeFactory.create(identifier, group, ingredient, output, tappedBlock, chance);
return this.recipeFactory.create(identifier, group, ingredient, output, tappedBlock, resultBlock, chance);
}

@Override
public void write(PacketByteBuf packetByteBuf, TreeTapRecipe recipe) {
packetByteBuf.writeString(recipe.group);
recipe.ingredient.write(packetByteBuf);
packetByteBuf.writeIdentifier(Registry.BLOCK.getId(recipe.tappedBlock));
packetByteBuf.writeIdentifier(Registry.BLOCK.getId(recipe.tappedBlock));
packetByteBuf.writeIdentifier(Registry.BLOCK.getId(recipe.resultBlock));
packetByteBuf.writeItemStack(recipe.output);
packetByteBuf.writeInt(recipe.chance);
}
Expand All @@ -41,11 +43,12 @@ public void write(PacketByteBuf packetByteBuf, TreeTapRecipe recipe) {
public TreeTapRecipe read(Identifier identifier, PacketByteBuf packetByteBuf) {
String group = packetByteBuf.readString();
Ingredient ingredient = Ingredient.fromPacket(packetByteBuf);
Block tappedBlock = Registry.BLOCK.get(packetByteBuf.readIdentifier());
Block tappedBlock = Registry.BLOCK.get(packetByteBuf.readIdentifier());
Block resultBlock = Registry.BLOCK.get(packetByteBuf.readIdentifier());
ItemStack output = packetByteBuf.readItemStack();
int chance = packetByteBuf.readInt();

return this.recipeFactory.create(identifier, group, ingredient, output, tappedBlock, chance);
return this.recipeFactory.create(identifier, group, ingredient, output, tappedBlock, resultBlock, chance);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"item": "minecraft:glass_bottle"
},
"tapped_block": "minecraft:bee_nest",
"result_block": "minecraft:bee_nest",
"result": {
"item": "minecraft:honey_bottle"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"item": "minecraft:bowl"
},
"tapped_block": "minecraft:mushroom_stem",
"result_block": "minecraft:mushroom_stem",
"result": {
"item": "minecraft:mushroom_stew"
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
"item": "minecraft:glass_bottle"
},
"tapped_block": "paradise_lost:wisteria_log",
"result_block": "paradise_lost:wisteria_log",
"result": {
"item": "minecraft:potion",
"nbt": "{Potion: \"minecraft:water\"}"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "paradise_lost:tree_tap",
"ingredient": {
"item": "paradise_lost:aurel_bucket"
},
"tapped_block": "paradise_lost:wisteria_log",
"result_block": "paradise_lost:wisteria_log",
"result": {
"item": "paradise_lost:aurel_water_bucket"
},
"chance": 2
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"type": "paradise_lost:tree_tap",
"ingredient": {
"item": "minecraft:bucket"
},
"tapped_block": "paradise_lost:wisteria_log",
"result_block": "paradise_lost:wisteria_log",
"result": {
"item": "minecraft:water_bucket"
},
"chance": 2
}

0 comments on commit 15eef6a

Please sign in to comment.