Skip to content

Commit

Permalink
feat: 添加效果射綫魔法
Browse files Browse the repository at this point in the history
  • Loading branch information
northgreen committed Apr 23, 2024
1 parent a9bcaae commit 8568c0b
Show file tree
Hide file tree
Showing 24 changed files with 338 additions and 23 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.19.2 2024-04-23T16:27:26.7336147 Language
d04d40d92f525332cba17675dca053783f282d5b assets\the_origin_of_magic\lang\en_us.json
// 1.19.2 2024-04-23T22:39:15.7231787 Language
7cd0c9ec37de0a8d5af1a51cd38da5908dffbc8b assets\the_origin_of_magic\lang\en_us.json
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.19.2 2024-04-23T16:27:26.736128 Block Loot Tables
// 1.19.2 2024-04-23T22:39:15.7256416 Block Loot Tables
fe57f13449a11436bbede8c37e01bd0d1cd87191 data\the_origin_of_magic\loot_tables\blocks\magic_workbench.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.19.2 2024-04-23T16:27:26.7391245 Models
// 1.19.2 2024-04-23T22:39:15.7276744 Models
181423bcaae52ae5cf7cee43b878159bada3a241 assets\the_origin_of_magic\models\item\instant_damage_magic.json
02d3ff4716d16f7c5a4dd4432d1b98f744a13f02 assets\the_origin_of_magic\models\item\blood_essence.json
105ea751d9d55fefa41f158e8e462c2e69f451ed assets\the_origin_of_magic\models\item\magic_life_time_up.json
Expand All @@ -12,6 +12,7 @@ ddf4e605ac73f757f76bbfe39d60312b7042e7d9 assets\the_origin_of_magic\models\item\
43e2c3caac7463f02d4048ca73f166772b1e1cb3 assets\the_origin_of_magic\models\item\magic_life_time_down.json
14f7b54096acc0b1b7b588d72bd80df62d566018 assets\the_origin_of_magic\models\item\earth_magic_element.json
da16015585e364c4561b91a3b83056d8c3646d1c assets\the_origin_of_magic\models\item\gold_magic_element.json
1dce304afb036f29cfc41d921aca0fd0bb0e8f7a assets\the_origin_of_magic\models\item\ray_magic.json
681374800d5b4991c2e8d6304781b89089bd379c assets\the_origin_of_magic\models\item\poison_magic.json
7091cce590f8bb481903e0177866dfcb338f42c0 assets\the_origin_of_magic\models\item\magic_core.json
03b1f5cc891077d36d38a8d98d2ffe49396f8229 assets\the_origin_of_magic\models\item\water_magic_element.json
Expand Down
17 changes: 17 additions & 0 deletions src/main/generated/assets/the_origin_of_magic/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,23 @@
"item.the_origin_of_magic.magic_life_time_up": "Magic Life Time Up",
"item.the_origin_of_magic.nature_magic_element": "Nature Magic Element",
"item.the_origin_of_magic.poison_magic": "Poison Magic",
"item.the_origin_of_magic.ray_magic": "Ray Magic",
"item.the_origin_of_magic.ray_magic.effect.fire_resistance": "Fire resistance Ray Magic",
"item.the_origin_of_magic.ray_magic.effect.harming": "Harming Ray Magic",
"item.the_origin_of_magic.ray_magic.effect.healing": "Healing Ray Magic",
"item.the_origin_of_magic.ray_magic.effect.invisibility": "Invisibility Ray Magic",
"item.the_origin_of_magic.ray_magic.effect.leaping": "Leaping Ray Magic",
"item.the_origin_of_magic.ray_magic.effect.luck": "Luck Ray Magic",
"item.the_origin_of_magic.ray_magic.effect.night_vision": "Night vision Ray Magic",
"item.the_origin_of_magic.ray_magic.effect.poison": "Poison Ray Magic",
"item.the_origin_of_magic.ray_magic.effect.regeneration": "Regeneration Ray Magic",
"item.the_origin_of_magic.ray_magic.effect.slow_falling": "Slow falling Ray Magic",
"item.the_origin_of_magic.ray_magic.effect.slowness": "Slowness Ray Magic",
"item.the_origin_of_magic.ray_magic.effect.strength": "Strength Ray Magic",
"item.the_origin_of_magic.ray_magic.effect.swiftness": "Swiftness Ray Magic",
"item.the_origin_of_magic.ray_magic.effect.turtle_master": "Turtle master Ray Magic",
"item.the_origin_of_magic.ray_magic.effect.water_breathing": "Water breathing Ray Magic",
"item.the_origin_of_magic.ray_magic.effect.weakness": "Weakness Ray Magic",
"item.the_origin_of_magic.test_staff": "Test Staff",
"item.the_origin_of_magic.test_staff.tooltip": "Only For Codding Test",
"item.the_origin_of_magic.water_magic_element": "Water Magic Element",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,15 @@ public class AllEntity {
"magic_bullet"
);

