Skip to content

Commit

Permalink
feat: add Acid Cauldron
Browse files Browse the repository at this point in the history
  • Loading branch information
kd8lvt authored Jul 17, 2024
1 parent eee7c57 commit 749669e
Show file tree
Hide file tree
Showing 17 changed files with 199 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -623,6 +623,8 @@ private void addBlockTranslations() {

addBlock(ModBlocks.PRIMAL_ORIFICE, "Primal Orifice", "A primitive piece full of holes that seems to generate and leak acidic juices.\nIt can be milked with buckets and bottles.");
addBlock(ModBlocks.ACID_FLUID_BLOCK, "Gastric Acid");

addBlock(ModBlocks.ACID_CAULDRON,"Gastric Acid Cauldron");
}

private void addEntityTranslations() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -572,6 +572,7 @@ private void addBlockTranslations() {
addBlock(ModBlocks.PRIMAL_ORIFICE, "Oozin' Flesh", "An ancient hunk o' flesh that be full of holes. It be leakin' somethin' acidic.");

addBlock(ModBlocks.ACID_FLUID_BLOCK, "Acid");
addBlock(ModBlocks.ACID_CAULDRON, "Pot o' Acid");
}

private void addEntityTranslations() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ protected LootTable.Builder createFleshSpikeTable(FleshSpikeBlock block) {
))));
}

protected LootTable.Builder drop(Item item) {
return LootTable.lootTable().withPool(LootPool.lootPool()
.setRolls(ConstantValue.exactly(1))
.add(applyExplosionDecay(item,LootItem.lootTableItem(item))));
}

