Skip to content

Commit

Permalink
Add Random Polymorph Functionality
Browse files Browse the repository at this point in the history
  • Loading branch information
Direwolf20-MC committed Dec 7, 2024
1 parent b48a5d8 commit 2eee62c
Show file tree
Hide file tree
Showing 22 changed files with 378 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
// 1.21.1 2024-09-25T19:43:29.0537222 Tags for minecraft:entity_type mod id justdirethings
// 1.21.1 2024-12-07T15:14:23.6887728 Tags for minecraft:entity_type mod id justdirethings
b7ee8eaecff151e619b9a22ecae620a5b3ce15a0 data/c/tags/entity_type/teleporting_not_supported.json
e00f2931577049b9a4400a87ed9c249373be376c data/justdirethings/tags/entity_type/creature_catcher_deny.json
669025814936e708d42d9d0a5b88c11e62cf12ef data/justdirethings/tags/entity_type/no_ai_deny.json
669025814936e708d42d9d0a5b88c11e62cf12ef data/justdirethings/tags/entity_type/no_earthquake.json
b7ee8eaecff151e619b9a22ecae620a5b3ce15a0 data/justdirethings/tags/entity_type/paradox_absorb_deny.json
b7ee8eaecff151e619b9a22ecae620a5b3ce15a0 data/justdirethings/tags/entity_type/paradox_deny.json
263995270039da950f2e27b535f1b7c71a5f5423 data/justdirethings/tags/entity_type/polymorphic_hostile.json
d53ddb5be22b17ec02beda6e2e3695f074abc70f data/justdirethings/tags/entity_type/polymorphic_peaceful.json
6a890ea62d03cc1110fa8d1fe5a0669082d9d96b data/minecraft/tags/entity_type/arrows.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.21.1 2024-12-07T12:22:16.5157473 Languages: en_us for mod: justdirethings
3b47394404270f860109f4004040665ac95dfef0 assets/justdirethings/lang/en_us.json
// 1.21.1 2024-12-07T15:35:26.0358297 Languages: en_us for mod: justdirethings
dc7bbea3a13870709a7bafccf7758ac21f7bffec assets/justdirethings/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.21.1 2024-12-07T12:22:16.5167479 Recipes
// 1.21.1 2024-12-07T15:39:40.3847313 Recipes
39cd44c838de7f56aeac73aec8b3bfb64ad7fec2 data/justdirethings/advancement/recipes/building_blocks/blazegold_ingot_9x9.json
2f2a0f948f272df9713010dbcb75beb81c328b01 data/justdirethings/advancement/recipes/building_blocks/celestigem_9x9.json
4c183b67eff4bc24117606cdc45ebcd987dd4138 data/justdirethings/advancement/recipes/building_blocks/charcoal_9x9.json
Expand Down Expand Up @@ -697,7 +697,7 @@ de4d6dd744789b903d6828fec4ce5847a1dfef60 data/justdirethings/recipe/paradoxmachi
cc73b7c24448814a0e8663c8065a6625cbd30072 data/justdirethings/recipe/pocket_generator.json
035ed5c68eac114352b166d38b7f8308e5db63c0 data/justdirethings/recipe/polymorphic_catalyst.json
6cfafeb9ae58abc121bd78f1c67b11aedec8297b data/justdirethings/recipe/polymorphic_fluid_block-fluiddrop.json
fc60c6a1885dc44e50e451ea8e12eb4f9d7acf4c data/justdirethings/recipe/polymorphic_wand.json
52f1c1f4d04ba53cc38b2dbfc49fb1d19a35b344 data/justdirethings/recipe/polymorphic_wand.json
1494fe69edb92207b18a251b9c4a4d7ef2487b45 data/justdirethings/recipe/portalgun.json
4ed1bcc18461694ef969bb8820a6a4433cec054f data/justdirethings/recipe/portalgun_v2.json
881053ecbb4f27590666128cfd52f2c212cf6a37 data/justdirethings/recipe/portal_fluid_block-goospread.json
Expand Down
3 changes: 3 additions & 0 deletions src/generated/resources/assets/justdirethings/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@
"justdirethings.ability.orescanner": "Ore Scanner",
"justdirethings.ability.orexray": "X-Ray",
"justdirethings.ability.phase": "Phase",
"justdirethings.ability.polymorph_random": "Random Polymorph",
"justdirethings.ability.potionarrow": "Potion Arrow",
"justdirethings.ability.runspeed": "Run Speed",
"justdirethings.ability.skysweeper": "Sky Sweeper",
Expand Down Expand Up @@ -317,6 +318,7 @@
"justdirethings.hint.dropinwater": "Drop in Water",
"justdirethings.homing.detailtext": "Arrows seek their targets",
"justdirethings.instabreak.detailtext": "Instantly break all blocks",
"justdirethings.invalidpolymorphentity": "Invalid Entity for Polymorphing",
"justdirethings.invulnerability.detailtext": "Activate for a few seconds of invulnerability",
"justdirethings.invulnerability.flavortext": "Bring it!!",
"justdirethings.jumpboost.detailtext": "Jump Higher",
Expand Down Expand Up @@ -350,6 +352,7 @@
"justdirethings.pocketgeneratorburntime": "Burn Time: %f / %f",
"justdirethings.pocketgeneratorfuelstack": "Fuel: %f %s",
"justdirethings.pocketgeneratornofuel": "Fuel Empty",
"justdirethings.polymorphicfluidamt": "Polymorphic Fluid: %s / %s",
"justdirethings.portalfluidamt": "Portal Fluid: %s / %s",
"justdirethings.potionarrow.detailtext": "Insert a Potion Canister to apply effects to enemies",
"justdirethings.potionarrow.flavortext": "Like Vanilla, without inventory issues...",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,14 @@
},
"i": {
"item": "justdirethings:blazegold_ingot"
},
"r": {
"item": "justdirethings:polymorphic_catalyst"
}
},
"pattern": [
" b",
" i ",
" r ",
"i "
],
"result": {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
{
"values": [
"minecraft:zombie",
"minecraft:skeleton",
"minecraft:creeper",
"minecraft:spider",
"minecraft:enderman",
"minecraft:silverfish",
"minecraft:zombified_piglin",
"minecraft:piglin",
"minecraft:piglin_brute",
"minecraft:hoglin",
"minecraft:zoglin",
"minecraft:ghast",
"minecraft:blaze",
"minecraft:slime",
"minecraft:witch",
"minecraft:rabbit",
"minecraft:endermite",
"minecraft:stray",
"minecraft:wither_skeleton",
"minecraft:skeleton_horse",
"minecraft:zombie_horse",
"minecraft:zombie_villager",
"minecraft:husk",
"minecraft:guardian",
"minecraft:evoker",
"minecraft:vex",
"minecraft:vindicator",
"minecraft:shulker",
"minecraft:drowned",
"minecraft:phantom",
"minecraft:pillager"
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
{
"values": [
"minecraft:sheep",
"minecraft:pig",
"minecraft:cow",
"minecraft:mooshroom",
"minecraft:chicken",
"minecraft:bat",
"minecraft:villager",
"minecraft:squid",
"minecraft:ocelot",
"minecraft:wolf",
"minecraft:horse",
"minecraft:rabbit",
"minecraft:donkey",
"minecraft:mule",
"minecraft:polar_bear",
"minecraft:llama",
"minecraft:parrot",
"minecraft:dolphin",
"minecraft:cod",
"minecraft:salmon",
"minecraft:pufferfish",
"minecraft:tropical_fish",
"minecraft:turtle",
"minecraft:cat",
"minecraft:fox",
"minecraft:panda",
"minecraft:trader_llama",
"minecraft:wandering_trader",
"minecraft:strider",
"minecraft:glow_squid",
"minecraft:goat",
"minecraft:bee",
"minecraft:frog",
"minecraft:tadpole",
"minecraft:camel",
"minecraft:axolotl"
]
}
18 changes: 17 additions & 1 deletion src/main/java/com/direwolf20/justdirethings/JustDireThings.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import com.direwolf20.justdirethings.common.containers.handlers.PotionCanisterHandler;
import com.direwolf20.justdirethings.common.entities.DecoyEntity;
import com.direwolf20.justdirethings.common.items.FluidCanister;
import com.direwolf20.justdirethings.common.items.PolymorphicWand;
import com.direwolf20.justdirethings.common.items.PortalGunV2;
import com.direwolf20.justdirethings.common.items.TimeWand;
import com.direwolf20.justdirethings.common.items.datacomponents.JustDireDataComponents;
Expand Down Expand Up @@ -168,14 +169,29 @@ public boolean canFillFluidType(FluidStack fluid) {

};
}
if (itemStack.getItem() instanceof PolymorphicWand polymorphicWand) {
return new FluidHandlerItemStack(JustDireDataComponents.FLUID_CONTAINER, itemStack, polymorphicWand.getMaxMB()) {
@Override
public boolean isFluidValid(int tank, FluidStack stack) {
return stack.is(Registration.POLYMORPHIC_FLUID_TYPE.get());
}

@Override
public boolean canFillFluidType(FluidStack fluid) {
return fluid.is(Registration.POLYMORPHIC_FLUID_TYPE.get());
}

};
}
if (itemStack.getItem() instanceof FluidCanister fluidCanister) {
return new FluidHandlerItemStack(JustDireDataComponents.FLUID_CONTAINER, itemStack, fluidCanister.getMaxMB());
}
return null;
},
Registration.PortalGunV2.get(),
Registration.FluidCanister.get(),
Registration.TimeWand.get()
Registration.TimeWand.get(),
Registration.PolymorphicWand.get()
);

