Skip to content

Commit

Permalink
perf: 优化代码结构,對氣泡的位置進行更改。
Browse files Browse the repository at this point in the history
  • Loading branch information
northgreen committed Apr 20, 2024
1 parent 2597bb5 commit 77181da
Show file tree
Hide file tree
Showing 14 changed files with 84 additions and 32 deletions.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
// 1.19.2 2024-04-19T22:45:49.3401001 Language
// 1.19.2 2024-04-20T13:20:04.2533668 Language
cf9144aa31d03773d984551199f36d4c66351a1f 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-19T22:45:49.3370978 Block Loot Tables
// 1.19.2 2024-04-20T13:20:04.2507738 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,3 +1,5 @@
// 1.19.2 2024-04-19T22:45:49.3434062 Models
// 1.19.2 2024-04-20T13:20:04.2558702 Models
02d3ff4716d16f7c5a4dd4432d1b98f744a13f02 assets\the_origin_of_magic\models\item\blood_essence.json
b1555a32206034cd8f1b13891371182e88d9d40a assets\the_origin_of_magic\models\item\test_magic.json
03b1f5cc891077d36d38a8d98d2ffe49396f8229 assets\the_origin_of_magic\models\item\water_magic_element.json
a50a32a25dfc8a066cacf0c15ac0420396c0c5fc assets\the_origin_of_magic\models\item\hoglin_entity_limiter.json
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/hoglin_entity_limiter"
}
}
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/test_magic"
}
}
Original file line number Diff line number Diff line change
@@ -1,20 +1,22 @@
package com.ictye.the_origin_of_magic.Contents;

import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.ExplosionThrownMagic;
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdThrownMagic;
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.TestThrownMagic;
import com.ictye.the_origin_of_magic.the_origin_of_magic;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder;
import net.minecraft.client.render.entity.FlyingItemEntityRenderer;
import net.minecraft.entity.*;
import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import com.ictye.the_origin_of_magic.the_origin_of_magic;

