Skip to content

Commit

Permalink
fix: 修复一个施放魔法的bug,但是我们又添加了另一个bug()
Browse files Browse the repository at this point in the history
  • Loading branch information
northgreen committed Apr 27, 2024
1 parent 8605d91 commit fe65095
Show file tree
Hide file tree
Showing 17 changed files with 180 additions and 19 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.19.2 2024-04-26T22:04:29.1768104 Language
3851efb5ab185dfcb547eb5bcb77baad65fa6623 assets\the_origin_of_magic\lang\en_us.json
// 1.19.2 2024-04-27T17:58:45.6994048 Language
e20b0ea5b300d1f01ca66c6725d1e0c00be855ef 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-26T22:04:29.1788149 Block Loot Tables
// 1.19.2 2024-04-27T17:58:45.6969072 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,5 +1,6 @@
// 1.19.2 2024-04-26T22:04:29.1813286 Models
// 1.19.2 2024-04-27T17:58:45.694408 Models
e61b535cd7ab658695681160ffbc526e0b8655f4 assets\the_origin_of_magic\models\item\magic_bullet_with_trigger.json
6e0df2c99a9c005ddce1ec13cf27aff50ee1081f assets\the_origin_of_magic\models\item\magic_bullet_with_time_trigger.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
781092579f171cf0db8317aa6267ad8e5cfbbd1f assets\the_origin_of_magic\models\item\fire_magic_element.json
Expand Down
2 changes: 2 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 @@ -11,6 +11,7 @@
"item.the_origin_of_magic.hostile_entity_limiter": "Hostile Entity Limiter",
"item.the_origin_of_magic.kind_magic_element": "Kind Magic Element",
"item.the_origin_of_magic.magic_bullet": "Magic Bullet",
"item.the_origin_of_magic.magic_bullet_with_time_trigger": "Magic Bullet With Time Trigger",
"item.the_origin_of_magic.magic_bullet_with_trigger": "Magic Bullet With Trigger",
"item.the_origin_of_magic.magic_core": "Magic Core",
"item.the_origin_of_magic.magic_life_time_down": "Magic Life Time Down",
Expand Down Expand Up @@ -41,6 +42,7 @@
"text.the_origin_of_magic.empty_staff": "Maybe...... I means that the staff on your hand is empty,no magic in it and can't cast any magic,you need to use the Magic Workbench to edit this staff",
"text.the_origin_of_magic.magic_work_station.staff_state": "Staff State",
"text.the_origin_of_magic.not_staff": "This is not a staff , have no magic energy.So you can't edit it with magic work station",
"text.the_origin_of_magic.random_cast": "Rundom Cast",
"text.the_origin_of_magic.staff_capacity": "Staff Capacity",
"text.the_origin_of_magic.staff_casting": "Casting Num",
"text.the_origin_of_magic.staff_scattering": "Spell Scatter",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "the_origin_of_magic:item/magic_bullet_with_time_trigger"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,15 @@ public class AllEntity {
);


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

/**
* 注冊魔法實體渲染器
*/
Expand All @@ -77,5 +86,6 @@ public static void regEntityRenderer(){
EntityRendererRegistry.register(MAGIC_BULLET_ENTITY_TYPE, MagicRender::new);
EntityRendererRegistry.register(POISON_RAY_MAGIC_ENTITY_TYPE, MagicRender::new);
EntityRendererRegistry.register(MAGIC_BULLET_WITH_TRIGGER_ENTITY_TYPE, MagicRender::new);
EntityRendererRegistry.register(MAGIC_BULLET_WITH_TIME_TRIGGER_ENTITY_TYPE, MagicRender::new);
}
}
13 changes: 13 additions & 0 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 @@ -132,6 +132,19 @@ public class AllItem {
AllEntity.MAGIC_BULLET_WITH_TRIGGER_ENTITY_TYPE
);

public static final Item MAGIC_BULLET_WITH_TIME_TRIGGER = the_origin_of_magic.MOD_REGISTRATE.itemBuilder(
MagicBulletWithTimeTriggerItem::new,
"magic_bullet_with_time_trigger",
"Magic Bullet With Time Trigger",
Models.GENERATED,
new FabricItemSettings()
.maxCount(1)
.group(TheOriginOfMagicItemGroup)
.maxDamage(100)
.rarity(Rarity.COMMON),
AllEntity.MAGIC_BULLET_WITH_TIME_TRIGGER_ENTITY_TYPE
);

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

import com.ictye.the_origin_of_magic.Contents.AllParticle;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.world.World;