//Blocks
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ public boolean render(GuiGraphics guiGraphics, Font font, ItemStack stack, int x
if (stack.getItem() instanceof PoweredItem poweredItem) {
isPowerBarVisible = poweredItem.isPowerBarVisible(stack);
}
if (stack.isBarVisible())
isPowerBarVisible = true;

// Retrieve fluid capability
boolean isFluidBarVisible = fluidContainingItem.isFluidBarVisible(stack);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,15 +1,77 @@
package com.direwolf20.justdirethings.common.items;

import com.direwolf20.justdirethings.common.items.interfaces.Ability;
import com.direwolf20.justdirethings.common.items.interfaces.BaseToggleableTool;
import com.direwolf20.justdirethings.common.items.interfaces.LeftClickableTool;
import com.direwolf20.justdirethings.common.items.interfaces.*;
import com.direwolf20.justdirethings.setup.Config;
import com.direwolf20.justdirethings.util.MagicHelpers;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.InteractionResultHolder;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.HitResult;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.fluids.capability.IFluidHandlerItem;

public class PolymorphicWand extends BaseToggleableTool implements LeftClickableTool {
import java.util.List;

public class PolymorphicWand extends BaseToggleableTool implements LeftClickableTool, FluidContainingItem {
public PolymorphicWand() {
super(new Properties()
.fireResistant()
.durability(200));
registerAbility(Ability.LAVAREPAIR);
//registerAbility(Ability.AIRBURST, new AbilityParams(1, 2, 1, 2));
registerAbility(Ability.POLYMORPH_RANDOM);
}

@Override
public int getMaxMB() {
return Config.POLYMORPHIC_WAND_MAX_FLUID.get();
}

@Override
public InteractionResult useOn(UseOnContext pContext) {
ItemStack itemStack = pContext.getItemInHand();
Player player = pContext.getPlayer();
if (player == null || itemStack.isEmpty()) return InteractionResult.FAIL;
BlockHitResult blockhitresult = getPlayerPOVHitResult(player.level(), player, ClipContext.Fluid.SOURCE_ONLY);
if (blockhitresult.getType() == HitResult.Type.BLOCK) {
if (FluidContainingItem.pickupFluid(player.level(), player, itemStack, blockhitresult))
return InteractionResult.SUCCESS;
}
return super.useOn(pContext);
}

@Override
public InteractionResultHolder<ItemStack> use(Level level, Player player, InteractionHand hand) {
ItemStack itemStack = player.getItemInHand(hand);
BlockHitResult blockhitresult = getPlayerPOVHitResult(level, player, ClipContext.Fluid.SOURCE_ONLY);
if (blockhitresult.getType() == HitResult.Type.BLOCK) {
if (FluidContainingItem.pickupFluid(level, player, itemStack, blockhitresult))
return InteractionResultHolder.fail(itemStack);
}
return super.use(level, player, hand);
}

@Override
public void appendHoverText(ItemStack stack, Item.TooltipContext context, List<Component> tooltip, TooltipFlag flagIn) {
super.appendHoverText(stack, context, tooltip, flagIn);
Level level = context.level();
if (level == null) {
return;
}
IFluidHandlerItem fluidHandler = stack.getCapability(Capabilities.FluidHandler.ITEM);
if (fluidHandler == null) {
return;
}
tooltip.add(Component.translatable("justdirethings.polymorphicfluidamt", MagicHelpers.formatted(fluidHandler.getFluidInTank(0).getAmount()), MagicHelpers.formatted(fluidHandler.getTankCapacity(0))).withStyle(ChatFormatting.GREEN));
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ public enum Ability {
AbilityMethods::stupefy, CustomSettingType.NONE,
ResourceLocation.fromNamespaceAndPath(JustDireThings.MODID, "textures/gui/overlay/stupefy.png"), Registration.UPGRADE_STUPEFY),
SPLASH(SettingType.TOGGLE, 20, 250, UseType.PASSIVE, BindingType.CUSTOM_ONLY, Registration.UPGRADE_SPLASH),
POLYMORPH_RANDOM(SettingType.TOGGLE, 10, 1000, UseType.USE, BindingType.LEFT_AND_CUSTOM,
AbilityMethods::polymorphRandom, CustomSettingType.NONE,
ResourceLocation.fromNamespaceAndPath(JustDireThings.MODID, "textures/gui/overlay/polymorph_random.png")),

//Tier 3
DROPTELEPORT(SettingType.TOGGLE, 2, 100, UseType.PASSIVE, BindingType.CUSTOM_ONLY, CustomSettingType.RENDER, Registration.UPGRADE_DROPTELEPORT),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
import com.direwolf20.justdirethings.common.network.data.ClientSoundPayload;
import com.direwolf20.justdirethings.datagen.JustDireBlockTags;
import com.direwolf20.justdirethings.datagen.JustDireEntityTags;
import com.direwolf20.justdirethings.setup.Config;
import com.direwolf20.justdirethings.setup.Registration;
import com.direwolf20.justdirethings.util.MiscTools;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.network.chat.Component;
import net.minecraft.network.protocol.game.ClientboundSetEntityMotionPacket;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.server.level.ServerPlayer;
Expand All @@ -26,10 +29,7 @@
import net.minecraft.world.effect.MobEffectCategory;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.TieredItem;
Expand All @@ -47,6 +47,7 @@
import net.minecraft.world.phys.shapes.VoxelShape;
import net.neoforged.neoforge.common.Tags;
import net.neoforged.neoforge.entity.PartEntity;
import net.neoforged.neoforge.event.EventHooks;
import net.neoforged.neoforge.items.IItemHandler;
import net.neoforged.neoforge.network.PacketDistributor;

Expand Down Expand Up @@ -471,6 +472,57 @@ public static boolean stupefy(Level level, Player player, ItemStack itemStack) {
return false;
}

public static boolean polymorphRandom(Level level, Player player, ItemStack itemStack) {
if (level.isClientSide) return false;
if (itemStack.getItem() instanceof ToggleableTool toggleableTool && toggleableTool.canUseAbilityAndDurability(itemStack, Ability.POLYMORPH_RANDOM)) {
int fuelAmt = Config.RANDOM_POLYMORPH_COST.get();
if (!FluidContainingItem.hasEnoughFluid(itemStack, fuelAmt))
return false;
Entity entity = MiscTools.getEntityLookedAt(player, 4);
if (entity == null) return false;
boolean peaceful = entity.getType().is(JustDireEntityTags.POLYMORPHIC_PEACEFUL);
if (!peaceful && !entity.getType().is(JustDireEntityTags.POLYMORPHIC_HOSTILE)) {
player.displayClientMessage(Component.translatable("justdirethings.invalidpolymorphentity"), true);
return false; //If not peaceful or hostile tagged, return
}
if (entity instanceof Mob mob) {
EntityType<?> newType = getRandomMobTypeByCategory(level, peaceful);
if (newType != null) {
// Spawn new mob at the same location
Mob newMob = (Mob) newType.create(level);
if (newMob != null) {
EventHooks.finalizeMobSpawn(mob, (ServerLevel) level, level.getCurrentDifficultyAt(player.blockPosition()), MobSpawnType.SPAWNER, null);

newMob.moveTo(mob.getX(), mob.getY(), mob.getZ(), mob.getYRot(), mob.getXRot());
newMob.setHealth(newMob.getMaxHealth()); // Reset health to maximum
((ServerLevel) level).addFreshEntityWithPassengers(newMob);

if (!newMob.isAddedToLevel())
return false; //If it failed to add for some reason?

// Play effects
player.playNotifySound(SoundEvents.ILLUSIONER_CAST_SPELL, SoundSource.PLAYERS, 0.5F, 0.75F);
((ServerLevel) level).sendParticles(ParticleTypes.WHITE_SMOKE,
mob.getX(), mob.getEyeY(), mob.getZ(),
20, 0.25, 0.2, 0.25, 0);

// Remove the old mob
mob.discard();

// Damage the tool
FluidContainingItem.consumeFluid(itemStack, fuelAmt);
Helpers.damageTool(itemStack, player, Ability.POLYMORPH_RANDOM);
}
}

//player.playNotifySound(SoundEvents.ILLUSIONER_CAST_SPELL, SoundSource.PLAYERS, 0.5F, 0.75F);
//((ServerLevel) level).sendParticles(ParticleTypes.WHITE_SMOKE, mob.getX(), mob.getEyeY(), mob.getZ(), 20, 0.25, 0.2, 0.25, 0);
//Helpers.damageTool(itemStack, player, Ability.POLYMORPH_RANDOM);
}
}
return false;
}

public static boolean groundstomp(Level level, Player player, ItemStack itemStack) {
if (level.isClientSide) return false;
int currentCooldown = ToggleableTool.getAnyCooldown(itemStack, Ability.GROUNDSTOMP);
Expand Down Expand Up @@ -662,4 +714,12 @@ public static void clearStupefyTargets(ItemStack itemStack) {
itemStack.set(JustDireDataComponents.STUPEFY_TARGETS, new ArrayList<>());
}

private static EntityType<?> getRandomMobTypeByCategory(Level level, boolean peaceful) {
List<EntityType<?>> mobTypes = BuiltInRegistries.ENTITY_TYPE.stream()
.filter(type -> peaceful ? type.is(JustDireEntityTags.POLYMORPHIC_PEACEFUL) : type.is(JustDireEntityTags.POLYMORPHIC_HOSTILE))
.toList();

return mobTypes.isEmpty() ? null : mobTypes.get(level.random.nextInt(mobTypes.size()));
}

}
Loading

0 comments on commit 2eee62c

Please sign in to comment.