Skip to content

Commit

Permalink
Merge branch '1.19.2' into 1.20.1
Browse files Browse the repository at this point in the history
  • Loading branch information
iron431 committed Aug 10, 2024
2 parents 361b3cd + 3ec88df commit c1c10ef
Show file tree
Hide file tree
Showing 49 changed files with 1,077 additions and 496 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,17 @@
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.*;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.BooleanOp;
import net.minecraft.world.phys.shapes.CollisionContext;
Expand All @@ -38,7 +40,7 @@
public class AlchemistCauldronBlock extends BaseEntityBlock {
public AlchemistCauldronBlock() {
super(Properties.copy(Blocks.CAULDRON).lightLevel((blockState) -> 3));
this.registerDefaultState(this.stateDefinition.any().setValue(LIT, false).setValue(LEVEL, 0));
this.registerDefaultState(this.stateDefinition.any().setValue(LIT, true)/*.setValue(LEVEL, 0)*/);

}

Expand All @@ -53,8 +55,8 @@ public AlchemistCauldronBlock() {
private static final VoxelShape SHAPE = Shapes.or(Shapes.or(box(0, 0, 4, 16, 2, 6), box(0, 0, 10, 16, 2, 12), box(4, 0, 0, 6, 2, 16), box(10, 0, 0, 12, 2, 16)), Shapes.join(Shapes.or(Shapes.join(box(0, 2, 0, 16, 16, 16), box(0, 12, 0, 16, 14, 16), BooleanOp.ONLY_FIRST), box(1, 12, 1, 15, 14, 15)), box(2, 4, 2, 14, 16, 14), BooleanOp.ONLY_FIRST));

public static final BooleanProperty LIT = BlockStateProperties.LIT;
public static final int MAX_LEVELS = 4;
public static final IntegerProperty LEVEL = IntegerProperty.create("level", 0, MAX_LEVELS);
//public static final int MAX_LEVELS = 4;
//public static final IntegerProperty LEVEL = IntegerProperty.create("level", 0, MAX_LEVELS);

@Override
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level pLevel, BlockState pState, BlockEntityType<T> pBlockEntityType) {
Expand All @@ -68,35 +70,35 @@ protected static <T extends BlockEntity> BlockEntityTicker<T> createTicker(Level

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(LIT, LEVEL);
builder.add(LIT/*, LEVEL*/);
}

public VoxelShape getShape(BlockState pState, BlockGetter pLevel, BlockPos pPos, CollisionContext pContext) {
return SHAPE;
}

@Override
public InteractionResult use(BlockState blockState, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult blockHit) {
public InteractionResult use(BlockState pState, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult pHit) {
if (level.getBlockEntity(pos) instanceof AlchemistCauldronTile tile) {
return tile.handleUse(blockState, level, pos, player, hand);
return tile.handleUse(level.getBlockState(pos), level, pos, player, hand);
}
return super.use(blockState, level, pos, player, hand, blockHit);
return super.use(pState, level, pos, player, hand, pHit);
}

@Override
public void entityInside(BlockState blockState, Level level, BlockPos pos, Entity entity) {
if (entity.tickCount % 20 == 0) {
if (isBoiling(blockState)) {
if (entity instanceof LivingEntity livingEntity && livingEntity.hurt(DamageSources.get(level, ISSDamageTypes.CAULDRON), 2)) {
MagicManager.spawnParticles(level, ParticleHelper.BLOOD, entity.getX(), entity.getY() + entity.getBbHeight() / 2, entity.getZ(), 20, .05, .05, .05, .1, false);
if (level.getBlockEntity(pos) instanceof AlchemistCauldronTile cauldronTile) {
AlchemistCauldronTile.appendItem(cauldronTile.resultItems, new ItemStack(ItemRegistry.BLOOD_VIAL.get()));
cauldronTile.setChanged();
if (level.getBlockEntity(pos) instanceof AlchemistCauldronTile cauldronTile) {
if (AlchemistCauldronBlock.isLit(blockState)) {
if (entity instanceof LivingEntity livingEntity && livingEntity.hurt(DamageSources.get(level, ISSDamageTypes.CAULDRON), 2)) {
MagicManager.spawnParticles(level, ParticleHelper.BLOOD, entity.getX(), entity.getY() + entity.getBbHeight() / 2, entity.getZ(), 20, .05, .05, .05, .1, false);
if (cauldronTile.addToOutput(new ItemStack(ItemRegistry.BLOOD_VIAL.get()))) {
cauldronTile.setChanged();
}
}
}
}
}

super.entityInside(blockState, level, pos, entity);
}

Expand Down Expand Up @@ -150,12 +152,4 @@ public static boolean isLit(BlockState blockState) {
return blockState.hasProperty(LIT) && blockState.getValue(LIT);
}

public static int getLevel(BlockState blockState) {
return blockState.hasProperty(LEVEL) ? blockState.getValue(LEVEL) : 0;
}

public static boolean isBoiling(BlockState blockState) {
return isLit(blockState) && getLevel(blockState) > 0;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package io.redspace.ironsspellbooks.block.alchemist_cauldron;

import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.world.item.Item;
import net.minecraftforge.eventbus.api.Event;

public class AlchemistCauldronBuildInteractionsEvent extends Event {
private final Object2ObjectOpenHashMap<Item, AlchemistCauldronInteraction> interactionMap;

public AlchemistCauldronBuildInteractionsEvent(Object2ObjectOpenHashMap<Item, AlchemistCauldronInteraction> interactionMap) {
this.interactionMap = interactionMap;
}

public void addInteraction(Item item, AlchemistCauldronInteraction interaction) {
if (!interactionMap.containsKey(item)) {
interactionMap.put(item, interaction);
}
}

public void addSimpleBottleEmptyInteraction(Item item) {
if (!interactionMap.containsKey(item)) {
AlchemistCauldronTile.createBottleEmptyInteraction(interactionMap, () -> item);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
package io.redspace.ironsspellbooks.block.alchemist_cauldron;

import net.minecraft.core.BlockPos;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;

import javax.annotation.Nullable;

public interface AlchemistCauldronInteraction{
public interface AlchemistCauldronInteraction {
@Nullable
ItemStack interact(BlockState blockState, Level level, BlockPos pos, int currentLevel, ItemStack itemStack);
ItemStack interact(AlchemistCauldronTile blockEntity, BlockState blockState, Level level, BlockPos pos, ItemStack itemStack);
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,13 @@
package io.redspace.ironsspellbooks.block.alchemist_cauldron;

import com.google.common.collect.ImmutableList;
import io.redspace.ironsspellbooks.IronsSpellbooks;
import io.redspace.ironsspellbooks.registries.ItemRegistry;
import io.redspace.ironsspellbooks.registries.PotionRegistry;
import net.minecraft.core.NonNullList;
import io.redspace.ironsspellbooks.api.util.Utils;
import net.minecraft.core.Holder;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.alchemy.Potion;
import net.minecraft.world.item.alchemy.PotionUtils;

import java.util.ArrayList;
import java.util.List;

public class AlchemistCauldronRecipe {

//Base is the item inside the cauldron being acted on
Expand Down Expand Up @@ -48,9 +42,9 @@ public AlchemistCauldronRecipe setResultLimit(int i) {
return this;
}

public ItemStack createOutput(ItemStack input, ItemStack ingredient, boolean consumeOnSuccess) {
if (ItemStack.isSameItemSameTags(input, this.inputStack) && ItemStack.isSameItemSameTags(ingredient, this.ingredientStack)) {
if (input.getCount() >= this.requiredBaseCount) {
public ItemStack createOutput(ItemStack input, ItemStack ingredient, boolean ignoreCount, boolean consumeOnSuccess) {
if (CauldronPlatformHelper.itemMatches(input, this.inputStack) && CauldronPlatformHelper.itemMatches(ingredient, this.ingredientStack)) {
if (ignoreCount || input.getCount() >= this.requiredBaseCount) {
ItemStack result = this.resultStack.copy();
result.setCount(this.resultLimitCount);
if (consumeOnSuccess) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@
import io.redspace.ironsspellbooks.IronsSpellbooks;
import io.redspace.ironsspellbooks.registries.ItemRegistry;
import io.redspace.ironsspellbooks.registries.PotionRegistry;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.alchemy.PotionUtils;
import net.minecraft.world.item.alchemy.Potions;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.List;
import java.util.HashMap;
import java.util.Map;

public class AlchemistCauldronRecipeRegistry {
private static final List<AlchemistCauldronRecipe> recipes = new ArrayList<>();
private static final Map<ResourceLocation, AlchemistCauldronRecipe> recipes = new HashMap<>();

static {
//No cool recipes for right now :(
Expand All @@ -22,38 +24,57 @@ public class AlchemistCauldronRecipeRegistry {
//recipes.add(new AlchemistCauldronRecipe(ItemRegistry.INK_EPIC.get(), Items.OBSIDIAN, Items.CRYING_OBSIDIAN));
//recipes.add(new AlchemistCauldronRecipe(ItemRegistry.INK_LEGENDARY.get(), Items.BLUE_ORCHID, Items.DANDELION).setBaseRequirement(2).setResultLimit(2));
// recipes.add(new AlchemistCauldronRecipe(PotionRegistry.INSTANT_MANA_ONE.get(), Items.FLOWERING_AZALEA_LEAVES, ItemRegistry.CASTERS_TEA.get()));
recipes.add(new AlchemistCauldronRecipe(Potions.STRONG_HEALING, Items.OAK_LOG, ItemRegistry.OAKSKIN_ELIXIR.get()).setBaseRequirement(2).setResultLimit(1));
recipes.add(new AlchemistCauldronRecipe(ItemRegistry.OAKSKIN_ELIXIR.get(), Items.AMETHYST_SHARD, ItemRegistry.GREATER_OAKSKIN_ELIXIR.get()).setBaseRequirement(2).setResultLimit(1));
recipes.add(new AlchemistCauldronRecipe(Potions.STRONG_HEALING, Items.AMETHYST_SHARD, ItemRegistry.GREATER_HEALING_POTION.get()).setBaseRequirement(4).setResultLimit(1));
recipes.add(new AlchemistCauldronRecipe(Potions.INVISIBILITY, ItemRegistry.SHRIVING_STONE.get(), ItemRegistry.INVISIBILITY_ELIXIR.get()).setBaseRequirement(4).setResultLimit(1));
recipes.add(new AlchemistCauldronRecipe(Potions.LONG_INVISIBILITY, ItemRegistry.SHRIVING_STONE.get(), ItemRegistry.INVISIBILITY_ELIXIR.get()).setBaseRequirement(4).setResultLimit(1));
recipes.add(new AlchemistCauldronRecipe(ItemRegistry.INVISIBILITY_ELIXIR.get(), Items.AMETHYST_CLUSTER, ItemRegistry.GREATER_INVISIBILITY_ELIXIR.get()));
recipes.add(new AlchemistCauldronRecipe(PotionRegistry.INSTANT_MANA_THREE.get(), Items.ENDER_PEARL, ItemRegistry.EVASION_ELIXIR.get()).setBaseRequirement(4).setResultLimit(1));
recipes.add(new AlchemistCauldronRecipe(ItemRegistry.EVASION_ELIXIR.get(), Items.DRAGON_BREATH, ItemRegistry.GREATER_EVASION_ELIXIR.get()));
recipes.add(new AlchemistCauldronRecipe(ItemRegistry.INK_COMMON.get(), Items.COPPER_INGOT, ItemRegistry.INK_UNCOMMON.get()).setBaseRequirement(4).setResultLimit(1));
recipes.add(new AlchemistCauldronRecipe(ItemRegistry.INK_UNCOMMON.get(), Items.IRON_INGOT, ItemRegistry.INK_RARE.get()).setBaseRequirement(4).setResultLimit(1));
recipes.add(new AlchemistCauldronRecipe(ItemRegistry.INK_RARE.get(), Items.GOLD_INGOT, ItemRegistry.INK_EPIC.get()).setBaseRequirement(4).setResultLimit(1));
recipes.add(new AlchemistCauldronRecipe(ItemRegistry.INK_EPIC.get(), Items.AMETHYST_SHARD, ItemRegistry.INK_LEGENDARY.get()).setBaseRequirement(4).setResultLimit(1));
addRecipe(new AlchemistCauldronRecipe(Potions.STRONG_HEALING, Items.OAK_LOG, ItemRegistry.OAKSKIN_ELIXIR.get()).setBaseRequirement(2).setResultLimit(1));
addRecipe(new AlchemistCauldronRecipe(ItemRegistry.OAKSKIN_ELIXIR.get(), Items.AMETHYST_SHARD, ItemRegistry.GREATER_OAKSKIN_ELIXIR.get()).setBaseRequirement(2).setResultLimit(1));
addRecipe(new AlchemistCauldronRecipe(Potions.STRONG_HEALING, Items.AMETHYST_SHARD, ItemRegistry.GREATER_HEALING_POTION.get()).setBaseRequirement(4).setResultLimit(1));
addRecipe(new AlchemistCauldronRecipe(Potions.INVISIBILITY, ItemRegistry.SHRIVING_STONE.get(), ItemRegistry.INVISIBILITY_ELIXIR.get()).setBaseRequirement(4).setResultLimit(1));
addRecipe(new AlchemistCauldronRecipe(Potions.LONG_INVISIBILITY, ItemRegistry.SHRIVING_STONE.get(), ItemRegistry.INVISIBILITY_ELIXIR.get()).setBaseRequirement(4).setResultLimit(1));
addRecipe(new AlchemistCauldronRecipe(ItemRegistry.INVISIBILITY_ELIXIR.get(), Items.AMETHYST_CLUSTER, ItemRegistry.GREATER_INVISIBILITY_ELIXIR.get()));
addRecipe(new AlchemistCauldronRecipe(PotionRegistry.INSTANT_MANA_THREE.get(), Items.ENDER_PEARL, ItemRegistry.EVASION_ELIXIR.get()).setBaseRequirement(4).setResultLimit(1));
addRecipe(new AlchemistCauldronRecipe(ItemRegistry.EVASION_ELIXIR.get(), Items.DRAGON_BREATH, ItemRegistry.GREATER_EVASION_ELIXIR.get()));
addRecipe(new AlchemistCauldronRecipe(ItemRegistry.INK_COMMON.get(), Items.COPPER_INGOT, ItemRegistry.INK_UNCOMMON.get()).setBaseRequirement(4).setResultLimit(1));
addRecipe(new AlchemistCauldronRecipe(ItemRegistry.INK_UNCOMMON.get(), Items.IRON_INGOT, ItemRegistry.INK_RARE.get()).setBaseRequirement(4).setResultLimit(1));
addRecipe(new AlchemistCauldronRecipe(ItemRegistry.INK_RARE.get(), Items.GOLD_INGOT, ItemRegistry.INK_EPIC.get()).setBaseRequirement(4).setResultLimit(1));
addRecipe(new AlchemistCauldronRecipe(ItemRegistry.INK_EPIC.get(), Items.AMETHYST_SHARD, ItemRegistry.INK_LEGENDARY.get()).setBaseRequirement(4).setResultLimit(1));

}

/**
* If any modder is crazy enough to want to use this, do it during FMLCommonSetup Event
* Use this during FMLCommonSetup Event for custom recipes while better API handling is WIP
*/
public static AlchemistCauldronRecipe addRecipe(AlchemistCauldronRecipe recipe) {
recipes.add(recipe);
public static AlchemistCauldronRecipe registerRecipe(ResourceLocation resourceLocation, AlchemistCauldronRecipe recipe) {
recipes.put(resourceLocation, recipe);
return recipe;
}

private static AlchemistCauldronRecipe addRecipe(AlchemistCauldronRecipe recipe) {
recipes.put(IronsSpellbooks.id(ForgeRegistries.ITEMS.getKey(recipe.getResult().getItem()).getPath()), recipe);
return recipe;
}


/**
* Searches through registered recipes, and returns the resulting item or ItemStack.EMPTY if there are no matches.
* It is expected for input to have a consolidated count, and the result can have a count > 1
* Input without the required count will return negative, and the result can have a count > 1
*/
public static ItemStack getOutput(ItemStack input, ItemStack ingredient, boolean consumeOnSucces) {
if (input.isEmpty() || ingredient.isEmpty()) return ItemStack.EMPTY;
for (AlchemistCauldronRecipe recipe : recipes) {
ItemStack result = recipe.createOutput(input, ingredient, consumeOnSucces);
for (AlchemistCauldronRecipe recipe : recipes.values()) {
ItemStack result = recipe.createOutput(input, ingredient, false, consumeOnSucces);
if (!result.isEmpty()) {
return result;
}
}
return ItemStack.EMPTY;
}

/**
* Searches through registered recipes, and returns the resulting item or ItemStack.EMPTY if there are no matches
*/
public static ItemStack getOutput(ItemStack input, ItemStack ingredient, boolean ignoreCount, boolean consumeOnSucces) {
if (input.isEmpty() || ingredient.isEmpty()) return ItemStack.EMPTY;
for (AlchemistCauldronRecipe recipe : recipes.values()) {
ItemStack result = recipe.createOutput(input, ingredient, ignoreCount, consumeOnSucces);
if (!result.isEmpty()) {
return result;
}
Expand All @@ -65,8 +86,8 @@ public static ItemStack getOutput(ItemStack input, ItemStack ingredient, boolean
* Returns if any cauldron recipe has this as the ingredient
*/
public static boolean isValidIngredient(ItemStack itemStack) {
for (AlchemistCauldronRecipe recipe : recipes) {
if (ItemStack.isSameItemSameTags(recipe.getIngredient(), itemStack))
for (AlchemistCauldronRecipe recipe : recipes.values()) {
if (CauldronPlatformHelper.itemMatches(recipe.getIngredient(), itemStack))
return true;
}
return false;
Expand All @@ -76,13 +97,33 @@ public static boolean isValidIngredient(ItemStack itemStack) {
* Returns if this combination of items (the count of input matters) yields a result
*/
public static boolean hasOutput(ItemStack input, ItemStack ingredient) {
return !getOutput(input, ingredient, false).isEmpty();
return !getOutput(input, ingredient, true, false).isEmpty();
}

@Nullable
public static AlchemistCauldronRecipe getRecipeForResult(ItemStack result) {
for (AlchemistCauldronRecipe recipe : recipes.values()) {
if (CauldronPlatformHelper.itemMatches(result, recipe.getResult())) {
return recipe;
}
}
return null;
}

@Nullable
public static AlchemistCauldronRecipe getRecipeForInputs(ItemStack base, ItemStack reagent) {
for (AlchemistCauldronRecipe recipe : recipes.values()) {
if (CauldronPlatformHelper.itemMatches(base, recipe.getInput()) && CauldronPlatformHelper.itemMatches(reagent, recipe.getIngredient())) {
return recipe;
}
}
return null;
}

/**
* Returns an immutable list of all "registered" recipes
* Returns an immutable list of all registered recipes
*/
public static ImmutableList<AlchemistCauldronRecipe> getRecipes() {
return ImmutableList.copyOf(recipes);
return ImmutableList.copyOf(recipes.values());
}
}
Loading

0 comments on commit c1c10ef

Please sign in to comment.