Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ org.gradle.jvmargs=-Xmx2G \

# Core NeoForge properties
minecraft_version=1.21.1
neo_version=21.1.37
neo_version_range=[21.1.37, 22-)
neo_version=21.1.60
neo_version_range=[21.1.60, 22-)
# For latest see https://parchmentmc.org/docs/getting-started
neoForge.parchment.minecraftVersion=1.21
neoForge.parchment.mappingsVersion=2024.07.28
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1500,7 +1500,8 @@
"text.modern_industrialization.AcceptsSteamToo": "Also Accepts Steam (1 mb \u003d 1 EU)",
"text.modern_industrialization.AcceptsUpgrades": "Add upgrades to increase max processing EU/t.",
"text.modern_industrialization.Activated": "Activated",
"text.modern_industrialization.AllowCreativeFlight": "Allow Creative Flight",
"text.modern_industrialization.AttributeInfiniteDamage": "Infinite Damage",
"text.modern_industrialization.AttributeQuantumArmor": "Quantum Armor",
"text.modern_industrialization.BarrelStack": "Can store up to %d stacks",
"text.modern_industrialization.BarrelStorageComponent": "%s / %s (%s)",
"text.modern_industrialization.BaseDurationSeconds": "%s sec",
Expand Down
18 changes: 18 additions & 0 deletions src/main/java/aztech/modern_industrialization/MI.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,10 @@
import net.minecraft.server.packs.repository.Pack;
import net.minecraft.server.packs.repository.PackCompatibility;
import net.minecraft.server.packs.repository.PackSource;
import net.minecraft.util.Mth;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.inventory.AnvilMenu;
import net.minecraft.world.item.ItemStack;
Expand All @@ -80,6 +83,8 @@
import net.neoforged.neoforge.event.AddPackFindersEvent;
import net.neoforged.neoforge.event.AnvilUpdateEvent;
import net.neoforged.neoforge.event.RegisterGameTestsEvent;
import net.neoforged.neoforge.event.entity.EntityAttributeModificationEvent;
import net.neoforged.neoforge.event.entity.living.LivingIncomingDamageEvent;
import net.neoforged.neoforge.event.entity.player.PlayerEvent;
import net.neoforged.neoforge.event.entity.player.PlayerInteractEvent;
import net.neoforged.neoforge.event.village.VillagerTradesEvent;
Expand Down Expand Up @@ -174,6 +179,19 @@ public MI(IEventBus modBus, Dist dist) {
}
});

modBus.addListener(EntityAttributeModificationEvent.class, event -> {
for (EntityType<? extends LivingEntity> entityType : event.getTypes()) {
event.add(entityType, MIRegistries.QUANTUM_ARMOR);
event.add(entityType, MIRegistries.INFINITE_DAMAGE);
}
});
NeoForge.EVENT_BUS.addListener(LivingIncomingDamageEvent.class, event -> {
if (event.getSource().getDirectEntity() instanceof LivingEntity damager
&& damager.getAttributeValue(MIRegistries.INFINITE_DAMAGE) > Mth.EPSILON) {
event.setAmount((float) Integer.MAX_VALUE);
}
});

modBus.addListener(FMLCommonSetupEvent.class, event -> {
MIBlock.BLOCK_DEFINITIONS.values().forEach(BlockDefinition::onRegister);
MIItem.ITEM_DEFINITIONS.values().forEach(ItemDefinition::onRegister);
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/aztech/modern_industrialization/MIRegistries.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@
*/
package aztech.modern_industrialization;

import aztech.modern_industrialization.attributes.InfiniteDamageAttribute;
import aztech.modern_industrialization.attributes.QuantumArmorAttribute;
import aztech.modern_industrialization.blocks.creativestorageunit.CreativeStorageUnitBlockEntity;
import aztech.modern_industrialization.blocks.forgehammer.ForgeHammerRecipe;
import aztech.modern_industrialization.blocks.forgehammer.ForgeHammerScreenHandler;
Expand All @@ -39,6 +41,7 @@
import net.minecraft.core.Holder;
import net.minecraft.core.registries.Registries;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.village.poi.PoiType;
import net.minecraft.world.entity.npc.VillagerProfession;
import net.minecraft.world.flag.FeatureFlags;
Expand Down Expand Up @@ -135,6 +138,13 @@ public class MIRegistries {
SoundEvents.VILLAGER_WORK_TOOLSMITH);
});