public class AllEntity {

public static final EntityType<StdThrownMagic> TEST_MAGIC_ENTITY_TYPE= FabricEntityTypeBuilder.<StdThrownMagic>create(SpawnGroup.MISC, TestThrownMagic::new)
public static final EntityType<StdThrownMagic> TEST_MAGIC_ENTITY_TYPE= FabricEntityTypeBuilder.<StdThrownMagic>create(SpawnGroup.MISC, ExplosionThrownMagic::new)
.dimensions(EntityDimensions.fixed(0.25F, 0.25F))
.trackRangeBlocks(4).trackedUpdateRate(10)
.build();
Expand Down
30 changes: 14 additions & 16 deletions src/main/java/com/ictye/the_origin_of_magic/Contents/AllItem.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package com.ictye.the_origin_of_magic.Contents;

import com.ictye.the_origin_of_magic.foundation.Items.Magic.LimiterItem.UndeadEntityLimiterItem;
import com.ictye.the_origin_of_magic.foundation.Items.Magic.StdMagicItem;
import com.ictye.the_origin_of_magic.foundation.Items.Magic.TestMagicEntityItem;
import com.ictye.the_origin_of_magic.foundation.Items.Staff.DeadwoodStaff;
import com.ictye.the_origin_of_magic.foundation.Items.Staff.TestStaff;
Expand Down Expand Up @@ -49,15 +48,15 @@ public class AllItem {
/**
* 所有魔法
*/
public static final Item TEST_MAGIC = createMagic("Test Magic","test_magic",new TestMagicEntityItem(new FabricItemSettings()
public static final Item TEST_MAGIC = new TestMagicEntityItem(new FabricItemSettings()
.maxCount(1)
.group(TheOriginOfMagicItemGroup), AllEntity.TEST_MAGIC_ENTITY_TYPE)); // 測試魔法
.group(TheOriginOfMagicItemGroup), AllEntity.TEST_MAGIC_ENTITY_TYPE); // 測試魔法

public static final Item HOGLIN_ENTITY_LIMITER = createMagic("Hoglin Entity Limiter","hoglin_entity_limiter",new UndeadEntityLimiterItem(new FabricItemSettings()
public static final Item HOGLIN_ENTITY_LIMITER = new UndeadEntityLimiterItem(new FabricItemSettings()
.maxCount(1)
.group(TheOriginOfMagicItemGroup)
.maxDamage(100)
.rarity(Rarity.COMMON),null));
.rarity(Rarity.COMMON),null);

/**
* 所有材料
Expand All @@ -75,38 +74,37 @@ public class AllItem {
/**
* 物品ID列表
*/
public static Map<String, Item> ItemMap = Map.of(
public static final Map<String, Item> ItemMap = Map.of(
"deadwood_staff",DEADWOOD_STAFF,
"test_staff",TEST_STAFF,
"test_magic",TEST_MAGIC,
"hoglin_entity_limiter", HOGLIN_ENTITY_LIMITER,
"blood_essence",BLOOD_ESSENCE,
"water_magic_element",WATER_MAGIC_ELEMENT
);

/**
* 物品英文翻譯列表
*/
public static Map<String, Item> ItemTransMap = Map.of(
public static final Map<String, Item> ItemTransMap = Map.of(
"Deadwood Staff",DEADWOOD_STAFF,
"Test Staff",TEST_STAFF,
"Test Magic",TEST_MAGIC,
"Hoglin Entity Limiter", HOGLIN_ENTITY_LIMITER,
"Blood Essence", BLOOD_ESSENCE,
"Water Magic Element",WATER_MAGIC_ELEMENT
);

/**
* 物品模型列表
*/
public static Map< Item,Model> ItemModelMap = Map.of(
public static final Map< Item,Model> ItemModelMap = Map.of(
BLOOD_ESSENCE,Models.GENERATED,
WATER_MAGIC_ELEMENT,Models.GENERATED
WATER_MAGIC_ELEMENT,Models.GENERATED,
TEST_MAGIC,Models.GENERATED,
HOGLIN_ENTITY_LIMITER,Models.GENERATED
);

private static Item createMagic(String name, String id, StdMagicItem magicItem){
ItemMap.put(id,magicItem);
ItemModelMap.put(magicItem,Models.GENERATED);
ItemTransMap.put(name,magicItem);
return magicItem;
}

private static void registerItem(String name, Item item){
Registry.register(Registry.ITEM, new Identifier(the_origin_of_magic.Mod_Id, name), item);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,11 @@
import net.minecraft.particle.ParticleTypes;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import net.minecraft.world.explosion.Explosion;

public class TestThrownMagic extends StdThrownMagic {
public class ExplosionThrownMagic extends StdThrownMagic {

private float exolisionRate;

Expand All @@ -20,17 +21,17 @@ protected float getGravity() {
return 0.0F;
}

public TestThrownMagic(EntityType<? extends ThrownEntity> entityType, World world) {
public ExplosionThrownMagic(EntityType<? extends ThrownEntity> entityType, World world) {
super(entityType, world);
this.exolisionRate = 1.0F;
}

public TestThrownMagic(EntityType<? extends ThrownEntity> type, LivingEntity owner, World world) {
public ExplosionThrownMagic(EntityType<? extends ThrownEntity> type, LivingEntity owner, World world) {
super(type, owner, world);
this.exolisionRate = 1.0F;
}

public TestThrownMagic(EntityType<? extends ThrownEntity> type, LivingEntity owner, World world, float exolisionRate) {
public ExplosionThrownMagic(EntityType<? extends ThrownEntity> type, LivingEntity owner, World world, float exolisionRate) {
this(type, owner, world);
this.exolisionRate = exolisionRate;
}
Expand Down Expand Up @@ -62,6 +63,13 @@ public ItemStack getStack() {
@Override
public void tick() {
super.tick();
this.world.addParticle(ParticleTypes.DRAGON_BREATH, this.getX(), this.getY(), this.getZ(), 0.0D, 0.0D, 0.0D);
this.world.addParticle(ParticleTypes.FIREWORK, this.getX(), this.getY(), this.getZ(), 0.0D, 0.0D, 0.0D);
Vec3d v = this.getVelocity();
for(int i = 8;i > 0;i--){
double x = random.nextDouble() * 2 - 1;
double y = random.nextDouble() * 2 - 1;
double z = random.nextDouble() * 2 - 1;
this.world.addParticle(ParticleTypes.FLAME, this.getX(), this.getY(), this.getZ(), x/2, y/2, z/2);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.ictye.the_origin_of_magic.foundation.Entitys.Magics.Limiters;

import net.minecraft.entity.mob.HoglinEntity;
import net.minecraft.entity.mob.HostileEntity;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
Expand All @@ -11,7 +11,7 @@ public class HostileEntityLimiter extends StdMagicLimiter {
public boolean canEffect(@Nullable EntityHitResult entityHitResult, @Nullable HitResult hitResult, @Nullable BlockHitResult blockHitResult) {
// 判斷是否為亡靈生物
if (entityHitResult != null) {
return entityHitResult.getEntity() instanceof HoglinEntity;
return entityHitResult.getEntity() instanceof HostileEntity;
}
return false;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
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.ExplosionThrownMagic;
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.StdThrownMagic;
import com.ictye.the_origin_of_magic.foundation.Entitys.Magics.TestThrownMagic;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.world.World;
Expand All @@ -16,6 +16,6 @@ public TestMagicEntityItem(Settings settings, EntityType<StdThrownMagic> entityT

@Override
public StdThrownMagic getMagic(PlayerEntity user, World world, float exolisionRate, int hartRate) {
return new TestThrownMagic(magicEntityType,user,world,exolisionRate);
return new ExplosionThrownMagic(magicEntityType,user,world,exolisionRate);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import org.spongepowered.asm.mixin.injection.Slice;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(InGameHud.class)
Expand All @@ -28,4 +30,16 @@ public abstract class PlayerHudMixin extends DrawableHelper{
private void renderStatusBars(MatrixStack matrices, CallbackInfo ci){
MagicLevelHud.renderThirstHud(matrices, client, this.getCameraPlayer(), ticks);
}

// 提高氣泡的位置
@ModifyArg(method = "renderStatusBars",
at = @At(value = "INVOKE",target = "Lnet/minecraft/client/gui/hud/InGameHud;drawTexture(Lnet/minecraft/client/util/math/MatrixStack;IIIIII)V"),
index = 2,
slice = @Slice(
from = @At(value = "INVOKE",target = "Lnet/minecraft/entity/player/PlayerEntity;getMaxAir()I"),
to = @At(value = "INVOKE",target = "Lnet/minecraft/util/profiler/Profiler;pop()V")
))
private int modifyAirBarPosition(int par2) {
return par2 - 12;
}
}
16 changes: 16 additions & 0 deletions src/main/java/com/ictye/the_origin_of_magic/utils/Vec3d_Util.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,21 @@ public static Vec3d getLookVec(LivingEntity player, double length) {

return vec.normalize().multiply(length);
}

public static Vec3d RodriguesRotation(Vec3d vec, double angle, Vec3d axis){

double x = vec.x;
double y = vec.y;
double z = vec.z;

double sinAngle = Math.sin(angle);
double cosAngle = Math.cos(angle);

double rx = (axis.x * (1 - cosAngle)) + (axis.x * axis.x * (1 - cosAngle)) + (axis.z * sinAngle);
double ry = (axis.y * (1 - cosAngle)) + (axis.y * axis.y * (1 - cosAngle)) + (axis.z * sinAngle);
double rz = (axis.z * (1 - cosAngle)) + (axis.x * axis.y * sinAngle) + (axis.z * axis.z * (1 - cosAngle));

return new Vec3d(x * rx + y * ry + z * rz, x * ry + y * rz + z * rx, x * rz + y * rx + z * ry);
}
}

Binary file modified src/main/resources/assets/the_origin_of_magic/logo.png
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.

0 comments on commit 77181da

Please sign in to comment.