Skip to content

Commit

Permalink
amalgamite
Browse files Browse the repository at this point in the history
crystal code working FINALLY
  • Loading branch information
gemsb committed Jan 5, 2024
1 parent 7eccf08 commit 537ff7b
Show file tree
Hide file tree
Showing 13 changed files with 180 additions and 89 deletions.
2 changes: 2 additions & 0 deletions src/main/java/net/ugi/sculk_depths/block/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ public class ModBlocks {

public static final Block SOUL_FIRE = registerBlockWithoutBlockItem("soul_fire", new SoulFireBlock(FabricBlockSettings.copyOf(Blocks.SOUL_FIRE)), ModItemGroup.SCULK_DEPTHS);

public static final Block AMALGAMITE = registerBlock("amalgamite",
new Block(FabricBlockSettings.copyOf(Blocks.DEEPSLATE).strength(5.0f,8f).requiresTool()), ModItemGroup.SCULK_DEPTHS);
public static final Block LARGUTH = registerBlock("larguth",
new Block(FabricBlockSettings.copyOf(Blocks.OBSIDIAN).strength(40.0f,1000f).requiresTool()), ModItemGroup.SCULK_DEPTHS);
//umbrusk blockset
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package net.ugi.sculk_depths.item.crystal;

import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import net.fabricmc.fabric.api.client.item.v1.ItemTooltipCallback;
import net.minecraft.entity.EquipmentSlot;
Expand All @@ -9,12 +10,14 @@
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.ugi.sculk_depths.SculkDepths;
import net.ugi.sculk_depths.block.enums.CrystalType;
import net.ugi.sculk_depths.item.ModItems;
import net.ugi.sculk_depths.tags.ModTags;
Expand Down Expand Up @@ -66,6 +69,8 @@ public static ActionResult createCrystalUpgrade(ItemStack stack, PlayerEntity pl
public static void addAttributeToCrystalUpgrade(ItemStack stack, PlayerEntity player, CrystalType crystal) {
EquipmentSlot slot = EquipmentSlot.MAINHAND;
Multimap<EntityAttribute, EntityAttributeModifier> modifiers = stack.getAttributeModifiers(slot);
SculkDepths.LOGGER.info(modifiers.toString());
Multimap<EntityAttribute, EntityAttributeModifier> modifiers2 = HashMultimap.create();

if(stack.getItem() == ModItems.QUAZARITH_SHOVEL){
if (crystal == CrystalType.WHITE){
Expand Down Expand Up @@ -98,7 +103,13 @@ public static void addAttributeToCrystalUpgrade(ItemStack stack, PlayerEntity pl
if(stack.getItem() == ModItems.QUAZARITH_SWORD){

if (crystal == CrystalType.WHITE){
modifiers.put(EntityAttributes.GENERIC_ATTACK_DAMAGE, new EntityAttributeModifier( "Attack Damage", 2,EntityAttributeModifier.Operation.ADDITION));
modifiers2 = addAttribute(modifiers,modifiers2, EntityAttributes.GENERIC_ATTACK_DAMAGE, Item.ATTACK_DAMAGE_MODIFIER_ID,"Attack Damage", 20,EntityAttributeModifier.Operation.ADDITION);
modifiers2 = addAttribute(modifiers,modifiers2, EntityAttributes.GENERIC_ATTACK_SPEED, Item.ATTACK_SPEED_MODIFIER_ID,"Attack Speed", 2,EntityAttributeModifier.Operation.ADDITION);
modifiers2 = addAttribute(modifiers,modifiers2, EntityAttributes.GENERIC_MOVEMENT_SPEED, UUID.randomUUID(),"Movement Speed", 20,EntityAttributeModifier.Operation.ADDITION);
}
if (crystal == CrystalType.ORANGE){

modifiers2 = addAttribute(modifiers,modifiers2, EntityAttributes.GENERIC_MOVEMENT_SPEED, UUID.randomUUID(),"Movement Speed", 20,EntityAttributeModifier.Operation.ADDITION);
}
}

Expand Down Expand Up @@ -126,15 +137,55 @@ public static void addAttributeToCrystalUpgrade(ItemStack stack, PlayerEntity pl
if(stack.getItem() == ModItems.QUAZARITH_BOOTS){

if (crystal == CrystalType.WHITE){
modifiers.put(EntityAttributes.GENERIC_ATTACK_DAMAGE, new EntityAttributeModifier( "Attack Damage", 2,EntityAttributeModifier.Operation.ADDITION));
modifiers.put(EntityAttributes.GENERIC_ATTACK_DAMAGE, new EntityAttributeModifier( "Attack Damage", 2, EntityAttributeModifier.Operation.ADDITION));
}
}

Multimap<EntityAttribute, EntityAttributeModifier> finalModifiers = modifiers2;
modifiers.forEach((entityAttribute, entityAttributeModifier) -> {
int check[] = {0};
finalModifiers.forEach((entityAttribute2, entityAttributeModifier2) -> {
SculkDepths.LOGGER.info(entityAttribute.toString() + ", " + entityAttributeModifier.toString());
if (entityAttributeModifier2.getId().equals(entityAttributeModifier.getId())) {
check[0] = 1;
}

});
if (check[0] == 0){
finalModifiers.put(entityAttribute,entityAttributeModifier);
}


});


EquipmentSlot slot2 = getEquipmentSlot(stack.getItem());

finalModifiers.forEach((entityAttribute, entityAttributeModifier) -> {
stack.addAttributeModifier(entityAttribute, new EntityAttributeModifier(entityAttributeModifier.getId(), entityAttributeModifier.getName(), entityAttributeModifier.getValue(), entityAttributeModifier.getOperation()) , slot2);
});
}

public static Multimap<EntityAttribute, EntityAttributeModifier> addAttribute(Multimap<EntityAttribute, EntityAttributeModifier> modifiers,Multimap<EntityAttribute, EntityAttributeModifier> modifiers2, EntityAttribute attribute, UUID uuid, String name, double value, EntityAttributeModifier.Operation operation){
final int[] check = {0};
modifiers.forEach((entityAttribute, entityAttributeModifier) -> {
stack.addAttributeModifier(entityAttribute, new EntityAttributeModifier(Item.ATTACK_DAMAGE_MODIFIER_ID, entityAttributeModifier.getName(), entityAttributeModifier.getValue(), entityAttributeModifier.getOperation()) , slot2);
if (entityAttributeModifier.getId().equals(uuid)) {
check[0] = 1;
if (operation == EntityAttributeModifier.Operation.ADDITION){
double originalValue = entityAttributeModifier.getValue();
modifiers2.put(attribute, new EntityAttributeModifier(uuid,name, originalValue + value, operation));
}
if (operation == EntityAttributeModifier.Operation.MULTIPLY_TOTAL){
double originalValue = entityAttributeModifier.getValue();
modifiers2.put(attribute, new EntityAttributeModifier(uuid,name, originalValue * value, operation));
}
}

});
if (check[0] == 0){
modifiers2.put(attribute, new EntityAttributeModifier( uuid,name, value, operation));
}
return modifiers2;
}

public static void addNbtToCrystalUpgrade(ItemStack stack, PlayerEntity player, CrystalType crystal) {
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/net/ugi/sculk_depths/mixin/ItemAccessorMixin.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package net.ugi.sculk_depths.mixin;

import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;
import org.spongepowered.asm.mixin.gen.Invoker;

import java.util.UUID;

@Mixin(Item.class)
public interface ItemAccessorMixin {
@Accessor
static UUID getATTACK_DAMAGE_MODIFIER_ID() {
throw new AssertionError(); // never called
}
@Accessor
static UUID getATTACK_SPEED_MODIFIER_ID() {
throw new AssertionError(); // never called
}
}
19 changes: 10 additions & 9 deletions src/main/java/net/ugi/sculk_depths/mixin/ItemStackMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,31 @@
import net.minecraft.item.ItemStack;
import net.minecraft.util.Uuids;
import org.apache.logging.log4j.core.config.plugins.convert.TypeConverters;
import org.slf4j.Logger;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;

import java.util.UUID;

@Mixin(ItemStack.class)
public class ItemStackMixin{

@Shadow @Final private static Logger LOGGER;

@ModifyExpressionValue(
method = "getTooltip",
at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/attribute/EntityAttributeModifier;getId()Ljava/util/UUID;")

)
private static UUID fixBug(UUID original){
if (original.equals(Item.ATTACK_DAMAGE_MODIFIER_ID)) {
return Item.ATTACK_DAMAGE_MODIFIER_ID;
if (original.equals(ItemAccessorMixin.getATTACK_DAMAGE_MODIFIER_ID())) {
return ItemAccessorMixin.getATTACK_DAMAGE_MODIFIER_ID();
}
if (original.equals(ItemAccessorMixin.getATTACK_SPEED_MODIFIER_ID())) {
return ItemAccessorMixin.getATTACK_SPEED_MODIFIER_ID();
}
return original;
}

/* @ModifyExpressionValue(
method = "getTooltip",
at = @At(value = "HEAD", target = "Lnet/minecraft/item/Item;ATTACK_DAMAGE_MODIFIER_ID:Ljava/util/UUID")
)*/

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"variants": {
"": { "model": "sculk_depths:block/amalgamite" }
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "sculk_depths:block/amalgamite"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "sculk_depths:block/amalgamite"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
Expand Up @@ -469,7 +469,7 @@
"type": "minecraft:condition",
"if_true": {
"type": "minecraft:vertical_gradient",
"random_name": "minecraft:deepslate",
"random_name": "sculk_depths:amalgamite",
"true_at_and_below": {
"absolute": 72
},
Expand All @@ -480,7 +480,7 @@
"then_run": {
"type": "minecraft:block",
"result_state": {
"Name": "minecraft:deepslate",
"Name": "sculk_depths:amalgamite",
"Properties": {
"axis": "y"
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"values": [
"minecraft:deepslate"
"minecraft:deepslate",
"sculk_depths:amalgamite"
]
}
Loading

0 comments on commit 537ff7b

Please sign in to comment.