public static final EntityType<StdThrownMagic> POISON_RAY_MAGIC_ENTITY_TYPE = the_origin_of_magic.MOD_REGISTRATE.entityBuilder(
FabricEntityTypeBuilder
.<StdThrownMagic>create(SpawnGroup.MISC, RayMagic::new)
.dimensions(EntityDimensions.fixed(0.25F, 0.25F))
.trackRangeBlocks(4).trackedUpdateRate(10)
.build(),
"poison_ray_magic"
);


/**
* 注冊魔法實體渲染器
Expand All @@ -67,5 +76,6 @@ public static void regEntityRenderer(){
EntityRendererRegistry.register(POISON_MAGIC_ENTITY_TYPE, FlyingItemEntityRenderer::new);
EntityRendererRegistry.register(INSTANT_DAMAGE_ENTITY_TYPE, FlyingItemEntityRenderer::new);
EntityRendererRegistry.register(MAGIC_BULLET_ENTITY_TYPE, MagicRender::new);
EntityRendererRegistry.register(POISON_RAY_MAGIC_ENTITY_TYPE, MagicRender::new);
}
}
18 changes: 14 additions & 4 deletions src/main/java/com/ictye/the_origin_of_magic/Contents/AllItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,8 @@

import com.ictye.the_origin_of_magic.foundation.Items.Magic.CorrectionMagic.MagicLIfeTimeDownItem;
import com.ictye.the_origin_of_magic.foundation.Items.Magic.CorrectionMagic.MagicLifeTimeUpItem;
import com.ictye.the_origin_of_magic.foundation.Items.Magic.ExplosionMagicEntityItem;
import com.ictye.the_origin_of_magic.foundation.Items.Magic.InstantDamageMagicItem;
import com.ictye.the_origin_of_magic.foundation.Items.Magic.*;
import com.ictye.the_origin_of_magic.foundation.Items.Magic.LimiterItem.UndeadEntityLimiterItem;
import com.ictye.the_origin_of_magic.foundation.Items.Magic.MagicBulletItem;
import com.ictye.the_origin_of_magic.foundation.Items.Magic.PoisonMagicEntityItem;
import com.ictye.the_origin_of_magic.foundation.Items.Staff.DeadwoodStaff;
import com.ictye.the_origin_of_magic.foundation.Items.Staff.TestStaff;
import com.ictye.the_origin_of_magic.infrastructure.ModRegistrate;
Expand Down Expand Up @@ -108,6 +105,19 @@ public class AllItem {
AllEntity.INSTANT_DAMAGE_ENTITY_TYPE
);

public static final Item RAY_MAGIC_ITEM = the_origin_of_magic.MOD_REGISTRATE.itemBuilder(
RayMagicItem::new,
"ray_magic",
"Ray Magic",
Models.GENERATED,
new FabricItemSettings()
.maxCount(1)
.group(TheOriginOfMagicItemGroup)
.maxDamage(100)
.rarity(Rarity.COMMON),
AllEntity.POISON_RAY_MAGIC_ENTITY_TYPE
);

public static final Item MAGIC_BULLET_ITEM = the_origin_of_magic.MOD_REGISTRATE.itemBuilder(
MagicBulletItem::new,
"magic_bullet",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,173 @@
package com.ictye.the_origin_of_magic.foundation.Entitys.Magics;

import com.google.common.collect.Sets;
import com.ictye.the_origin_of_magic.Contents.AllItem;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.data.DataTracker;
import net.minecraft.entity.data.TrackedData;
import net.minecraft.entity.data.TrackedDataHandlerRegistry;
import net.minecraft.entity.effect.StatusEffectInstance;
import net.minecraft.entity.projectile.thrown.ThrownEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.nbt.NbtElement;
import net.minecraft.nbt.NbtList;
import net.minecraft.particle.ParticleTypes;
import net.minecraft.potion.Potion;
import net.minecraft.potion.PotionUtil;
import net.minecraft.potion.Potions;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;

import java.util.List;
import java.util.Set;

public class RayMagic extends StdThrownMagic{
private static final TrackedData<Integer> COLOR = DataTracker.registerData(RayMagic.class, TrackedDataHandlerRegistry.INTEGER);
private boolean colorSet;
private Potion potion = Potions.EMPTY;
private final Set<StatusEffectInstance> effects = Sets.newHashSet();

public RayMagic(EntityType<? extends ThrownEntity> entityType, World world) {
super(entityType, world);
}

public RayMagic(EntityType<? extends ThrownEntity> type, LivingEntity owner, World world, float explosionRate, int ageRate) {
super(type, owner, world, explosionRate, ageRate);
}

public RayMagic(EntityType<? extends ThrownEntity> type, LivingEntity owner, World world, float explosionRate, int ageRate, ItemStack stack) {
super(type, owner, world, explosionRate, ageRate);
if (stack.isOf(AllItem.RAY_MAGIC_ITEM)) {
int i;
this.potion = PotionUtil.getPotion(stack);
List<StatusEffectInstance> collection = PotionUtil.getCustomPotionEffects(stack);
if (!collection.isEmpty()) {
for (StatusEffectInstance statusEffectInstance : collection) {
this.effects.add(new StatusEffectInstance(statusEffectInstance));
}
}
if ((i = RayMagic.getCustomPotionColor(stack)) == -1) {
this.initColor();
} else {
this.setColor(i);
}
} else {
this.potion = Potions.EMPTY;
this.effects.clear();
this.dataTracker.set(COLOR, -1);
}
}

public static int getCustomPotionColor(ItemStack stack) {
NbtCompound nbtCompound = stack.getNbt();
if (nbtCompound != null && nbtCompound.contains("CustomPotionColor", NbtElement.NUMBER_TYPE)) {
return nbtCompound.getInt("CustomPotionColor");
}
return -1;
}

@Override
protected void initDataTracker() {
super.initDataTracker();
this.dataTracker.startTracking(COLOR, -1);
}

public int getColor() {
return this.dataTracker.get(COLOR);
}

private void setColor(int color) {
this.colorSet = true;
this.dataTracker.set(COLOR, color);
}

@Override
protected float getGravity() {
return 0;
}

@Override
protected void onEntityHit(EntityHitResult entityHitResult) {
LivingEntity target = (LivingEntity) entityHitResult.getEntity();
Entity entity = this.getEffectCause();
for (StatusEffectInstance statusEffectInstance : this.potion.getEffects()) {
target.addStatusEffect(new StatusEffectInstance(statusEffectInstance.getEffectType(), Math.max(statusEffectInstance.getDuration() / 8, 1), statusEffectInstance.getAmplifier(), statusEffectInstance.isAmbient(), statusEffectInstance.shouldShowParticles()), entity);
}
if (!this.effects.isEmpty()) {
for (StatusEffectInstance statusEffectInstance : this.effects) {
target.addStatusEffect(statusEffectInstance, entity);
}
}

super.onEntityHit(entityHitResult);
this.remove(RemovalReason.CHANGED_DIMENSION);
}

@Override
public void tick() {
int i = this.getColor();
double d = (double)(i >> 16 & 0xFF) / 255.0;
double e = (double)(i >> 8 & 0xFF) / 255.0;
double f = (double)(i >> 0 & 0xFF) / 255.0;
this.world.addParticle(ParticleTypes.ENTITY_EFFECT, this.getParticleX(0.5), this.getRandomBodyY(), this.getParticleZ(0.5), d, e, f);
super.tick();
}

@Override
public ItemStack getStack() {
return new ItemStack(Items.AIR);
}

@Override
public void writeCustomDataToNbt(NbtCompound nbt) {
super.writeCustomDataToNbt(nbt);
if (this.potion != Potions.EMPTY) {
nbt.putString("Potion", Registry.POTION.getId(this.potion).toString());
}
if (this.colorSet) {
nbt.putInt("Color", this.getColor());
}
if (!this.effects.isEmpty()) {
NbtList nbtList = new NbtList();
for (StatusEffectInstance statusEffectInstance : this.effects) {
nbtList.add(statusEffectInstance.writeNbt(new NbtCompound()));
}
nbt.put("CustomPotionEffects", nbtList);
}
}

private void initColor() {
this.colorSet = false;
if (this.potion == Potions.EMPTY && this.effects.isEmpty()) {
this.dataTracker.set(COLOR, -1);
} else {
this.dataTracker.set(COLOR, PotionUtil.getColor(PotionUtil.getPotionEffects(this.potion, this.effects)));
}
}

public void addEffect(StatusEffectInstance effect) {
this.effects.add(effect);
this.getDataTracker().set(COLOR, PotionUtil.getColor(PotionUtil.getPotionEffects(this.potion, this.effects)));
}

@Override
public void readCustomDataFromNbt(NbtCompound nbt) {
super.readCustomDataFromNbt(nbt);
if (nbt.contains("Potion", NbtElement.STRING_TYPE)) {
this.potion = PotionUtil.getPotion(nbt);
}
for (StatusEffectInstance statusEffectInstance : PotionUtil.getCustomPotionEffects(nbt)) {
this.addEffect(statusEffectInstance);
}
if (nbt.contains("Color", NbtElement.NUMBER_TYPE)) {
this.setColor(nbt.getInt("Color"));
} else {
this.initColor();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.ictye.the_origin_of_magic.foundation.Items.Magic.StdMagicItem;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class MagicLIfeTimeDownItem extends StdMagicItem {
Expand All @@ -14,7 +15,7 @@ public MagicLIfeTimeDownItem(Settings settings, EntityType<StdThrownMagic> entit
}

@Override
public StdMagicInterface getMagic(PlayerEntity user, World world, float excisionRate, int hartRate) {
public StdMagicInterface getMagic(PlayerEntity user, World world, float excisionRate, int hartRate, ItemStack itemStack) {
return new MagicLifeTimeDown();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.ictye.the_origin_of_magic.foundation.Items.Magic.StdMagicItem;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class MagicLifeTimeUpItem extends StdMagicItem {
Expand All @@ -14,7 +15,7 @@ public MagicLifeTimeUpItem(Settings settings, EntityType<StdThrownMagic> entityT
}

@Override
public StdMagicInterface getMagic(PlayerEntity user, World world, float excisionRate, int hartRate) {
public StdMagicInterface getMagic(PlayerEntity user, World world, float excisionRate, int hartRate, ItemStack itemStack) {
return new MagicLifeTimeUp();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> too
}

@Override
public StdThrownMagic getMagic(PlayerEntity user, World world, float explosionRate, int hartRate) {
public StdThrownMagic getMagic(PlayerEntity user, World world, float explosionRate, int hartRate ,ItemStack itemStack) {
return new ExplosionThrownMagic(magicEntityType,user,world,explosionRate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdThrownMagic;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class InstantDamageMagicItem extends StdMagicItem {
Expand All @@ -14,7 +15,7 @@ public InstantDamageMagicItem(Settings settings, EntityType<StdThrownMagic> enti
}

@Override
public StdMagicInterface getMagic(PlayerEntity user, World world, float excisionRate, int hartRate) {
public StdMagicInterface getMagic(PlayerEntity user, World world, float excisionRate, int hartRate, ItemStack itemStack) {
return new InstantDamageItemMagic(AllEntity.INSTANT_DAMAGE_ENTITY_TYPE,user, world);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> too
}

@Override
public StdMagicInterface getMagic(PlayerEntity user, World world, float excisionRate, int hartRate) {
public StdMagicInterface getMagic(PlayerEntity user, World world, float excisionRate, int hartRate,ItemStack itemStack) {
return new HostileEntityLimiter();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdThrownMagic;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

public class MagicBulletItem extends StdMagicItem{
Expand All @@ -14,7 +15,7 @@ public MagicBulletItem(Settings settings, EntityType<StdThrownMagic> entityType)
}

@Override
public StdMagicInterface getMagic(PlayerEntity user, World world, float excisionRate, int hartRate) {
public StdMagicInterface getMagic(PlayerEntity user, World world, float excisionRate, int hartRate, ItemStack itemStack) {
return new MagicBullet(AllEntity.MAGIC_BULLET_ENTITY_TYPE, user, world);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdThrownMagic;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;

import static com.ictye.the_origin_of_magic.Contents.AllEntity.POISON_MAGIC_ENTITY_TYPE;
Expand All @@ -19,7 +20,7 @@ public PoisonMagicEntityItem(Settings settings, EntityType<StdThrownMagic> entit
}

@Override
public StdMagicInterface getMagic(PlayerEntity user, World world, float excisionRate, int hartRate) {
public StdMagicInterface getMagic(PlayerEntity user, World world, float excisionRate, int hartRate, ItemStack itemStack) {
return new PoisonThrownMagic(POISON_MAGIC_ENTITY_TYPE,user,world);
}
}
Loading

0 comments on commit 8568c0b

Please sign in to comment.