// Attributes
public static final DeferredRegister<Attribute> ATTRIBUTES = DeferredRegister.create(Registries.ATTRIBUTE, MI.ID);

public static final Holder<Attribute> QUANTUM_ARMOR = ATTRIBUTES.register("quantum_armor", () -> new QuantumArmorAttribute().setSyncable(true));
public static final Holder<Attribute> INFINITE_DAMAGE = ATTRIBUTES.register("infinite_damage",
() -> new InfiniteDamageAttribute().setSyncable(true));

static void init(IEventBus modBus) {
BLOCK_ENTITIES.register(modBus);
CONDITIONS.register(modBus);
Expand All @@ -144,5 +154,6 @@ static void init(IEventBus modBus) {
RECIPE_TYPES.register(modBus);
TABS.register(modBus);
VILLAGER_PROFESSIONS.register(modBus);
ATTRIBUTES.register(modBus);
}
}
3 changes: 2 additions & 1 deletion src/main/java/aztech/modern_industrialization/MIText.java
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,9 @@ public enum MIText {
AcceptsSteam("Accepts Steam (1 mb = 1 EU)"),
AcceptsSteamToo("Also Accepts Steam (1 mb = 1 EU)"),
AcceptsUpgrades("Add upgrades to increase max processing EU/t."),
AllowCreativeFlight("Allow Creative Flight"),
Activated("Activated"),
AttributeInfiniteDamage("Infinite Damage"),
AttributeQuantumArmor("Quantum Armor"),
BarrelStack("Can store up to %d stacks"),
BarrelStorageComponent("%s / %s (%s)"),
BaseDurationSeconds("%s sec"),
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
/*
* MIT License
*
* Copyright (c) 2020 Azercoco & Technici4n
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package aztech.modern_industrialization.attributes;

import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.item.TooltipFlag;

public abstract class DisplayNamedAttribute extends Attribute {
protected DisplayNamedAttribute(String descriptionId, double defaultValue) {
super(descriptionId, defaultValue);
}

/**
* Translation key to use in tooltips, thanks to our override of {@link #toComponent(AttributeModifier, TooltipFlag)}.
* {@link #getDescriptionId()} is still used in /attribute commands and other contexts.
*/
public abstract String getTooltipDescriptionId();

/*
* The below methods is copied from IAttributeExtension and uses DisplayAttribute#getDisplayDescriptionId so that Attribute#getDescriptionId
* can return the MIText.AttributeQuantumArmor description id. This is desirable because when using the /attribute command it will display the
* attribute name as "Quantum Armor" instead of just "Armor" like it does when using "attribute.name.generic.armor" as the description id (or
* "Infinite Damage" instead of just "Damage" for the InfiniteDamageAttribute).
*/

@Override
public MutableComponent toComponent(AttributeModifier modif, TooltipFlag flag) {
double value = modif.amount();
String key = value > 0 ? "neoforge.modifier.plus" : "neoforge.modifier.take";
ChatFormatting color = this.getStyle(value > 0);

Component attrDesc = Component.translatable(this.getTooltipDescriptionId());
Component valueComp = this.toValueComponent(modif.operation(), value, flag);
MutableComponent comp = Component.translatable(key, valueComp, attrDesc).withStyle(color);

return comp.append(this.getDebugInfo(modif, flag));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/*
* MIT License
*
* Copyright (c) 2020 Azercoco & Technici4n
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package aztech.modern_industrialization.attributes;

import aztech.modern_industrialization.MIText;
import aztech.modern_industrialization.items.tools.QuantumSword;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.item.TooltipFlag;

public class InfiniteDamageAttribute extends DisplayNamedAttribute {
private static final String INFINITY = "\u221e";

public InfiniteDamageAttribute() {
super(MIText.AttributeInfiniteDamage.getTranslationKey(), 0);
}

// Allows a modifier with the base id to render green with the effective value.
// Other modifiers still render blue with the additional value.
@Override
public ResourceLocation getBaseId() {
return QuantumSword.BASE_INFINITE_DAMAGE;
}

@Override
public MutableComponent toValueComponent(AttributeModifier.Operation operation, double value, TooltipFlag flag) {
return Component.literal(INFINITY);
}

@Override
public MutableComponent toBaseComponent(double value, double entityBase, boolean merged, TooltipFlag flag) {
String stringValue = value > Mth.EPSILON ? INFINITY : FORMAT.format(0);
MutableComponent comp = Component.translatable("attribute.modifier.equals.0", stringValue,
Component.translatable(this.getTooltipDescriptionId()));
if (flag.isAdvanced() && !merged) {
Component debugInfo = Component.literal(" ")
.append(Component.translatable("neoforge.attribute.debug.base", FORMAT.format(entityBase), FORMAT.format(value - entityBase))
.withStyle(ChatFormatting.GRAY));
comp.append(debugInfo);
}
return comp;
}

@Override
public String getTooltipDescriptionId() {
return "attribute.name.generic.attack_damage";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
/*
* MIT License
*
* Copyright (c) 2020 Azercoco & Technici4n
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package aztech.modern_industrialization.attributes;

import aztech.modern_industrialization.MIText;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.MutableComponent;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.item.TooltipFlag;

public class QuantumArmorAttribute extends DisplayNamedAttribute {
public QuantumArmorAttribute() {
super(MIText.AttributeQuantumArmor.getTranslationKey(), 0);
}

@Override
public MutableComponent toValueComponent(AttributeModifier.Operation operation, double value, TooltipFlag flag) {
return Component.literal("\u00B9\u2044\u2084 |\u221E> + \u00B3\u2044\u2084 |0>");
}

@Override
public String getTooltipDescriptionId() {
return "attribute.name.generic.armor";
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,23 +25,17 @@

import aztech.modern_industrialization.MI;
import aztech.modern_industrialization.MIComponents;
import aztech.modern_industrialization.MIText;
import aztech.modern_industrialization.items.ActivatableItem;
import dev.technici4n.grandpower.api.ISimpleEnergyItem;
import java.util.List;
import net.minecraft.ChatFormatting;
import net.minecraft.core.component.DataComponentType;
import net.minecraft.network.chat.Component;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.entity.EquipmentSlot;
import net.minecraft.world.entity.EquipmentSlotGroup;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Rarity;
import net.minecraft.world.item.TooltipFlag;
import net.minecraft.world.item.component.ItemAttributeModifiers;
import net.minecraft.world.level.Level;
import net.neoforged.neoforge.common.NeoForgeMod;
Expand All @@ -60,8 +54,7 @@ public ItemAttributeModifiers getDefaultAttributeModifiers(ItemStack stack) {
NeoForgeMod.CREATIVE_FLIGHT,
new AttributeModifier(MI.id("gravichestplate_flight"), 1, AttributeModifier.Operation.ADD_VALUE),
EquipmentSlotGroup.CHEST)
.build()
.withTooltip(false);
.build();
}
return ItemAttributeModifiers.EMPTY;
}
Expand Down Expand Up @@ -117,11 +110,4 @@ public long getEnergyMaxInput(ItemStack stack) {
public long getEnergyMaxOutput(ItemStack stack) {
return 0;
}

@Override
public void appendHoverText(ItemStack stack, Item.TooltipContext context, List<Component> list, TooltipFlag flag) {
list.add(Component.empty());
list.add(Component.translatable("item.modifiers." + getType().getSlot().getName()).withStyle(ChatFormatting.GRAY));
list.add(MIText.AllowCreativeFlight.text().withStyle(ChatFormatting.BLUE));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
package aztech.modern_industrialization.items.armor;

import aztech.modern_industrialization.MIItem;
import aztech.modern_industrialization.MIRegistries;
import java.util.concurrent.ThreadLocalRandom;
import net.minecraft.world.damagesource.DamageTypes;
import net.minecraft.world.entity.EquipmentSlot;
Expand All @@ -37,12 +38,7 @@ private MIArmorEffects() {
}

public static boolean quantumArmorPreventsDamage(LivingEntity entity) {
int parts = 0;
for (QuantumArmorItem item : QuantumArmorItem.ITEMS) {
if (entity.getItemBySlot(item.getType().getSlot()).getItem() == item) {
parts++;
}
}
double parts = entity.getAttributeValue(MIRegistries.QUANTUM_ARMOR);
return ThreadLocalRandom.current().nextDouble() < parts / 4d;
}

Expand Down
Loading
Loading