Skip to content

Commit

Permalink
no damage fuck
Browse files Browse the repository at this point in the history
  • Loading branch information
Leclowndu93150 committed Nov 10, 2024
1 parent 8eb602c commit 4c8038a
Show file tree
Hide file tree
Showing 8 changed files with 140 additions and 42 deletions.
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
// 1.21.1 2024-10-12T17:59:11.663395815 Recipes
// 1.21.1 2024-11-10T11:12:05.0127252 Recipes
3e6e10b5b918f24573e390baf114595590f1a8c3 data/carbort/advancement/recipes/misc/unstable_ingot.json
254d13fee08e76f937288a3cc1867cade30d0299 data/carbort/recipe/unstable_ingot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"criteria": {
"has_item": {
"conditions": {
"items": [
{
"items": "carbort:division_sigil"
}
]
},
"trigger": "minecraft:inventory_changed"
},
"has_the_recipe": {
"conditions": {
"recipe": "carbort:unstable_ingot"
},
"trigger": "minecraft:recipe_unlocked"
}
},
"requirements": [
[
"has_the_recipe",
"has_item"
]
],
"rewards": {
"recipes": [
"carbort:unstable_ingot"
]
}
}
24 changes: 24 additions & 0 deletions src/generated/resources/data/carbort/recipe/unstable_ingot.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
{
"type": "minecraft:crafting_shaped",
"category": "misc",
"key": {
"#": {
"item": "carbort:division_sigil"
},
"D": {
"item": "minecraft:diamond"
},
"I": {
"item": "minecraft:iron_ingot"
}
},
"pattern": [
"I",
"#",
"D"
],
"result": {
"count": 1,
"id": "carbort:unstable_ingot"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,11 @@
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.Optional;

public class DivisionSigilItem extends Item {
Expand All @@ -33,11 +35,11 @@ public DivisionSigilItem(Properties properties) {
}

@Override
public InteractionResult useOn(UseOnContext context) {
public @NotNull InteractionResult useOn(UseOnContext context) {
Player player = context.getPlayer();
ItemStack stack = context.getItemInHand();

if (stack.get(CBDataComponents.ACTIVE) || !player.isShiftKeyDown() || player.getMainHandItem() != stack) {
if (Boolean.TRUE.equals(stack.get(CBDataComponents.ACTIVE)) || !Objects.requireNonNull(player).isShiftKeyDown() || player.getMainHandItem() != stack) {
return InteractionResult.FAIL;
}

Expand Down Expand Up @@ -87,14 +89,30 @@ public boolean isDamageable(ItemStack stack) {
return true;
}

@Override
public @NotNull ItemStack getCraftingRemainingItem(ItemStack itemStack) {
ItemStack sigil = itemStack.copy();
int newSigil = sigil.getDamageValue() + 1;
if (newSigil >= sigil.getMaxDamage()) {
return ItemStack.EMPTY;
}
sigil.setDamageValue(newSigil);
return sigil;
}

@Override
public boolean hasCraftingRemainingItem(ItemStack stack) {
return true;
}

@Override
public boolean isFoil(ItemStack stack) {
return stack.get(CBDataComponents.ACTIVE);
return Boolean.TRUE.equals(stack.get(CBDataComponents.ACTIVE));
}

@Override
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, TooltipFlag tooltipFlag) {
tooltipComponents.add(Component.literal("Status: " + (stack.get(CBDataComponents.ACTIVE) ? "Active" : "Inactive")).withStyle(ChatFormatting.GRAY));
public void appendHoverText(ItemStack stack, TooltipContext context, List<Component> tooltipComponents, @NotNull TooltipFlag tooltipFlag) {
tooltipComponents.add(Component.literal("Status: " + (Boolean.TRUE.equals(stack.get(CBDataComponents.ACTIVE)) ? "Active" : "Inactive")).withStyle(ChatFormatting.GRAY));
super.appendHoverText(stack, context, tooltipComponents, tooltipFlag);
}
}
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
package com.leclowndu93150.carbort.content.items;

import com.google.common.collect.Sets;
import com.leclowndu93150.carbort.registries.CBDataComponents;
import com.leclowndu93150.carbort.utils.RandomFunctions;
import net.minecraft.ChatFormatting;
import net.minecraft.client.Minecraft;
import net.minecraft.core.component.DataComponents;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.CraftingMenu;
import net.minecraft.world.item.*;
import net.minecraft.world.item.component.DyedItemColor;
import net.minecraft.world.item.crafting.ArmorDyeRecipe;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.ExplosionDamageCalculator;
import net.minecraft.world.level.Level;

import java.util.HashSet;
import java.util.List;

public class UnstableIngotItem extends Item {
public UnstableIngotItem(Properties properties) {
super(properties);
}

public static final ExplosionDamageCalculator DAMAGE_CALCULATOR = new ExplosionDamageCalculator() {
@Override
public float getEntityDamageAmount(Explosion explosion, Entity entity) {
if (entity instanceof Player player) {
float currentHealth = player.getHealth();
return 1000f;
}
return super.getEntityDamageAmount(explosion, entity);
}
};

@Override
public int getMaxStackSize(ItemStack stack) {
return 1;
Expand Down Expand Up @@ -55,7 +62,17 @@ public void inventoryTick(ItemStack stack, Level level, Entity entity, int slotI
if (stack.get(CBDataComponents.TIMER) <= 0){
if(entity instanceof Player player && !player.isCreative() && !level.isClientSide()){
stack.shrink(1);
level.explode(entity, entity.getX(), entity.getY(), entity.getZ(),3, Level.ExplosionInteraction.TNT);
player.level().explode(
null,
Explosion.getDefaultDamageSource(player.level(), player),
DAMAGE_CALCULATOR,
player.getX(),
player.getY(),
player.getZ(),
3f,
true,
Level.ExplosionInteraction.TNT
);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
package com.leclowndu93150.carbort.datagen;

import com.leclowndu93150.carbort.registries.CBDataComponents;
import com.leclowndu93150.carbort.registries.CBItems;
import net.minecraft.core.HolderLookup;
import net.minecraft.data.PackOutput;
import net.minecraft.data.recipes.RecipeCategory;
import net.minecraft.data.recipes.RecipeOutput;
import net.minecraft.data.recipes.RecipeProvider;
import net.minecraft.data.recipes.ShapedRecipeBuilder;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.crafting.Ingredient;
import org.jetbrains.annotations.NotNull;

import java.util.concurrent.CompletableFuture;

Expand All @@ -13,7 +21,18 @@ public CBRecipesProvider(PackOutput output, CompletableFuture<HolderLookup.Provi
}

@Override
protected void buildRecipes(RecipeOutput p_recipeOutput, HolderLookup.Provider holderLookup) {
protected void buildRecipes(@NotNull RecipeOutput p_recipeOutput, HolderLookup.@NotNull Provider holderLookup) {
ItemStack sigilActive = CBItems.DIVISION_SIGIL.asItem().getDefaultInstance();
sigilActive.set(CBDataComponents.ACTIVE, true);

ShapedRecipeBuilder.shaped(RecipeCategory.MISC, CBItems.UNSTABLE_INGOT.get())
.define('I', Items.IRON_INGOT)
.define('#', Ingredient.of(sigilActive))
.define('D', Items.DIAMOND)
.pattern("I")
.pattern("#")
.pattern("D")
.unlockedBy("has_item", has(CBItems.DIVISION_SIGIL.get()))
.save(p_recipeOutput);
}
}
27 changes: 14 additions & 13 deletions src/main/java/com/leclowndu93150/carbort/events/CarbortEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,37 +10,28 @@
import com.leclowndu93150.carbort.networking.ChunkAnalyzerTogglePayload;
import com.leclowndu93150.carbort.networking.PayloadActions;
import com.leclowndu93150.carbort.registries.CBDataComponents;
import com.leclowndu93150.carbort.registries.CBItems;
import com.leclowndu93150.carbort.registries.CBMenus;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.CraftingMenu;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.ItemLike;
import net.minecraft.world.level.Explosion;
import net.minecraft.world.level.Level;
import net.neoforged.bus.api.EventPriority;
import net.neoforged.bus.api.SubscribeEvent;
import net.neoforged.fml.common.EventBusSubscriber;
import net.neoforged.neoforge.capabilities.Capabilities;
import net.neoforged.neoforge.capabilities.RegisterCapabilitiesEvent;
import net.neoforged.neoforge.client.event.RegisterColorHandlersEvent;
import net.neoforged.neoforge.client.event.RegisterMenuScreensEvent;
import net.neoforged.neoforge.event.entity.player.AttackEntityEvent;
import net.neoforged.neoforge.event.tick.EntityTickEvent;
import net.neoforged.neoforge.event.tick.PlayerTickEvent;
import net.neoforged.neoforge.event.tick.ServerTickEvent;
import net.neoforged.neoforge.network.event.RegisterPayloadHandlersEvent;
import net.neoforged.neoforge.network.registration.PayloadRegistrar;

import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.UUID;
import static com.leclowndu93150.carbort.content.items.UnstableIngotItem.DAMAGE_CALCULATOR;

@EventBusSubscriber(modid = Carbort.MODID)
public class CarbortEvents {
Expand Down Expand Up @@ -74,9 +65,19 @@ public static void holdingUnstableIngot(PlayerTickEvent.Post event){
if(item.has(CBDataComponents.TIMER)){
item.set(CBDataComponents.TIMER, item.getOrDefault(CBDataComponents.TIMER, 0) - 1);
if(item.getOrDefault(CBDataComponents.TIMER, 0) <= 0){
if(!player.isCreative()){
if (!player.isCreative()) {
item.shrink(1);
player.level().explode(player, player.getX(), player.getY(), player.getZ(),3, Level.ExplosionInteraction.TNT);
player.level().explode(
null,
Explosion.getDefaultDamageSource(player.level(), player),
DAMAGE_CALCULATOR,
player.getX(),
player.getY(),
player.getZ(),
3f,
true,
Level.ExplosionInteraction.TNT
);
}
}
}
Expand Down
15 changes: 0 additions & 15 deletions src/main/resources/data/carbort/recipe/unstable_ingot.json

This file was deleted.

0 comments on commit 4c8038a

Please sign in to comment.