@Override
protected void generate() {
LOGGER.info(logMarker, "registering block loot...");
Expand Down Expand Up @@ -240,6 +246,7 @@ protected void generate() {
addCustom(ModBlocks.FLESH_SPIKE.get(), this::createFleshSpikeTable);

add(ModBlocks.ACID_FLUID_BLOCK.get(), noDrop());
add(ModBlocks.ACID_CAULDRON.get(), drop(Items.CAULDRON));
}

protected <T extends Block> void addCustom(T block, Function<T, LootTable.Builder> function) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,15 @@ protected void registerStatesAndModels() {
directionalBlockWithItem(ModBlocks.CHRYSALIS.get());

particleOnly(ModBlocks.ACID_FLUID_BLOCK, new ResourceLocation("biomancy:block/acid_flat"));

cauldron(ModBlocks.ACID_CAULDRON,new ResourceLocation("biomancy:fluid/acid_overlay"));
}

public <T extends Block> void cauldron(RegistryObject<T> block, ResourceLocation fluidTexture) {
BlockModelBuilder model = models().withExistingParent(path(block.get()),"minecraft:block/lava_cauldron")
.texture("content",fluidTexture);

simpleBlock(block.get(),model);
}

public <T extends Block> void particleOnly(RegistryObject<T> block, ResourceLocation particleTexture) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.block.AbstractCauldronBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraftforge.common.Tags;
Expand Down Expand Up @@ -115,7 +116,10 @@ protected void addTags(HolderLookup.Provider provider) {

private void addFleshyBlocksToHoeTag() {
IntrinsicTagAppender<Block> tag = tag(BlockTags.MINEABLE_WITH_HOE);
ModBlocks.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach(tag::add);
ModBlocks.BLOCKS.getEntries().stream().map(RegistryObject::get).forEach((block)->{
if (block instanceof AbstractCauldronBlock) tag(BlockTags.MINEABLE_WITH_PICKAXE).add(block); //Lazy hack to get around Elen's lazy hack :P
else tag.add(block);
});
}

/**
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "biomancy:block/acid_cauldron"
}
}
}
1 change: 1 addition & 0 deletions src/generated/resources/assets/biomancy/lang/en_pt.json
Original file line number Diff line number Diff line change
Expand Up @@ -261,6 +261,7 @@
"block.biomancy.primal_orifice": "Oozin' Flesh",
"block.biomancy.primal_orifice.tooltip": "An ancient hunk o' flesh that be full of holes. It be leakin' somethin' acidic.",
"block.biomancy.acid_fluid_block": "Acid",
"block.biomancy.acid_cauldron": "Pot o' Acid",
"fluid_type.biomancy.acid": "Acid",
"entity.biomancy.hungry_flesh_blob": "Hungry Cube o' Flesh",
"entity.biomancy.flesh_blob": "Cube o' Flesh",
Expand Down
1 change: 1 addition & 0 deletions src/generated/resources/assets/biomancy/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,7 @@
"block.biomancy.primal_orifice": "Primal Orifice",
"block.biomancy.primal_orifice.tooltip": "A primitive piece full of holes that seems to generate and leak acidic juices.\nIt can be milked with buckets and bottles.",
"block.biomancy.acid_fluid_block": "Gastric Acid",
"block.biomancy.acid_cauldron": "Gastric Acid Cauldron",
"fluid_type.biomancy.acid": "Acid",
"entity.biomancy.hungry_flesh_blob": "Hungry Flesh Blob",
"entity.biomancy.flesh_blob": "Flesh Blob",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:block/lava_cauldron",
"textures": {
"content": "biomancy:fluid/acid_overlay"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"entries": [
{
"type": "minecraft:item",
"functions": [
{
"function": "minecraft:explosion_decay"
}
],
"name": "minecraft:cauldron"
}
],
"rolls": 1.0
}
],
"random_sequence": "biomancy:blocks/acid_cauldron"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"values": [
"biomancy:acid_cauldron"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
package com.github.elenterius.biomancy.block.cauldron;

import com.github.elenterius.biomancy.fluid.AcidFluid;
import com.github.elenterius.biomancy.init.ModFluids;
import com.github.elenterius.biomancy.init.ModItems;
import net.minecraft.core.BlockPos;
import net.minecraft.core.cauldron.CauldronInteraction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AbstractCauldronBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.common.SoundActions;
import net.minecraftforge.registries.ForgeRegistries;
import org.jetbrains.annotations.NotNull;

import java.util.Map;
import java.util.Objects;

public class AcidCauldron extends AbstractCauldronBlock {
public AcidCauldron() {
super(Properties.copy(Blocks.CAULDRON),getInteractions());
}

private static Map<Item, CauldronInteraction> getInteractions() {
Map<Item,CauldronInteraction> map = CauldronInteraction.newInteractionMap();
map.put(Items.BUCKET, (pBlockState, pLevel, pPos, pPlayer, pHand, pEmptyStack) -> CauldronInteraction.fillBucket(pBlockState, pLevel, pPos, pPlayer, pHand, pEmptyStack, ModItems.ACID_BUCKET.get().getDefaultInstance(), (_stack)->true, Objects.requireNonNull(ModFluids.ACID_TYPE.get().getSound(SoundActions.BUCKET_FILL))));
return map;
}

@Override
public void entityInside(BlockState state, Level level, BlockPos pos, Entity entity) {
if (!(entity instanceof LivingEntity)) return;
AcidFluid.onEntityInside((LivingEntity)entity);
}

@Override
public boolean isFull(BlockState pState) {
return true;
}

@Override
public InteractionResult use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit) {
//No idea why, but MC freaks out without this line. super.use() should cover it, but it doesn't so...
if (getInteractions().containsKey(player.getItemInHand(hand).getItem())) return getInteractions().get(player.getItemInHand(hand).getItem()).interact(state,level,pos,player,hand,player.getItemInHand(hand));

//An attempt to allow the player to do all the erosion interactions inside the cauldron.
//It mostly works, copper being a weird exception.
Block block = ForgeRegistries.BLOCKS.getValue(ForgeRegistries.ITEMS.getKey(player.getItemInHand(hand).getItem()));
if (!Objects.isNull(block)) {
BlockState eroded = AcidFluid.getEroded(block.defaultBlockState());
if (!Objects.isNull(eroded)) {
player.setItemInHand(hand,new ItemStack(eroded.getBlock().asItem(),player.getItemInHand(hand).getCount()));
return InteractionResult.SUCCESS;
}
}

return super.use(state, level, pos, player, hand, hit);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.github.elenterius.biomancy.fluid;

import com.github.elenterius.biomancy.block.veins.FleshVeinsBlock;
import com.github.elenterius.biomancy.init.ModBlocks;
import com.github.elenterius.biomancy.init.ModFluids;
import com.github.elenterius.biomancy.init.tags.ModBlockTags;
import com.github.elenterius.biomancy.util.CombatUtil;
Expand All @@ -22,6 +23,7 @@
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.fluids.ForgeFlowingFluid;
import org.jetbrains.annotations.Nullable;

import java.util.Map;

Expand All @@ -44,7 +46,7 @@ protected AcidFluid(Properties properties) {
public static void onEntityInside(LivingEntity livingEntity) {
if (livingEntity.isSpectator()) return;
if (livingEntity.tickCount % 5 != 0) return;
if (!livingEntity.isInFluidType(ModFluids.ACID_TYPE.get())) return;
if (!livingEntity.isInFluidType(ModFluids.ACID_TYPE.get()) && !livingEntity.getFeetBlockState().is(ModBlocks.ACID_CAULDRON.get())) return;

if (!livingEntity.level().isClientSide) {
CombatUtil.applyAcidEffect(livingEntity, 4);
Expand All @@ -62,6 +64,18 @@ else if (livingEntity.tickCount % 10 == 0 && livingEntity.getRandom().nextFloat(
}
}

@Nullable
public static BlockState getEroded(BlockState state) {
if (state instanceof WeatheringCopper && WeatheringCopper.getNext(state.getBlock()).isPresent()) {
return WeatheringCopper.getNext(state.getBlock()).get().defaultBlockState();
} else if (state.is(ModBlockTags.ACID_DESTRUCTIBLE)) {
return Blocks.AIR.defaultBlockState();
} else if (NORMAL_TO_ERODED_BLOCK_CONVERSION.containsKey(state.getBlock())) {
return NORMAL_TO_ERODED_BLOCK_CONVERSION.get(state.getBlock());
}
return null;
}

@Override
protected boolean canPassThrough(BlockGetter level, Fluid fluid, BlockPos fromPos, BlockState fromBlockState, Direction direction, BlockPos toPos, BlockState toBlockState, FluidState toFluidState) {
return toBlockState.getBlock() instanceof FleshVeinsBlock || super.canPassThrough(level, fluid, fromPos, fromBlockState, direction, toPos, toBlockState, toFluidState);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.github.elenterius.biomancy.block.bioforge.BioForgeBlock;
import com.github.elenterius.biomancy.block.biolab.BioLabBlock;
import com.github.elenterius.biomancy.block.bloom.BloomBlock;
import com.github.elenterius.biomancy.block.cauldron.AcidCauldron;
import com.github.elenterius.biomancy.block.chrysalis.ChrysalisBlock;
import com.github.elenterius.biomancy.block.cradle.PrimordialCradleBlock;
import com.github.elenterius.biomancy.block.decomposer.DecomposerBlock;
Expand Down Expand Up @@ -136,6 +137,7 @@ public final class ModBlocks {
public static final RegistryObject<FleshDoorBlock> FLESH_DOOR = register("flesh_door", FleshDoorBlock::new);
public static final RegistryObject<FullFleshDoorBlock> FULL_FLESH_DOOR = register("full_flesh_door", FullFleshDoorBlock::new);
public static final RegistryObject<FleshChainBlock> TENDON_CHAIN = register("tendon_chain", properties -> new FleshChainBlock(properties.noOcclusion()));
public static final RegistryObject<AcidCauldron> ACID_CAULDRON = register("acid_cauldron", AcidCauldron::new);

private ModBlocks() {}

Expand Down
12 changes: 11 additions & 1 deletion src/main/java/com/github/elenterius/biomancy/init/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.github.elenterius.biomancy.item.weapon.RavenousClawsItem;
import com.github.elenterius.biomancy.item.weapon.gun.CausticGunbladeItem;
import com.github.elenterius.biomancy.item.weapon.gun.DevArmCannonItem;
import net.minecraft.core.cauldron.CauldronInteraction;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
Expand All @@ -20,10 +21,12 @@
import net.minecraft.world.item.*;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.common.ForgeSpawnEggItem;
import net.minecraftforge.common.SoundActions;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
import net.minecraftforge.registries.RegistryObject;

import java.util.Objects;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.stream.Stream;
Expand Down Expand Up @@ -224,7 +227,14 @@ public static <T extends Item> Stream<RegistryObject<T>> findEntries(Class<T> cl
}

private static <T extends Item> RegistryObject<T> registerItem(String name, Function<Item.Properties, T> factory) {
return ITEMS.register(name, () -> factory.apply(createProperties()));
RegistryObject<T> ret = ITEMS.register(name, () -> factory.apply(createProperties()));
if (name.equals("biomancy:acid_bucket")) {
//Register Cauldron filling for Acid
CauldronInteraction.EMPTY.put(ret.get(),(state, level, pos, player, hand, stack)->{
return CauldronInteraction.emptyBucket(level,pos,player,hand,stack, ModBlocks.ACID_CAULDRON.get().defaultBlockState(), Objects.requireNonNull(ModFluids.ACID.get().getFluidType().getSound(SoundActions.BUCKET_EMPTY)));
});
}
return ret;
}

private static <T extends Block> RegistryObject<SimpleBlockItem> registerSimpleBlockItem(RegistryObject<T> blockHolder) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.github.elenterius.biomancy.mixin;

import com.github.elenterius.biomancy.init.ModBlocks;
import com.github.elenterius.biomancy.init.ModFluids;
import com.github.elenterius.biomancy.init.ModItems;
import net.minecraft.core.BlockPos;
import net.minecraft.core.cauldron.CauldronInteraction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AbstractCauldronBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraftforge.common.SoundActions;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import java.util.Objects;

@Mixin(value= AbstractCauldronBlock.class)
public abstract class AbstractCauldronBlockMixin {
@Inject(at=@At("TAIL"),method="Lnet/minecraft/world/level/block/AbstractCauldronBlock;use(Lnet/minecraft/world/level/block/state/BlockState;Lnet/minecraft/world/level/Level;Lnet/minecraft/core/BlockPos;Lnet/minecraft/world/entity/player/Player;Lnet/minecraft/world/InteractionHand;Lnet/minecraft/world/phys/BlockHitResult;)Lnet/minecraft/world/InteractionResult;", cancellable = true)
public void biomancy$use(BlockState state, Level level, BlockPos pos, Player player, InteractionHand hand, BlockHitResult hit, CallbackInfoReturnable<InteractionResult> cir) {
//Allow the Acid bucket to fill Cauldrons. I have no idea why this should require a mixin, beyond "Just Vanilla Things".
if (player.getItemInHand(hand).getItem().equals(ModItems.ACID_BUCKET.get())) {
cir.setReturnValue(CauldronInteraction.emptyBucket(level,pos,player,hand,player.getItemInHand(hand), ModBlocks.ACID_CAULDRON.get().defaultBlockState(), Objects.requireNonNull(ModFluids.ACID_TYPE.get().getSound(SoundActions.BUCKET_FILL))));
}
}
}
9 changes: 5 additions & 4 deletions src/main/resources/mixins.biomancy.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
"defaultRequire": 1
},
"mixins": [
"AgeableMobAccessor", "AreaEffectCloudMixin", "ArmorStandAccessor", "ArrowMixin", "BiomeAccessor", "DamageSourceAccessor", "EntityAccessor",
"IntegerPropertyAccessor", "LivingEntityAccessor", "LivingEntityMixin", "MobEffectInstanceAccessor", "MobEffectInstanceMixin", "MobEntityAccessor",
"PhantomMixin", "PlayerMixin", "ServerLevelAccessor", "ServerLevelMixin", "SlimeAccessor", "SuspiciousStewItemAccessor", "SwordItemMixinAccessor",
"TadpoleAccessor", "TextureSlotAccessor", "ThrownPotionMixin", "UnbreakingEnchantmentMixin", "WallBlockMixin", "ZombieVillagerMixinAccessor"
"AbstractCauldronBlockMixin", "AgeableMobAccessor", "AreaEffectCloudMixin", "ArmorStandAccessor", "ArrowMixin", "BiomeAccessor", "DamageSourceAccessor",
"EntityAccessor", "IntegerPropertyAccessor", "LivingEntityAccessor", "LivingEntityMixin", "MobEffectInstanceAccessor", "MobEffectInstanceMixin",
"MobEntityAccessor", "PhantomMixin", "PlayerMixin", "ServerLevelAccessor", "ServerLevelMixin", "SlimeAccessor", "SuspiciousStewItemAccessor",
"SwordItemMixinAccessor", "TadpoleAccessor", "TextureSlotAccessor", "ThrownPotionMixin", "UnbreakingEnchantmentMixin", "WallBlockMixin",
"ZombieVillagerMixinAccessor"
],
"client": [
"client.ClientPackListenerMixin", "client.ClientRecipeBookMixin", "client.GuiGraphicsMixin", "client.PlayerRendererMixin", "client.RecipeCollectionAccessor"
Expand Down

0 comments on commit 749669e

Please sign in to comment.