Skip to content

Commit

Permalink
fix: 修复触发魔法的bug。。。。。。
Browse files Browse the repository at this point in the history
  • Loading branch information
northgreen committed Apr 27, 2024
1 parent fe65095 commit c875db8
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.19.2 2024-04-27T17:58:45.6994048 Language
// 1.19.2 2024-04-27T21:43:20.5506987 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-27T17:58:45.6969072 Block Loot Tables
// 1.19.2 2024-04-27T21:43:20.5476236 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-27T17:58:45.694408 Models
// 1.19.2 2024-04-27T21:43:20.5441261 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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.world.World;

Expand All @@ -32,7 +33,7 @@ public void tick() {
@Override
protected void onEntityHit(EntityHitResult entityHitResult) {
if(prdRandom!=null){
prdRandom.setSP((float) (prdRandom.getP() + 0.5));
prdRandom.setSP(prdRandom.getP() + 0.5F);
if(prdRandom.getBool()){
entityHitResult.getEntity().damage(DamageSource.thrownProjectile(this, this.getOwner()), 7);
}else {
Expand All @@ -45,6 +46,12 @@ protected void onEntityHit(EntityHitResult entityHitResult) {
super.onEntityHit(entityHitResult);
}

@Override
protected void onBlockHit(BlockHitResult blockHitResult) {
super.onBlockHit(blockHitResult);
remove(RemovalReason.DISCARDED);
}

@Override
public ItemStack getStack() {
return new ItemStack(Items.AIR);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,15 +136,42 @@ public void setAdditionTrigger(List<StdCastInterface> magics){
this.additionMagicList = magics;
}

/**
* 設置附加魔法
* @param magics 魔法
*/
public void setAdditionTrigger(StdThrownMagic ... magics){
this.additionMagicList = List.of(magics);
}

/**
* 魔法构造器
* @param entityType 魔法類型
* @param world 世界
*/
public StdThrownMagic(EntityType<? extends StdThrownMagic> entityType, World world) {
super(entityType, world);
}

/**
* 魔法初始化
* @param type 魔法類型
* @param x x座標
* @param y y座標
* @param z z座標
* @param world 世界
*/
public StdThrownMagic(EntityType<? extends StdThrownMagic> type, double x, double y, double z, World world) {
this(type, world);
this.setPosition(x, y, z);
}

/**
* 魔法初始化
* @param type 魔法類型
* @param owner 擁有者
* @param world 世界
*/
public StdThrownMagic(EntityType<? extends StdThrownMagic> type, LivingEntity owner, World world) {
this(type, owner.getX(), owner.getEyeY() - (double)0.1f, owner.getZ(), world);
this.setOwner(owner);
Expand All @@ -160,7 +187,7 @@ protected void onCollision(HitResult hitResult) {
// 計算反彈
if(isReflect && reflectCount > 0){
if (hitResult instanceof BlockHitResult blockHitResult) {
Vec3d v = this.getVelocity();
Vec3d v = this.getVelocity().multiply(0.5);
Direction face = blockHitResult.getSide();
if(face == Direction.UP || face == Direction.DOWN){
setVelocity(new Vec3d(v.x,-v.y,v.z));
Expand All @@ -179,19 +206,19 @@ protected void onCollision(HitResult hitResult) {
HitResult.Type type = hitResult.getType();
if (type == HitResult.Type.ENTITY) {
if (hitResult instanceof EntityHitResult && !(limiter.canEffect((EntityHitResult) hitResult, hitResult, null))) {
this.remove(RemovalReason.CHANGED_DIMENSION);
this.remove(RemovalReason.DISCARDED);
return;
}
} else if (type == HitResult.Type.BLOCK) {
if (hitResult instanceof BlockHitResult && !(limiter.canEffect(null, hitResult, (BlockHitResult) hitResult))) {
this.remove(RemovalReason.CHANGED_DIMENSION);
this.remove(RemovalReason.DISCARDED);
return;
}
}
}

if(!world.isClient){
if(hitCast){
if(hitCast || ageCast){
castAddiMagic(hitResult);
}
}
Expand All @@ -208,7 +235,7 @@ protected void castAddiMagic(HitResult hitResult){
if(owner instanceof PlayerEntityMixinInterfaces player){
if(additionMagic instanceof StdThrownMagic magic){
magic.setPosition(this.getPos());
Vec3d v = this.getVelocity();
Vec3d v = this.getVelocity().multiply(0.5);
if(hitResult instanceof BlockHitResult blockHitResult){
// 撞到方塊后反射
Direction face = blockHitResult.getSide();
Expand Down Expand Up @@ -310,24 +337,17 @@ public void tick() {
this.setPosition(d, e, f);

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 (age>=getAge() * Math.min(this.ageRate,1)){
if(ageCast){
if(!world.isClient){
castAddiMagic();
}
}
this.remove(RemovalReason.DISCARDED);
}
for(StdEffectMagic effectMagic : effectMagicList){
effectMagic.tick(this.world);
}
super.remove(reason);
}

protected float getGravity() {
Expand Down

0 comments on commit c875db8

Please sign in to comment.