-
Notifications
You must be signed in to change notification settings - Fork 40
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #857 from ZhuRuoLing/dev
添加更多生物转化
- Loading branch information
Showing
14 changed files
with
392 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
common/src/main/java/dev/dubhe/anvilcraft/data/recipe/transform/TransformOptions.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package dev.dubhe.anvilcraft.data.recipe.transform; | ||
|
||
import com.google.gson.JsonElement; | ||
import com.google.gson.JsonObject; | ||
import com.mojang.serialization.Codec; | ||
import com.mojang.serialization.JsonOps; | ||
import dev.dubhe.anvilcraft.init.ModBlocks; | ||
import net.minecraft.util.StringRepresentable; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.EquipmentSlot; | ||
import net.minecraft.world.entity.LivingEntity; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.Items; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public enum TransformOptions implements StringRepresentable { | ||
|
||
KEEP_INVENTORY("keepInventory") { | ||
@Override | ||
public void accept(Entity oldEntity, Entity newEntity) { | ||
if (newEntity instanceof LivingEntity n && oldEntity instanceof LivingEntity o) { | ||
for (EquipmentSlot value : EquipmentSlot.values()) { | ||
n.setItemSlot(value, o.getItemBySlot(value)); | ||
} | ||
for (InteractionHand value : InteractionHand.values()) { | ||
n.setItemInHand(value, o.getItemInHand(value)); | ||
} | ||
} | ||
} | ||
}, | ||
REPLACE_ANVIL("replaceAnvil") { | ||
@Override | ||
public void accept(Entity oldEntity, Entity newEntity) { | ||
if (newEntity instanceof LivingEntity n && oldEntity instanceof LivingEntity o) { | ||
for (InteractionHand value : InteractionHand.values()) { | ||
ItemStack itemStack = o.getItemInHand(value); | ||
if (itemStack.is(Items.ANVIL) | ||
|| itemStack.is(Items.CHIPPED_ANVIL) | ||
|| itemStack.is(Items.DAMAGED_ANVIL)) { | ||
o.setItemInHand(value, ModBlocks.HEAVY_IRON_BLOCK.asItem().getDefaultInstance()); | ||
n.setItemInHand(value, ModBlocks.HEAVY_IRON_BLOCK.asItem().getDefaultInstance()); | ||
} | ||
} | ||
} | ||
} | ||
}; | ||
|
||
public static final Codec<TransformOptions> CODEC = StringRepresentable.fromEnum(TransformOptions::values); | ||
private final String name; | ||
|
||
TransformOptions(String name) { | ||
this.name = name; | ||
} | ||
|
||
@Override | ||
public @NotNull String getSerializedName() { | ||
return name; | ||
} | ||
|
||
public abstract void accept(Entity oldEntity, Entity newEntity); | ||
|
||
/** | ||
* | ||
*/ | ||
public static TransformOptions fromJson(JsonObject jsonObject) { | ||
return CODEC.decode(JsonOps.INSTANCE, jsonObject) | ||
.getOrThrow(false, s -> { | ||
}).getFirst(); | ||
} | ||
|
||
/** | ||
* | ||
*/ | ||
public JsonElement toJson() { | ||
return CODEC.encodeStart(JsonOps.INSTANCE, this) | ||
.getOrThrow(false, s -> { | ||
}); | ||
} | ||
} |
Oops, something went wrong.