public class MagicBulletWithTimeTrigger extends StdThrownMagic{
@Override
public float getMagicRate() {
return 2;
}

@Override
public boolean hasNoGravity() {
return true;
}

@Override
public void tick() {
super.tick();
world.addParticle(AllParticle.MAGIC_BULLET_PARTICLE, getX(), getY(), getZ(), 0, 0, 0);
world.addParticle(AllParticle.MAGIC_BULLET_PARTICLE, getX()*1.2, getY()*1.2, getZ()*1.2, 0, 0, 0);
world.addParticle(AllParticle.MAGIC_BULLET_PARTICLE, getX()*0.7, getY()*0.7, getZ()*0.7, 0, 0, 0);
world.addParticle(AllParticle.MAGIC_BULLET_PARTICLE, this.getParticleX(0.5) * 1.3, this.getRandomBodyY()* 1.3, this.getParticleZ(0.5)* 1.3, 0, 0, 0);
}

@Override
protected void onEntityHit(EntityHitResult entityHitResult) {
if(prdRandom!=null){
prdRandom.setSP((float) (prdRandom.getP() + 0.5));
if(prdRandom.getBool()){
entityHitResult.getEntity().damage(DamageSource.thrownProjectile(this, this.getOwner()), 7);
}else {
entityHitResult.getEntity().damage(DamageSource.thrownProjectile(this, this.getOwner()), 4);
}
}else {
entityHitResult.getEntity().damage(DamageSource.thrownProjectile(this, this.getOwner()), 4);
}

super.onEntityHit(entityHitResult);
}

@Override
public ItemStack getStack() {
return new ItemStack(Items.AIR);
}
public MagicBulletWithTimeTrigger(EntityType<? extends StdThrownMagic> entityType, World world) {
super(entityType, world);
this.ageCast = true;
this.additionalTrigger = 1;
}

public MagicBulletWithTimeTrigger(EntityType<? extends StdThrownMagic> type, LivingEntity owner, World world) {
super(type, owner, world);
this.ageCast = true;
this.additionalTrigger = 1;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ protected void castAddiMagic(HitResult hitResult){
magic.setPosition(this.getPos());
Vec3d v = this.getVelocity();
if(hitResult instanceof BlockHitResult blockHitResult){
// 撞到方塊后反彈
// 撞到方塊后反射
Direction face = blockHitResult.getSide();
if(face == Direction.UP || face == Direction.DOWN){
magic.setVelocity(new Vec3d(v.x,-v.y,v.z));
Expand All @@ -228,6 +228,7 @@ protected void castAddiMagic(HitResult hitResult){
}
}
}
this.remove(RemovalReason.DISCARDED);
}
}

Expand All @@ -251,10 +252,8 @@ protected void castAddiMagic(){
}

/**
* 對onCollision的包裝
* 對onCollision的包裝,任何撞擊都會調用此方法
* @param hitResult 撞擊結果
*
* @see #onCollision(HitResult)
*/
protected void collision(HitResult hitResult){
}
Expand Down Expand Up @@ -312,16 +311,23 @@ public void tick() {

age++;
if (age>=getAge() * this.ageRate){
this.remove(RemovalReason.CHANGED_DIMENSION);
}
for(StdEffectMagic effectMagic : effectMagicList){
effectMagic.tick(this.world);
}
}

@Override
public void remove(RemovalReason reason) {
if(reason!=RemovalReason.KILLED){
if(ageCast){
if(!world.isClient){
castAddiMagic();
}
}
this.remove(RemovalReason.CHANGED_DIMENSION);
}
for(StdEffectMagic effectMagic : effectMagicList){
effectMagic.tick(this.world);
}
super.remove(reason);
}

protected float getGravity() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.ictye.the_origin_of_magic.foundation.Items.Magic;

import com.ictye.the_origin_of_magic.Contents.AllEntity;
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.MagicBulletWithTimeTrigger;
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.MagicInterfaces.StdMagicInterface;
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 MagicBulletWithTimeTriggerItem extends StdMagicItem{
public MagicBulletWithTimeTriggerItem(Settings settings, EntityType<StdThrownMagic> entityType) {
super(settings, entityType);
}

@Override
public StdMagicInterface getMagic(PlayerEntity user, World world, ItemStack stack) {
return new MagicBulletWithTimeTrigger(AllEntity.MAGIC_BULLET_WITH_TIME_TRIGGER_ENTITY_TYPE,user, world);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdThrownMagic;
import com.ictye.the_origin_of_magic.foundation.Items.Magic.StdMagicItem;
import com.ictye.the_origin_of_magic.foundation.PlayerAbilities.MagicAbilitiesManager;
import com.ictye.the_origin_of_magic.the_origin_of_magic;
import com.ictye.the_origin_of_magic.utils.InterFaces.PlayerEntityMixinInterfaces;
import com.ictye.the_origin_of_magic.utils.MagicInventory;
import com.ictye.the_origin_of_magic.utils.Math.PRDRandom;
Expand All @@ -27,11 +28,13 @@
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;

/**
Expand Down Expand Up @@ -135,10 +138,10 @@ public abstract class StdStaff extends Item {
*/
int staffAgeRate;

float staffMagicLevel;

float staffMagicCastRate;

float staffMagicLevel;

public float getStaffMagicLevel() {
return staffMagicLevel;
}
Expand All @@ -157,6 +160,11 @@ public void setStaffMagicLevel(float staffMagicLevel) {
*/
protected PRDRandom random;

/**
* 魔杖是否隨機施放
*/
boolean randomCast = false;

public StdStaff(Settings settings) {
super(settings);
// 初始化各個參數
Expand Down Expand Up @@ -277,6 +285,9 @@ public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> too
.getString()).copy().formatted(Formatting.GREEN));
tooltip.add(Text.of(getCastingNum() +" " + Text.translatable("text.the_origin_of_magic.staff_casting")
.getString()).copy().formatted(Formatting.GREEN));
if(randomCast){
tooltip.add(Text.translatable("text.the_origin_of_magic.random_cast").formatted(Formatting.BLUE));
}
}

/**
Expand Down Expand Up @@ -310,9 +321,20 @@ public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand han
p = random.getP();
// 施放解析邏輯
int count = getCastingNum(); // 可釋放的數量
List<StdCastInterface> magicList = summonMagic(Magics, user, world, count, random);
List<StdCastInterface> magicList;
if(randomCast){
DefaultedList<ItemStack> magicStack = Magics.stacks;
Collections.shuffle(magicStack); // 打亂法術
MagicInventory inventory = new MagicInventory(magicStack);
magicList = summonMagic(inventory, user, world, count, random);
}else {
magicList = summonMagic(Magics, user, world, count, random);
}


// 生成法術實體
for (StdCastInterface MagicEntity : magicList) {
the_origin_of_magic.LOGGER.debug("MagicEntity: " + MagicEntity.getClass().getSimpleName());
if (MagicEntity instanceof StdThrownMagic Magic) {
MagicAbilitiesManager magicAbilitiesManager = ((PlayerEntityMixinInterfaces) user).the_origin_of_magic$getMagicAbilitiesManager();
Magic.setAgeRate(this.staffAgeRate);
Expand Down Expand Up @@ -358,6 +380,8 @@ private List<StdCastInterface> summonMagic(MagicInventory inventory, PlayerEntit
continue;
}

the_origin_of_magic.LOGGER.debug("Summon Magic: " + magicItem.getTranslationKey());

StdMagicInterface magic = ((StdMagicItem)magicItem).getMagic(user,world,itemStack);
// 分類討論()
if(magic instanceof StdCastInterface castInterface){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdDriestEffectMagic;
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdThrownMagic;
import com.ictye.the_origin_of_magic.infrastructure.netWork.NetworkIDFinder;
import com.ictye.the_origin_of_magic.the_origin_of_magic;
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
import net.fabricmc.fabric.api.networking.v1.ServerPlayNetworking;
import net.minecraft.entity.player.PlayerEntity;
Expand Down Expand Up @@ -36,10 +37,13 @@ public void setMagicLevel(float magicLevel) {
* @return 是否成功
*/
public boolean cast(PlayerEntity player, StdThrownMagic magic , World world,float staffRate){
the_origin_of_magic.LOGGER.debug("Casting magic: " +magic.getDisplayName().getString() + "("+magic.getUuid()+")");
if(world.getEntityById(magic.getId()) != null || magic.isRemoved()){
the_origin_of_magic.LOGGER.debug("Magic("+magic.getName()+"[" + magic.getUuid() +"]) already exist or removed");
return false;
}
float neededMagic = magic.getMagicRate() * magicRate * staffRate;
float neededMagic = magic.getMagicRate() * Math.max(magicRate,1) * Math.max(staffRate,1);
the_origin_of_magic.LOGGER.debug("Needed magic: " + neededMagic+ " current magic: " + magicLevel);
if(player.isCreative()){
return world.spawnEntity(magic);
}
Expand All @@ -57,7 +61,8 @@ public boolean cast(PlayerEntity player, StdThrownMagic magic , World world,floa
}

public boolean cast(PlayerEntity player, StdDriestEffectMagic magic , World world,float staffRate){
float neededMagic = magic.getMagicRate() * magicRate;
float neededMagic = magic.getMagicRate() * Math.max(magicRate,1) * Math.max(staffRate,1);
the_origin_of_magic.LOGGER.debug("Needed magic: " + neededMagic+ " current magic: " + magicLevel);
if(player.isCreative()){
return magic.onCast(player,world);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.ictye.the_origin_of_magic.foundation.Items.Magic.StdMagicItem;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.util.collection.DefaultedList;

/**
* 存放魔法的物品欄,用於法術施放什麽的
Expand All @@ -16,6 +17,15 @@ public MagicInventory(int size) {
super(size);
}

public MagicInventory(DefaultedList<ItemStack> magicStack) {
super(magicStack.size());
for(ItemStack i : magicStack){
if (i.getItem() instanceof StdMagicItem){
this.setStack(magicStack.indexOf(i), i);
}
}
}

public MagicInventory setStackFromInventory(SimpleInventory inventory) {
for (int i = 0; i < inventory.size(); i++) {
this.setStack(i, inventory.getStack(i));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@
"itemGroup.the_origin_of_magic.normal": "The Origin Of The Magic",
"text.the_origin_of_magic.staff_casting": "Casting Num",
"item.the_origin_of_magic.test_staff.tooltip": "Only For Codding Test",
"text.the_origin_of_magic.staff_size": "Staff Size: "

"text.the_origin_of_magic.staff_size": "Staff Size: ",
"text.the_origin_of_magic.random_cast": "Rundom Cast"
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.

0 comments on commit fe65095

Please sign in to comment.