diff --git a/bbmodel/missile_bullet/0.java b/bbmodel/missile_bullet/0.java new file mode 100644 index 0000000..07e3dcd --- /dev/null +++ b/bbmodel/missile_bullet/0.java @@ -0,0 +1,33 @@ +// Made with Blockbench 4.8.3 +// Exported for Minecraft version 1.17 or later with Mojang mappings +// Paste this class into your mod and generate all required imports + + +public class 0 extends EntityModel { + // This layer location should be baked with EntityRendererProvider.Context in the entity renderer and passed into this model's constructor + public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(new ResourceLocation("modid", "0"), "main"); + private final ModelPart bb_main; + + public 0(ModelPart root) { + this.bb_main = root.getChild("bb_main"); + } + + public static LayerDefinition createBodyLayer() { + MeshDefinition meshdefinition = new MeshDefinition(); + PartDefinition partdefinition = meshdefinition.getRoot(); + + PartDefinition bb_main = partdefinition.addOrReplaceChild("bb_main", CubeListBuilder.create().texOffs(0, 0).addBox(-1.0F, -1.0F, -1.0F, 2.0F, 2.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 24.0F, 0.0F)); + + return LayerDefinition.create(meshdefinition, 16, 16); + } + + @Override + public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { + + } + + @Override + public void renderToBuffer(PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) { + bb_main.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); + } +} \ No newline at end of file diff --git a/bbmodel/missile_bullet/missile_bullet.bbmodel b/bbmodel/missile_bullet/missile_bullet.bbmodel new file mode 100644 index 0000000..984a94c --- /dev/null +++ b/bbmodel/missile_bullet/missile_bullet.bbmodel @@ -0,0 +1 @@ +{"meta":{"format_version":"4.5","model_format":"modded_entity","box_uv":true},"name":"MissileBullet","model_identifier":"0","modded_entity_version":"1.17","modded_entity_flip_y":true,"visible_box":[1,1,0],"variable_placeholders":"","variable_placeholder_buttons":[],"unhandled_root_fields":{},"resolution":{"width":16,"height":16},"elements":[{"name":"cube","box_uv":true,"rescale":false,"locked":false,"render_order":"default","allow_mirror_modeling":true,"from":[-1,-1,-1],"to":[1,1,1],"autouv":1,"color":4,"origin":[0,0,0],"faces":{"north":{"uv":[2,2,4,4],"texture":0},"east":{"uv":[0,2,2,4],"texture":0},"south":{"uv":[6,2,8,4],"texture":0},"west":{"uv":[4,2,6,4],"texture":0},"up":{"uv":[4,2,2,0],"texture":0},"down":{"uv":[6,0,4,2],"texture":0}},"type":"cube","uuid":"0ad43cce-9897-9d64-e4ea-5fda6c45ff7d"}],"outliner":["0ad43cce-9897-9d64-e4ea-5fda6c45ff7d"],"textures":[{"path":"C:\\Users\\qiuzhenxuan\\Desktop\\Project\\MinecraftMod\\mindustry\\bbmodel\\missile_bullet\\missile_bullet.png","name":"missile_bullet.png","folder":"block","namespace":"","id":"0","particle":false,"render_mode":"default","render_sides":"auto","frame_time":1,"frame_order_type":"loop","frame_order":"","frame_interpolate":false,"visible":true,"mode":"bitmap","saved":true,"uuid":"44a9d5b5-1787-d722-088f-09dc550d0c66","relative_path":"../missile_bullet.png","source":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAB9JREFUOE9jZKAQMFKon2HUAIbRMGAYDQNQPhr4vAAAJpgAEX/anFwAAAAASUVORK5CYII="}]} \ No newline at end of file diff --git a/bbmodel/missile_bullet/missile_bullet.png b/bbmodel/missile_bullet/missile_bullet.png new file mode 100644 index 0000000..2d890a4 Binary files /dev/null and b/bbmodel/missile_bullet/missile_bullet.png differ diff --git a/src/main/java/com/hechu/mindustry/Mindustry.java b/src/main/java/com/hechu/mindustry/Mindustry.java index d1cd0c8..c5fcca3 100644 --- a/src/main/java/com/hechu/mindustry/Mindustry.java +++ b/src/main/java/com/hechu/mindustry/Mindustry.java @@ -1,9 +1,12 @@ package com.hechu.mindustry; +import com.hechu.mindustry.client.model.MissileBulletModel; import com.hechu.mindustry.client.renderer.blockentity.MechanicalDrillBlockEntityRenderer; import com.hechu.mindustry.client.renderer.blockentity.PneumaticDrillBlockEntityRenderer; import com.hechu.mindustry.client.renderer.blockentity.PowerNodeRenderer; import com.hechu.mindustry.client.renderer.blockentity.TurretRenderer; +import com.hechu.mindustry.client.renderer.entity.BasicBulletRender; +import com.hechu.mindustry.client.renderer.entity.MissileBulletRender; import com.hechu.mindustry.config.CommonConfig; import com.hechu.mindustry.config.ConfigHandler; import com.hechu.mindustry.kiwi.BlockEntityModule; @@ -47,15 +50,23 @@ public Mindustry() { @Mod.EventBusSubscriber(modid = MindustryConstants.MOD_ID, bus = Mod.EventBusSubscriber.Bus.MOD, value = Dist.CLIENT) public static class ClientModEvents { + @SubscribeEvent + public static void onRegisterLayers(EntityRenderersEvent.RegisterLayerDefinitions event) { + event.registerLayerDefinition(MissileBulletModel.LAYER_LOCATION, MissileBulletModel::createBodyLayer); + } + @SubscribeEvent public static void onRegisterRenderers(EntityRenderersEvent.RegisterRenderers event) { event.registerBlockEntityRenderer(BlockEntityModule.MECHANICAL_DRILL_BLOCK_ENTITY.get(), context -> new MechanicalDrillBlockEntityRenderer()); event.registerBlockEntityRenderer(BlockEntityModule.PNEUMATIC_DRILL_BLOCK_ENTITY.get(), context -> new PneumaticDrillBlockEntityRenderer()); - event.registerBlockEntityRenderer(BlockEntityModule.TURRET_BLOCK_ENTITY.get(), TurretRenderer::new); + event.registerBlockEntityRenderer(BlockEntityModule.SWARMER_TURRET_BLOCK_ENTITY.get(), TurretRenderer::new); + event.registerBlockEntityRenderer(BlockEntityModule.SPECTRE_TURRET_BLOCK_ENTITY.get(), TurretRenderer::new); event.registerBlockEntityRenderer(BlockEntityModule.POWER_NODE_BLOCK_ENTITY.get(), pContext -> new PowerNodeRenderer()); event.registerEntityRenderer(EntityModule.DUO.get(), DuoRenderer::new); + event.registerEntityRenderer(EntityModule.MISSILE_BULLET.get(), MissileBulletRender::new); + event.registerEntityRenderer(EntityModule.BASIC_BULLET.get(), BasicBulletRender::new); } @SubscribeEvent diff --git a/src/main/java/com/hechu/mindustry/client/model/MissileBulletModel.java b/src/main/java/com/hechu/mindustry/client/model/MissileBulletModel.java new file mode 100644 index 0000000..4162399 --- /dev/null +++ b/src/main/java/com/hechu/mindustry/client/model/MissileBulletModel.java @@ -0,0 +1,46 @@ +package com.hechu.mindustry.client.model;// Made with Blockbench 4.8.3 +// Exported for Minecraft version 1.17 or later with Mojang mappings +// Paste this class into your mod and generate all required imports + + +import com.hechu.mindustry.MindustryConstants; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; +import net.minecraft.client.model.EntityModel; +import net.minecraft.client.model.geom.ModelLayerLocation; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.model.geom.PartPose; +import net.minecraft.client.model.geom.builders.*; +import net.minecraft.client.renderer.RenderType; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.entity.Entity; + +public class MissileBulletModel extends EntityModel { + // This layer location should be baked with EntityRendererProvider.Context in the entity renderer and passed into this model's constructor + public static final ModelLayerLocation LAYER_LOCATION = new ModelLayerLocation(new ResourceLocation(MindustryConstants.MOD_ID, "missile_bullet"), "main"); + private final ModelPart body; + + public MissileBulletModel(ModelPart root) { + super(RenderType::entitySolid); + this.body = root; + } + + public static LayerDefinition createBodyLayer() { + MeshDefinition meshdefinition = new MeshDefinition(); + PartDefinition partdefinition = meshdefinition.getRoot(); + + PartDefinition bb_main = partdefinition.addOrReplaceChild("main", CubeListBuilder.create().texOffs(0, 0).addBox(-1.0F, -1.0F, -1.0F, 2.0F, 2.0F, 2.0F, new CubeDeformation(0.0F)), PartPose.offset(0.0F, 24.0F, 0.0F)); + + return LayerDefinition.create(meshdefinition, 16, 16); + } + + @Override + public void setupAnim(T entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { + + } + + @Override + public void renderToBuffer(PoseStack poseStack, VertexConsumer vertexConsumer, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) { + body.render(poseStack, vertexConsumer, packedLight, packedOverlay, red, green, blue, alpha); + } +} \ No newline at end of file diff --git a/src/main/java/com/hechu/mindustry/client/renderer/blockentity/TurretRenderer.java b/src/main/java/com/hechu/mindustry/client/renderer/blockentity/TurretRenderer.java index 12174a5..0bd590e 100644 --- a/src/main/java/com/hechu/mindustry/client/renderer/blockentity/TurretRenderer.java +++ b/src/main/java/com/hechu/mindustry/client/renderer/blockentity/TurretRenderer.java @@ -1,6 +1,7 @@ package com.hechu.mindustry.client.renderer.blockentity; -import com.hechu.mindustry.world.level.block.entity.turrets.TurretBlockEntity; +import com.hechu.mindustry.world.level.block.entity.turrets.SwarmerTurretBlockEntity; +import com.hechu.mindustry.world.level.block.entity.turrets.TurretBlockEntityBase; import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.math.Axis; import net.minecraft.client.Minecraft; @@ -21,7 +22,7 @@ import org.jetbrains.annotations.NotNull; @OnlyIn(Dist.CLIENT) -public class TurretRenderer implements BlockEntityRenderer { +public class TurretRenderer implements BlockEntityRenderer { public static final Material TURRET_LOCATION = new Material(TextureAtlas.LOCATION_BLOCKS, new ResourceLocation("entity/turret")); public TurretRenderer(BlockEntityRendererProvider.Context context) { @@ -29,7 +30,7 @@ public TurretRenderer(BlockEntityRendererProvider.Context context) { } @Override - public void render(@NotNull TurretBlockEntity blockEntity, float partialTick, @NotNull PoseStack poseStack, @NotNull MultiBufferSource buffer, int packedLight, int packedOverlay) { + public void render(@NotNull TurretBlockEntityBase blockEntity, float partialTick, @NotNull PoseStack poseStack, @NotNull MultiBufferSource buffer, int packedLight, int packedOverlay) { BlockRenderDispatcher blockRenderer = Minecraft.getInstance().getBlockRenderer(); // poseStack.pushPose(); @@ -54,10 +55,10 @@ public void render(@NotNull TurretBlockEntity blockEntity, float partialTick, @N float f2 = blockEntity.oRot + f1 * partialTick; float f3; - if (blockEntity.targetPosX != 0 || blockEntity.targetPosY != 0 || blockEntity.targetPosZ != 0) { - f3 = (float) Mth.atan2(blockEntity.targetPosY - blockEntity.getBlockPos().getCenter().y, - Mth.sqrt((float) (Mth.square(blockEntity.targetPosX - blockEntity.getBlockPos().getCenter().x) - + Mth.square(blockEntity.targetPosZ - blockEntity.getBlockPos().getCenter().z)))); + if (blockEntity.target != null) { + f3 = (float) Mth.atan2(blockEntity.targetPos.y - blockEntity.getBlockPos().getCenter().y, + Mth.sqrt((float) (Mth.square(blockEntity.targetPos.x - blockEntity.getBlockPos().getCenter().x) + + Mth.square(blockEntity.targetPos.z - blockEntity.getBlockPos().getCenter().z)))); // poseStack.mulPose(Axis.XN.rotationDegrees(90.0f)); } else { f3 = 0f; diff --git a/src/main/java/com/hechu/mindustry/client/renderer/entity/BasicBulletRender.java b/src/main/java/com/hechu/mindustry/client/renderer/entity/BasicBulletRender.java new file mode 100644 index 0000000..e5047f5 --- /dev/null +++ b/src/main/java/com/hechu/mindustry/client/renderer/entity/BasicBulletRender.java @@ -0,0 +1,31 @@ +package com.hechu.mindustry.client.renderer.entity; + +import com.hechu.mindustry.MindustryConstants; +import com.hechu.mindustry.client.model.MissileBulletModel; +import com.hechu.mindustry.world.entity.projectile.BasicBullet; +import com.hechu.mindustry.world.entity.projectile.MissileBullet; +import net.minecraft.client.model.EntityModel; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.resources.ResourceLocation; + +public class BasicBulletRender extends EntityRenderer { + private EntityModel model; + + public static final ResourceLocation TEXTURE = new ResourceLocation(MindustryConstants.MOD_ID, "textures/entity/bullets/missile_bullet.png"); + + public BasicBulletRender(EntityRendererProvider.Context pContext) { + super(pContext); + model = new MissileBulletModel(pContext.bakeLayer(MissileBulletModel.LAYER_LOCATION)); + } + + /** + * Returns the location of an entity's texture. + * + * @param pEntity + */ + @Override + public ResourceLocation getTextureLocation(BasicBullet pEntity) { + return TEXTURE; + } +} diff --git a/src/main/java/com/hechu/mindustry/client/renderer/entity/MissileBulletRender.java b/src/main/java/com/hechu/mindustry/client/renderer/entity/MissileBulletRender.java new file mode 100644 index 0000000..7df74bb --- /dev/null +++ b/src/main/java/com/hechu/mindustry/client/renderer/entity/MissileBulletRender.java @@ -0,0 +1,30 @@ +package com.hechu.mindustry.client.renderer.entity; + +import com.hechu.mindustry.MindustryConstants; +import com.hechu.mindustry.client.model.MissileBulletModel; +import com.hechu.mindustry.world.entity.projectile.MissileBullet; +import net.minecraft.client.model.EntityModel; +import net.minecraft.client.renderer.entity.EntityRenderer; +import net.minecraft.client.renderer.entity.EntityRendererProvider; +import net.minecraft.resources.ResourceLocation; + +public class MissileBulletRender extends EntityRenderer { + private EntityModel model; + + public static final ResourceLocation TEXTURE = new ResourceLocation(MindustryConstants.MOD_ID, "textures/entity/bullets/missile_bullet.png"); + + public MissileBulletRender(EntityRendererProvider.Context pContext) { + super(pContext); + model = new MissileBulletModel(pContext.bakeLayer(MissileBulletModel.LAYER_LOCATION)); + } + + /** + * Returns the location of an entity's texture. + * + * @param pEntity + */ + @Override + public ResourceLocation getTextureLocation(MissileBullet pEntity) { + return TEXTURE; + } +} diff --git a/src/main/java/com/hechu/mindustry/kiwi/BlockEntityModule.java b/src/main/java/com/hechu/mindustry/kiwi/BlockEntityModule.java index 4f2d68e..b573533 100644 --- a/src/main/java/com/hechu/mindustry/kiwi/BlockEntityModule.java +++ b/src/main/java/com/hechu/mindustry/kiwi/BlockEntityModule.java @@ -6,7 +6,8 @@ import com.hechu.mindustry.world.level.block.entity.PneumaticDrillBlockEntity; import com.hechu.mindustry.world.level.block.entity.multiblock.KilnBlockEntity; import com.hechu.mindustry.world.level.block.entity.multiblock.TestTurretMultiblockEntity; -import com.hechu.mindustry.world.level.block.entity.turrets.TurretBlockEntity; +import com.hechu.mindustry.world.level.block.entity.turrets.SpectreTurretBlockEntity; +import com.hechu.mindustry.world.level.block.entity.turrets.SwarmerTurretBlockEntity; import net.minecraft.world.level.block.entity.BlockEntityType; import snownee.kiwi.AbstractModule; import snownee.kiwi.KiwiGO; @@ -17,8 +18,9 @@ public class BlockEntityModule extends AbstractModule { public static final KiwiGO> MECHANICAL_DRILL_BLOCK_ENTITY = blockEntity(MechanicalDrillBlockEntity::new, null, MutilBlockModule.MECHANICAL_DRILL); public static final KiwiGO> PNEUMATIC_DRILL_BLOCK_ENTITY = blockEntity(PneumaticDrillBlockEntity::new, null, MutilBlockModule.PNEUMATIC_DRILL); public static final KiwiGO> HEALTH_TEST_BLOCK_ENTITY = blockEntity(HealthTestBlockEntity::new, null, MutilBlockModule.HEALTH_TEST); - public static final KiwiGO> TURRET_BLOCK_ENTITY = blockEntity(TurretBlockEntity::new, null, MutilBlockModule.TURRET); public static final KiwiGO> TEST_TURRET_MULTIBLOCK_ENTITY_BLOCK_ENTITY = blockEntity(TestTurretMultiblockEntity::new, null, MutilBlockModule.TEST_TURRET_MULTIBLOCK_ENTITY_BLOCK); public static final KiwiGO> KILN_BLOCK_ENTITY = blockEntity(KilnBlockEntity::new, null, MutilBlockModule.KILN_BLOCK); public static final KiwiGO> POWER_NODE_BLOCK_ENTITY = blockEntity(PowerNodeBlockEntity::new, null, BlockModule.POWER_NODE); + public static final KiwiGO> SWARMER_TURRET_BLOCK_ENTITY = blockEntity(SwarmerTurretBlockEntity::new, null, MutilBlockModule.SWARMER_TURRET); + public static final KiwiGO> SPECTRE_TURRET_BLOCK_ENTITY = blockEntity(SpectreTurretBlockEntity::new, null, MutilBlockModule.SPECTRE_TURRET); } diff --git a/src/main/java/com/hechu/mindustry/kiwi/BlockModule.java b/src/main/java/com/hechu/mindustry/kiwi/BlockModule.java index 0af9108..892510a 100644 --- a/src/main/java/com/hechu/mindustry/kiwi/BlockModule.java +++ b/src/main/java/com/hechu/mindustry/kiwi/BlockModule.java @@ -3,6 +3,8 @@ import com.hechu.mindustry.MindustryConstants; import com.hechu.mindustry.world.level.block.Equipment.PowerNodeBlock; import com.hechu.mindustry.world.level.block.ore.*; +import com.hechu.mindustry.world.level.block.turrets.SpectreTurretBlock; +import com.hechu.mindustry.world.level.block.turrets.SwarmerTurretBlock; import net.minecraft.world.level.block.Block; import snownee.kiwi.AbstractModule; import snownee.kiwi.KiwiGO; @@ -32,8 +34,10 @@ public class BlockModule extends AbstractModule { public static final KiwiGO THORIUM_ORE_BLOCK = go(ThoriumOreBlock::new); @KiwiModule.Name("titanium_ore") public static final KiwiGO TITANIUM_ORE_BLOCK = go(TitaniumOreBlock::new); + private static Set blocks = null; private static Set registerName = null; + public static Set getBlocks() { if (blocks == null) { blocks = Arrays.stream(BlockModule.class.getFields()) @@ -67,7 +71,7 @@ public static Set getRegisterName() { }) .map(field -> { KiwiModule.Name annotated = field.getAnnotation(KiwiModule.Name.class); - if (annotated == null){ + if (annotated == null) { return field.getName(); } return annotated.value(); diff --git a/src/main/java/com/hechu/mindustry/kiwi/EntityModule.java b/src/main/java/com/hechu/mindustry/kiwi/EntityModule.java index e316602..f649d40 100644 --- a/src/main/java/com/hechu/mindustry/kiwi/EntityModule.java +++ b/src/main/java/com/hechu/mindustry/kiwi/EntityModule.java @@ -1,6 +1,8 @@ package com.hechu.mindustry.kiwi; import com.hechu.mindustry.world.entity.Turret; +import com.hechu.mindustry.world.entity.projectile.BasicBullet; +import com.hechu.mindustry.world.entity.projectile.MissileBullet; import com.hechu.mindustry.world.entity.turrets.Duo; import net.minecraft.world.entity.EntityType; import net.minecraft.world.entity.MobCategory; @@ -14,8 +16,18 @@ public class EntityModule extends AbstractModule { EntityType.Builder.of(Duo::new, MobCategory.MISC) .sized(0.5F, 0.8F) .build("duo")); + + public static final KiwiGO> MISSILE_BULLET = go(() -> + EntityType.Builder.of(MissileBullet::new, MobCategory.MISC) + .sized(0.5F, 0.5F) + .build("missile_bullet")); // public static final KiwiGO> TURRET = go(() -> // EntityType.Builder.of(Turret::new, MobCategory.MISC) // .sized(0.5f, 0.8f) // .build("turret")); + + public static final KiwiGO> BASIC_BULLET = go(() -> + EntityType.Builder.of(BasicBullet::new, MobCategory.MISC) + .sized(0.5F, 0.5F) + .build("basic_bullet")); } diff --git a/src/main/java/com/hechu/mindustry/kiwi/MutilBlockModule.java b/src/main/java/com/hechu/mindustry/kiwi/MutilBlockModule.java index cb52005..f702c92 100644 --- a/src/main/java/com/hechu/mindustry/kiwi/MutilBlockModule.java +++ b/src/main/java/com/hechu/mindustry/kiwi/MutilBlockModule.java @@ -8,7 +8,8 @@ import com.hechu.mindustry.world.level.block.multiblock.MultiblockCoreBlock; import com.hechu.mindustry.world.level.block.multiblock.TestMultiblockCoreBlock; import com.hechu.mindustry.world.level.block.multiblock.TestTurretMultiblockEntityBlock; -import com.hechu.mindustry.world.level.block.turrets.TurretBlock; +import com.hechu.mindustry.world.level.block.turrets.SpectreTurretBlock; +import com.hechu.mindustry.world.level.block.turrets.SwarmerTurretBlock; import net.minecraft.world.level.block.Block; import snownee.kiwi.AbstractModule; import snownee.kiwi.KiwiGO; @@ -27,7 +28,8 @@ public class MutilBlockModule extends AbstractModule { public static final KiwiGO MECHANICAL_DRILL = go(MechanicalDrillBlock::new); public static final KiwiGO PNEUMATIC_DRILL = go(PneumaticDrillBlock::new); public static final KiwiGO HEALTH_TEST = go(HealthTestBlock::new); - public static final KiwiGO TURRET = go(TurretBlock::new); + public static final KiwiGO SWARMER_TURRET = go(SwarmerTurretBlock::new); + public static final KiwiGO SPECTRE_TURRET = go(SpectreTurretBlock::new); public static final KiwiGO TEST_MULTIBLOCK_CORE = go(TestMultiblockCoreBlock::new); public static final KiwiGO TEST_TURRET_MULTIBLOCK_ENTITY_BLOCK = go(TestTurretMultiblockEntityBlock::new); public static final KiwiGO KILN_BLOCK = go(KilnBlock::new); diff --git a/src/main/java/com/hechu/mindustry/world/entity/projectile/BasicBullet.java b/src/main/java/com/hechu/mindustry/world/entity/projectile/BasicBullet.java new file mode 100644 index 0000000..29b7c67 --- /dev/null +++ b/src/main/java/com/hechu/mindustry/world/entity/projectile/BasicBullet.java @@ -0,0 +1,162 @@ +package com.hechu.mindustry.world.entity.projectile; + +import com.hechu.mindustry.kiwi.EntityModule; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.world.damagesource.DamageSource; +import net.minecraft.world.damagesource.DamageType; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.Mob; +import net.minecraft.world.entity.projectile.AbstractHurtingProjectile; +import net.minecraft.world.entity.projectile.ProjectileUtil; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.gameevent.GameEvent; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.EntityHitResult; +import net.minecraft.world.phys.HitResult; +import net.minecraft.world.phys.Vec3; +import org.jetbrains.annotations.NotNull; + +public class BasicBullet extends BulletBase { + public BasicBullet(EntityType pEntityType, Level pLevel) { + super(pEntityType, pLevel); + } + + public BasicBullet(Level pLevel) { + super(EntityModule.BASIC_BULLET.get(), pLevel); + } + + public BasicBullet(double pX, double pY, double pZ, Level pLevel) { + super(EntityModule.BASIC_BULLET.get(), pX, pY, pZ, 0, 0, 0, pLevel); + } + + public BasicBullet(LivingEntity pShooter, double pOffsetX, double pOffsetY, double pOffsetZ, Level pLevel) { + super(EntityModule.BASIC_BULLET.get(), pShooter, pOffsetX, pOffsetY, pOffsetZ, pLevel); + } + + public float damage = 10.0F; + public int pierceCap = 2; + public boolean pierceBlock = true; + public float knockback = 0.0F; + + @Override + public void shoot(double pX, double pY, double pZ, float pVelocity, float pInaccuracy) { + super.shoot(pX, pY, pZ, pVelocity, pInaccuracy); + } + + /** + * Called to update the entity's position/logic. + */ + @Override + public void tick() { + Entity entity = this.getOwner(); + if (this.level().isClientSide || (entity == null || !entity.isRemoved()) && this.level().hasChunkAt(this.blockPosition())) { + super.tick(); + if (this.shouldBurn()) { + this.setSecondsOnFire(1); + } + + HitResult hitresult = ProjectileUtil.getHitResultOnMoveVector(this, this::canHitEntity); + if (hitresult.getType() != HitResult.Type.MISS && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, hitresult)) { + this.onHit(hitresult); + } + + this.checkInsideBlocks(); + Vec3 vec3 = this.getDeltaMovement(); + double d0 = this.getX() + vec3.x; + double d1 = this.getY() + vec3.y; + double d2 = this.getZ() + vec3.z; + ProjectileUtil.rotateTowardsMovement(this, 0.2F); + float f = this.getInertia(); + if (this.isInWater()) { + for (int i = 0; i < 4; ++i) { + float f1 = 0.25F; + this.level().addParticle(ParticleTypes.BUBBLE, d0 - vec3.x * 0.25D, d1 - vec3.y * 0.25D, d2 - vec3.z * 0.25D, vec3.x, vec3.y, vec3.z); + } + + f = 0.8F; + } + +// Vec3 deltaMovement = getDeltaMovement().add(vec3.add(xPower, yPower, xPower)).scale(f); +// this.setDeltaMovement(deltaMovement); + + this.level().addParticle(this.getTrailParticle(), d0, d1 + 0.5D, d2, 0.0D, 0.0D, 0.0D); + this.setPos(d0, d1, d2); + } else { + this.discard(); + } + } + + /** + * Return the motion factor for this projectile. The factor is multiplied by the original motion. + */ + @Override + protected float getInertia() { + return 1.0F; + } + + @Override + protected boolean shouldBurn() { + return true; + } + + /** + * Called when this EntityFireball hits a block or entity. + * + * @param pResult + */ + @Override + protected void onHit(HitResult pResult) { + HitResult.Type hitresult$type = pResult.getType(); + if (hitresult$type == HitResult.Type.ENTITY) { + Entity entity = ((EntityHitResult) pResult).getEntity(); + if (entity instanceof BulletBase) + return; + this.onHitEntity((EntityHitResult) pResult); + } else if (hitresult$type == HitResult.Type.BLOCK) { + BlockHitResult blockhitresult = (BlockHitResult) pResult; + this.onHitBlock(blockhitresult); + } + if (!this.level().isClientSide) { + this.level().broadcastEntityEvent(this, (byte) 3); + } + } + + //TODO: 一个实体或者方块疑似会被重复判定 + + /** + * Called when the arrow hits an entity + * + * @param pResult + */ + @Override + protected void onHitEntity(EntityHitResult pResult) { + Entity entity = pResult.getEntity(); + if (entity instanceof LivingEntity) { + entity.hurt(this.damageSources().mobProjectile(this, null), damage); + } + pierceCap--; + if (pierceCap < 0) { + this.level().gameEvent(GameEvent.PROJECTILE_LAND, pResult.getLocation(), GameEvent.Context.of(this, (BlockState) null)); + this.discard(); + } + } + + @Override + protected void onHitBlock(@NotNull BlockHitResult pResult) { + pierceCap--; + if (pierceCap < 0 || !pierceBlock) { + this.level().gameEvent(GameEvent.PROJECTILE_LAND, pResult.getLocation(), GameEvent.Context.of(this, (BlockState) null)); + this.discard(); + } + } + + @Override + protected @NotNull ParticleOptions getTrailParticle() { + return ParticleTypes.POOF; + } +} diff --git a/src/main/java/com/hechu/mindustry/world/entity/projectile/Bullet.java b/src/main/java/com/hechu/mindustry/world/entity/projectile/Bullet.java index 853df37..a114491 100644 --- a/src/main/java/com/hechu/mindustry/world/entity/projectile/Bullet.java +++ b/src/main/java/com/hechu/mindustry/world/entity/projectile/Bullet.java @@ -18,4 +18,6 @@ public Bullet(EntityType pEntityType, doubl public Bullet(EntityType pEntityType, LivingEntity pShooter, double pOffsetX, double pOffsetY, double pOffsetZ, Level pLevel) { super(pEntityType, pShooter, pOffsetX, pOffsetY, pOffsetZ, pLevel); } + + } diff --git a/src/main/java/com/hechu/mindustry/world/entity/projectile/BulletBase.java b/src/main/java/com/hechu/mindustry/world/entity/projectile/BulletBase.java new file mode 100644 index 0000000..496c727 --- /dev/null +++ b/src/main/java/com/hechu/mindustry/world/entity/projectile/BulletBase.java @@ -0,0 +1,20 @@ +package com.hechu.mindustry.world.entity.projectile; + +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.projectile.AbstractHurtingProjectile; +import net.minecraft.world.level.Level; + +public abstract class BulletBase extends AbstractHurtingProjectile { + public BulletBase(EntityType pEntityType, double pX, double pY, double pZ, double pOffsetX, double pOffsetY, double pOffsetZ, Level pLevel) { + super(pEntityType, pX, pY, pZ, pOffsetX, pOffsetY, pOffsetZ, pLevel); + } + + public BulletBase(EntityType pEntityType, Level pLevel) { + super(pEntityType, pLevel); + } + + public BulletBase(EntityType pEntityType, LivingEntity pShooter, double pOffsetX, double pOffsetY, double pOffsetZ, Level pLevel) { + super(pEntityType, pShooter, pOffsetX, pOffsetY, pOffsetZ, pLevel); + } +} diff --git a/src/main/java/com/hechu/mindustry/world/entity/projectile/MissileBullet.java b/src/main/java/com/hechu/mindustry/world/entity/projectile/MissileBullet.java new file mode 100644 index 0000000..b228b06 --- /dev/null +++ b/src/main/java/com/hechu/mindustry/world/entity/projectile/MissileBullet.java @@ -0,0 +1,176 @@ +package com.hechu.mindustry.world.entity.projectile; + +import com.hechu.mindustry.kiwi.EntityModule; +import net.minecraft.core.BlockPos; +import net.minecraft.core.particles.ParticleOptions; +import net.minecraft.core.particles.ParticleTypes; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.ai.targeting.TargetingConditions; +import net.minecraft.world.entity.monster.Enemy; +import net.minecraft.world.entity.projectile.AbstractHurtingProjectile; +import net.minecraft.world.entity.projectile.ProjectileUtil; +import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.Level; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.gameevent.GameEvent; +import net.minecraft.world.phys.*; +import org.jetbrains.annotations.Nullable; + +public class MissileBullet extends BulletBase { + public MissileBullet(EntityType pEntityType, Level pLevel) { + super(pEntityType, pLevel); + } + + public MissileBullet(Level pLevel) { + super(EntityModule.MISSILE_BULLET.get(), pLevel); + } + + public MissileBullet(double pX, double pY, double pZ, Level pLevel) { + super(EntityModule.MISSILE_BULLET.get(), pX, pY, pZ, 0, 0, 0, pLevel); + } + + public MissileBullet(LivingEntity pShooter, double pOffsetX, double pOffsetY, double pOffsetZ, Level pLevel) { + super(EntityModule.MISSILE_BULLET.get(), pShooter, pOffsetX, pOffsetY, pOffsetZ, pLevel); + } + + private boolean isCanSeeEntity(LivingEntity e) { + return e instanceof Enemy + && (this.level().clip(new ClipContext(position(), e.position(), ClipContext.Block.COLLIDER, + ClipContext.Fluid.NONE, null)).getType() == HitResult.Type.MISS); + } + + public LivingEntity target = null; + public Vec3 targetPos; + public double acceleration = 0.1; + public float maxVelocity = 1.0f; + + @Nullable + LivingEntity getNearestEnemy(Vec3 range) { + Vec3 pos = position(); + return level().getNearestEntity(LivingEntity.class, TargetingConditions.forCombat().selector(this::isCanSeeEntity), null, + pos.x, pos.y, pos.z, new AABB(BlockPos.containing(pos)).inflate(range.x, range.y, range.z)); + } + + @Nullable + LivingEntity getTarget() { + target = getNearestEnemy(new Vec3(64, 64, 64)); +// if (target == null || !target.isAlive()) { +// target = getNearestEnemy(new Vec3(64, 8, 64)); +// } + return target; + } + + @Override + public boolean alwaysAccepts() { + return super.alwaysAccepts(); + } + + /** + * Similar to setArrowHeading, it's point the throwable entity to a x, y, z direction. + * + * @param pX + * @param pY + * @param pZ + * @param pVelocity + * @param pInaccuracy + */ + @Override + public void shoot(double pX, double pY, double pZ, float pVelocity, float pInaccuracy) { + super.shoot(pX, pY, pZ, pVelocity, pInaccuracy); +// maxVelocity = pVelocity; + } + + /** + * Called to update the entity's position/logic. + */ + @Override + public void tick() { + Entity entity = this.getOwner(); + if (this.level().isClientSide || (entity == null || !entity.isRemoved()) && this.level().hasChunkAt(this.blockPosition())) { + super.tick(); + if (this.shouldBurn()) { + this.setSecondsOnFire(1); + } + + HitResult hitresult = ProjectileUtil.getHitResultOnMoveVector(this, this::canHitEntity); + if (hitresult.getType() != HitResult.Type.MISS && !net.minecraftforge.event.ForgeEventFactory.onProjectileImpact(this, hitresult)) { + this.onHit(hitresult); + } + + this.checkInsideBlocks(); + Vec3 vec3 = this.getDeltaMovement(); + double d0 = this.getX() + vec3.x; + double d1 = this.getY() + vec3.y; + double d2 = this.getZ() + vec3.z; + ProjectileUtil.rotateTowardsMovement(this, 0.2F); + float f = this.getInertia(); + if (this.isInWater()) { + for (int i = 0; i < 4; ++i) { + float f1 = 0.25F; + this.level().addParticle(ParticleTypes.BUBBLE, d0 - vec3.x * 0.25D, d1 - vec3.y * 0.25D, d2 - vec3.z * 0.25D, vec3.x, vec3.y, vec3.z); + } + + f = 0.8F; + } + + if (this.getTarget() != null) { + targetPos = new Vec3(target.position().x, target.position().y + target.getEyeHeight(), target.position().z); + Vec3 power = new Vec3(targetPos.x - d0, targetPos.y - d1, targetPos.z - d2).normalize().scale(acceleration); + Vec3 deltaMovement = vec3.add(power).scale((double) f).normalize().scale(maxVelocity); + this.setDeltaMovement(deltaMovement); + } + + this.level().addParticle(this.getTrailParticle(), d0, d1 + 0.5D, d2, 0.0D, 0.0D, 0.0D); + this.setPos(d0, d1, d2); + } else { + this.discard(); + } + } + + /** + * Return the motion factor for this projectile. The factor is multiplied by the original motion. + */ + @Override + protected float getInertia() { + return 1.0F; + } + + @Override + protected boolean shouldBurn() { + return true; + } + + /** + * Called when this EntityFireball hits a block or entity. + * + * @param pResult + */ + @Override + protected void onHit(HitResult pResult) { + HitResult.Type hitresult$type = pResult.getType(); + if (hitresult$type == HitResult.Type.ENTITY) { + if (((EntityHitResult) pResult).getEntity() instanceof MissileBullet) + return; + this.onHitEntity((EntityHitResult) pResult); + this.level().gameEvent(GameEvent.PROJECTILE_LAND, pResult.getLocation(), GameEvent.Context.of(this, (BlockState) null)); + level().explode(this, position().x, position().y, position().z, 1.5f, Level.ExplosionInteraction.NONE); + } else if (hitresult$type == HitResult.Type.BLOCK) { + BlockHitResult blockhitresult = (BlockHitResult) pResult; + this.onHitBlock(blockhitresult); + BlockPos blockpos = blockhitresult.getBlockPos(); + this.level().gameEvent(GameEvent.PROJECTILE_LAND, blockpos, GameEvent.Context.of(this, this.level().getBlockState(blockpos))); + level().explode(this, position().x, position().y, position().z, 1.5f, true, Level.ExplosionInteraction.NONE); + } + if (!this.level().isClientSide) { + this.level().broadcastEntityEvent(this, (byte) 3); + this.discard(); + } + } + + @Override + protected ParticleOptions getTrailParticle() { + return ParticleTypes.FLAME; + } +} diff --git a/src/main/java/com/hechu/mindustry/world/level/block/entity/turrets/SpectreTurretBlockEntity.java b/src/main/java/com/hechu/mindustry/world/level/block/entity/turrets/SpectreTurretBlockEntity.java new file mode 100644 index 0000000..d8658f8 --- /dev/null +++ b/src/main/java/com/hechu/mindustry/world/level/block/entity/turrets/SpectreTurretBlockEntity.java @@ -0,0 +1,43 @@ +package com.hechu.mindustry.world.level.block.entity.turrets; + +import com.hechu.mindustry.kiwi.BlockEntityModule; +import com.hechu.mindustry.world.entity.projectile.BasicBullet; +import com.hechu.mindustry.world.entity.projectile.MissileBullet; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec3; + +public class SpectreTurretBlockEntity extends TurretBlockEntityBase { + public SpectreTurretBlockEntity(BlockPos pos, BlockState state) { + super(BlockEntityModule.SPECTRE_TURRET_BLOCK_ENTITY.get(), pos, state); + } + + int timeAfterLastShoot = 0; + + @Override + public void tick() { + time++; + timeAfterLastShoot++; + Vec3 blockPosCenter = getBlockPos().getCenter(); + LivingEntity target = getTarget(); + if (target != null) targetPos = target.position(); + if (isShooting) { + BasicBullet bullet = new BasicBullet(blockPosCenter.x, blockPosCenter.y + 1, blockPosCenter.z, level); + double d1 = targetPos.x - blockPosCenter.x; + double d2 = targetPos.y - blockPosCenter.y; + double d3 = targetPos.z - blockPosCenter.z; + bullet.damage = 100.0F; + bullet.shoot(d1, d2, d3, 2.5F, 0.2F); + + level.addFreshEntity(bullet); + if (timeAfterLastShoot >= 2) { + isShooting = false; + } + } else if (target != null && timeAfterLastShoot >= 4) { + isShooting = true; + timeAfterLastShoot = 0; + } + } +} diff --git a/src/main/java/com/hechu/mindustry/world/level/block/entity/turrets/SwarmerTurretBlockEntity.java b/src/main/java/com/hechu/mindustry/world/level/block/entity/turrets/SwarmerTurretBlockEntity.java new file mode 100644 index 0000000..9349e5c --- /dev/null +++ b/src/main/java/com/hechu/mindustry/world/level/block/entity/turrets/SwarmerTurretBlockEntity.java @@ -0,0 +1,44 @@ +package com.hechu.mindustry.world.level.block.entity.turrets; + +import com.hechu.mindustry.kiwi.BlockEntityModule; +import com.hechu.mindustry.world.entity.projectile.MissileBullet; +import net.minecraft.core.BlockPos; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.phys.Vec3; + +public class SwarmerTurretBlockEntity extends TurretBlockEntityBase { + public SwarmerTurretBlockEntity(BlockPos pPos, BlockState pBlockState) { + super(BlockEntityModule.SWARMER_TURRET_BLOCK_ENTITY.get(), pPos, pBlockState); + } + + int timeAfterLastShoot = 0; + + @Override + public void tick() { + time++; + timeAfterLastShoot++; + Vec3 blockPosCenter = getBlockPos().getCenter(); + LivingEntity target = getTarget(); + if (target != null) targetPos = target.position(); + if (isShooting) { + if (time % 2 == 0) { + MissileBullet bullet = new MissileBullet(blockPosCenter.x, blockPosCenter.y + 1, blockPosCenter.z, level); + double d1 = targetPos.x - blockPosCenter.x; + double d3 = targetPos.z - blockPosCenter.z; + + bullet.acceleration = 0.3F; + bullet.maxVelocity = 0.7F; + bullet.shoot(d1, 100, d3, 0.2F, 2.56F); + + level.addFreshEntity(bullet); + } + if (timeAfterLastShoot >= 16) { + isShooting = false; + } + } else if (target != null && timeAfterLastShoot >= 20) { + isShooting = true; + timeAfterLastShoot = 0; + } + } +} diff --git a/src/main/java/com/hechu/mindustry/world/level/block/entity/turrets/TurretBlockEntity.java b/src/main/java/com/hechu/mindustry/world/level/block/entity/turrets/TurretBlockEntityBase.java similarity index 56% rename from src/main/java/com/hechu/mindustry/world/level/block/entity/turrets/TurretBlockEntity.java rename to src/main/java/com/hechu/mindustry/world/level/block/entity/turrets/TurretBlockEntityBase.java index 439b235..462afee 100644 --- a/src/main/java/com/hechu/mindustry/world/level/block/entity/turrets/TurretBlockEntity.java +++ b/src/main/java/com/hechu/mindustry/world/level/block/entity/turrets/TurretBlockEntityBase.java @@ -1,6 +1,5 @@ package com.hechu.mindustry.world.level.block.entity.turrets; -import com.hechu.mindustry.kiwi.BlockEntityModule; import com.hechu.mindustry.utils.capabilities.HealthHandler; import com.hechu.mindustry.utils.capabilities.IHealthHandler; import com.hechu.mindustry.utils.capabilities.MindustryCapabilities; @@ -15,8 +14,8 @@ import net.minecraft.world.entity.LivingEntity; import net.minecraft.world.entity.ai.targeting.TargetingConditions; import net.minecraft.world.entity.monster.Enemy; -import net.minecraft.world.entity.projectile.Arrow; import net.minecraft.world.level.ClipContext; +import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraft.world.level.block.state.BlockState; import net.minecraft.world.phys.AABB; import net.minecraft.world.phys.HitResult; @@ -27,20 +26,23 @@ import org.jetbrains.annotations.Nullable; import snownee.kiwi.block.entity.ModBlockEntity; -public class TurretBlockEntity extends ModBlockEntity { - public static final String NAME = "turret"; - +public abstract class TurretBlockEntityBase extends ModBlockEntity { + private final LazyOptional healthHandler = LazyOptional.of(HealthHandler::new); public int time; public float rot; public float oRot; public float tRot; - - public TurretBlockEntity(BlockPos pPos, BlockState pBlockState) { - super(BlockEntityModule.TURRET_BLOCK_ENTITY.get(), pPos, pBlockState); + public LivingEntity target = null; + public Vec3 targetPos = Vec3.ZERO; + /** + * 是否正在发射 + */ + public boolean isShooting = false; + + public TurretBlockEntityBase(BlockEntityType tileEntityTypeIn, BlockPos pos, BlockState state) { + super(tileEntityTypeIn, pos, state); } - private final LazyOptional healthHandler = LazyOptional.of(HealthHandler::new); - private boolean isCanSeeEntity(LivingEntity e) { return e instanceof Enemy && (this.level.clip(new ClipContext(getBlockPos().above().above().getCenter(), e.position(), ClipContext.Block.COLLIDER, @@ -55,11 +57,6 @@ private boolean isCanSeeEntity(LivingEntity e) { return super.getCapability(cap, side); } - public LivingEntity target = null; - public double targetPosX; - public double targetPosY; - public double targetPosZ; - @Nullable LivingEntity getNearestEnemy(Vec3 range) { BlockPos blockPos = this.getBlockPos(); @@ -90,9 +87,9 @@ public void onDataPacket(Connection net, ClientboundBlockEntityDataPacket pkt) { @Override public @NotNull CompoundTag getUpdateTag() { CompoundTag tag = super.getUpdateTag(); - tag.putDouble("targetPosX", targetPosX); - tag.putDouble("targetPosY", targetPosY); - tag.putDouble("targetPosZ", targetPosZ); + tag.putDouble("targetPosX", targetPos.x); + tag.putDouble("targetPosY", targetPos.y); + tag.putDouble("targetPosZ", targetPos.z); return tag; } @@ -109,47 +106,10 @@ protected CompoundTag writePacketData(CompoundTag compoundTag) { @Override public void handleUpdateTag(CompoundTag tag) { - targetPosX = tag.getDouble("targetPosX"); - targetPosY = tag.getDouble("targetPosY"); - targetPosZ = tag.getDouble("targetPosZ"); + targetPos = new Vec3(tag.getDouble("targetPosX"), tag.getDouble("targetPosY"), tag.getDouble("targetPosZ")); } - public void tick() { - BlockPos blockPos = getBlockPos(); - - time++; - if (time % 5 != 0) - return; - - Vec3 pos = blockPos.getCenter(); - pos = pos.add(0, 1, 0); - LivingEntity target = getTarget(); - if (target != null) { - Arrow bullet = new Arrow(level, pos.x, pos.y, pos.z); - Vec3 blockPosCenter = blockPos.getCenter(); - double d0 = target.getEyeY(); - double d1 = target.getX() - blockPosCenter.x; - double d2 = d0 - bullet.getY() - target.getBoundingBox().getYsize(); - double d3 = target.getZ() - blockPosCenter.z; - double d4 = Math.pow(Math.sqrt(d1 * d1 + d3 * d3), 1.55) * (double) 0.02F; - - bullet.shoot(d1, d2 + d4, d3, 3.2F, 2.56F); -// bullet.noPhysics = true; -// bullet.shoot(d1, 0, d3, 3.2F, 2.56F); -// this.playSound(SoundEvents.ARROW_SHOOT, 1.0F, 0.4F / (this.getRandom().nextFloat() * 0.4F + 0.8F)); - level.addFreshEntity(bullet); - } - - if (target != null) { - targetPosX = target.getX(); - targetPosY = target.getY(); - targetPosZ = target.getZ(); - } else { - targetPosX = 0; - targetPosY = 0; - targetPosZ = 0; - } - } + public abstract void tick(); public void serverTick() { tick(); @@ -160,44 +120,57 @@ public void serverTick() { public void clientTick() { tick(); - BlockPos blockPos = getBlockPos(); oRot = rot; - if (targetPosX != 0 || targetPosY != 0 || targetPosZ != 0) { - double d0 = targetPosX - ((double) blockPos.getX() + 0.5D); - double d1 = targetPosZ - ((double) blockPos.getZ() + 0.5D); - tRot = (float) Mth.atan2(d1, d0); - } else { - tRot += 0.02F; - } + if (target != null) { + double d0 = targetPos.x - ((double) blockPos.getX() + 0.5D); + double d1 = targetPos.z - ((double) blockPos.getZ() + 0.5D); + tRot = (float) Mth.atan2(d1, d0); + } else - while (rot >= (float) Math.PI) { - rot -= ((float) Math.PI * 2F); - } + { + tRot += 0.02F; + } - while (rot < -(float) Math.PI) { - rot += ((float) Math.PI * 2F); - } + while(rot >=(float)Math.PI) - while (tRot >= (float) Math.PI) { - tRot -= ((float) Math.PI * 2F); - } + { + rot -= ((float) Math.PI * 2F); + } - while (tRot < -(float) Math.PI) { - tRot += ((float) Math.PI * 2F); - } + while(rot< -(float)Math.PI) - float f2; - f2 = tRot - rot; - while (f2 >= (float) Math.PI) { - f2 -= ((float) Math.PI * 2F); - } + { + rot += ((float) Math.PI * 2F); + } - while (f2 < -(float) Math.PI) { - f2 += ((float) Math.PI * 2F); - } + while(tRot >=(float)Math.PI) + + { + tRot -= ((float) Math.PI * 2F); + } + + while(tRot< -(float)Math.PI) + + { + tRot += ((float) Math.PI * 2F); + } + + float f2; + f2 =tRot -rot; + while(f2 >=(float)Math.PI) - rot += f2 * 0.4F; - float f3 = 0.2F; + { + f2 -= ((float) Math.PI * 2F); } + + while(f2< -(float)Math.PI) + + { + f2 += ((float) Math.PI * 2F); + } + + rot +=f2 *0.4F; + float f3 = 0.2F; +} } diff --git a/src/main/java/com/hechu/mindustry/world/level/block/turrets/SpectreTurretBlock.java b/src/main/java/com/hechu/mindustry/world/level/block/turrets/SpectreTurretBlock.java new file mode 100644 index 0000000..cfb8b86 --- /dev/null +++ b/src/main/java/com/hechu/mindustry/world/level/block/turrets/SpectreTurretBlock.java @@ -0,0 +1,26 @@ +package com.hechu.mindustry.world.level.block.turrets; + +import com.hechu.mindustry.utils.capabilities.MindustryCapabilities; +import com.hechu.mindustry.world.level.block.entity.turrets.SpectreTurretBlockEntity; +import com.hechu.mindustry.world.level.block.entity.turrets.SwarmerTurretBlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.Nullable; + +public class SpectreTurretBlock extends TurretBlockBase { + public SpectreTurretBlock() { + super(Properties.of().destroyTime(3).strength(3.0F, 3.0F)); + } + + @Nullable + @Override + public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) { + SpectreTurretBlockEntity spectreTurretBlockEntity = new SpectreTurretBlockEntity(pPos, pState); + spectreTurretBlockEntity.getCapability(MindustryCapabilities.HEALTH_HANDLER, null).ifPresent(healthHandler -> { + healthHandler.setMaxHealth(100); + healthHandler.setHealth(100); + }); + return spectreTurretBlockEntity; + } +} diff --git a/src/main/java/com/hechu/mindustry/world/level/block/turrets/SwarmerTurretBlock.java b/src/main/java/com/hechu/mindustry/world/level/block/turrets/SwarmerTurretBlock.java new file mode 100644 index 0000000..d6f165d --- /dev/null +++ b/src/main/java/com/hechu/mindustry/world/level/block/turrets/SwarmerTurretBlock.java @@ -0,0 +1,27 @@ +package com.hechu.mindustry.world.level.block.turrets; + +import com.hechu.mindustry.utils.capabilities.MindustryCapabilities; +import com.hechu.mindustry.world.level.block.entity.turrets.SwarmerTurretBlockEntity; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.state.BlockState; +import org.jetbrains.annotations.NotNull; +import org.jetbrains.annotations.Nullable; + +public class SwarmerTurretBlock extends TurretBlockBase { + public SwarmerTurretBlock() { + super(Properties.of().destroyTime(3).strength(3.0F, 3.0F)); + } + + @Nullable + @Override + public BlockEntity newBlockEntity(@NotNull BlockPos pPos, @NotNull BlockState pState) { + SwarmerTurretBlockEntity swarmerTurretBlockEntity = new SwarmerTurretBlockEntity(pPos, pState); + swarmerTurretBlockEntity.getCapability(MindustryCapabilities.HEALTH_HANDLER, null).ifPresent(healthHandler -> { + healthHandler.setMaxHealth(100); + healthHandler.setHealth(100); + }); + return swarmerTurretBlockEntity; + } + +} diff --git a/src/main/java/com/hechu/mindustry/world/level/block/turrets/TurretBlock.java b/src/main/java/com/hechu/mindustry/world/level/block/turrets/TurretBlockBase.java similarity index 53% rename from src/main/java/com/hechu/mindustry/world/level/block/turrets/TurretBlock.java rename to src/main/java/com/hechu/mindustry/world/level/block/turrets/TurretBlockBase.java index 87c07b5..3d75498 100644 --- a/src/main/java/com/hechu/mindustry/world/level/block/turrets/TurretBlock.java +++ b/src/main/java/com/hechu/mindustry/world/level/block/turrets/TurretBlockBase.java @@ -1,47 +1,33 @@ package com.hechu.mindustry.world.level.block.turrets; -import com.hechu.mindustry.utils.capabilities.MindustryCapabilities; -import com.hechu.mindustry.world.level.block.entity.turrets.TurretBlockEntity; -import net.minecraft.core.BlockPos; +import com.hechu.mindustry.world.level.block.entity.turrets.SwarmerTurretBlockEntity; +import com.hechu.mindustry.world.level.block.entity.turrets.TurretBlockEntityBase; import net.minecraft.world.level.Level; import net.minecraft.world.level.block.BaseEntityBlock; import net.minecraft.world.level.block.RenderShape; import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraft.world.level.block.entity.BlockEntityTicker; import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.level.block.state.BlockBehaviour; import net.minecraft.world.level.block.state.BlockState; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import snownee.kiwi.block.IKiwiBlock; -public class TurretBlock extends BaseEntityBlock implements IKiwiBlock { - - public static final String NAME = "turret"; - - public TurretBlock() { - super(Properties.of().destroyTime(3).strength(3.0F, 3.0F)); - } - - @Nullable - @Override - public BlockEntity newBlockEntity(@NotNull BlockPos pPos, @NotNull BlockState pState) { - TurretBlockEntity turretBlockEntity = new TurretBlockEntity(pPos, pState); - turretBlockEntity.getCapability(MindustryCapabilities.HEALTH_HANDLER, null).ifPresent(healthHandler -> { - healthHandler.setMaxHealth(100); - healthHandler.setHealth(100); - }); - return turretBlockEntity; +public abstract class TurretBlockBase extends BaseEntityBlock implements IKiwiBlock { + public TurretBlockBase(Properties pProperties) { + super(pProperties); } @Nullable @Override public BlockEntityTicker getTicker(@NotNull Level level, @NotNull BlockState state, @NotNull BlockEntityType type) { return (pLevel1, pPos, pState1, pBlockEntity) -> { - if (pBlockEntity instanceof TurretBlockEntity turretBlockEntity) { + if (pBlockEntity instanceof TurretBlockEntityBase turretBlockEntityBase) { if (pLevel1.isClientSide) { - turretBlockEntity.clientTick(); + turretBlockEntityBase.clientTick(); } else { - turretBlockEntity.serverTick(); + turretBlockEntityBase.serverTick(); } } }; diff --git a/src/main/resources/assets/mindustry/blockstates/turret.json b/src/main/resources/assets/mindustry/blockstates/spectre_turret.json similarity index 100% rename from src/main/resources/assets/mindustry/blockstates/turret.json rename to src/main/resources/assets/mindustry/blockstates/spectre_turret.json diff --git a/src/main/resources/assets/mindustry/blockstates/swarmer_turret.json b/src/main/resources/assets/mindustry/blockstates/swarmer_turret.json new file mode 100644 index 0000000..c9c4dd1 --- /dev/null +++ b/src/main/resources/assets/mindustry/blockstates/swarmer_turret.json @@ -0,0 +1,7 @@ +{ + "variants": { + "": { + "model": "mindustry:block/health_test" + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/mindustry/lang/en_US.json b/src/main/resources/assets/mindustry/lang/en_US.json index 4a662df..f9ad7d1 100644 --- a/src/main/resources/assets/mindustry/lang/en_US.json +++ b/src/main/resources/assets/mindustry/lang/en_US.json @@ -11,7 +11,8 @@ "block.mindustry.scrap_ore": "Scrap Ore", "block.mindustry.thorium_ore": "Thorium Ore", "block.mindustry.titanium_ore": "Titanium Ore", - + "block.mindustry.swarmer_turret": "Swarmer", + "block.mindustry.spectre_turret": "Spectre", "item.mindustry.copper": "Copper", "item.mindustry.coal": "Coal", @@ -27,6 +28,11 @@ "item.mindustry.pyratite": "Pyratite", "item.mindustry.silicon": "Silicon", "item.mindustry.surge_alloy": "Surge Alloy", + "item.mindustry.swarmer_turret": "Swarmer", + "item.mindustry.spectre_turret": "Spectre", + + "entity.mindustry.missile_bullet": "Missile", + "entity.mindustry.basic_bullet": "Basic Bullet", "config.jade.plugin_mindustry.crafting_block": "Show Factory Progress", "config.jade.plugin_mindustry.drill": "Show Drill Detail", diff --git a/src/main/resources/assets/mindustry/lang/zh_CN.json b/src/main/resources/assets/mindustry/lang/zh_CN.json index 06e4070..fb7b0ae 100644 --- a/src/main/resources/assets/mindustry/lang/zh_CN.json +++ b/src/main/resources/assets/mindustry/lang/zh_CN.json @@ -11,6 +11,8 @@ "block.mindustry.thorium_ore": "钍矿", "block.mindustry.titanium_ore": "钛矿", "block.mindustry.lead_ore": "铅矿", + "block.mindustry.swarmer_turret": "蜂群", + "block.mindustry.spectre_turret": "幽灵", "item.mindustry.copper": "铜", "item.mindustry.coal": "煤", @@ -25,6 +27,11 @@ "item.mindustry.pyratite": "硫化物", "item.mindustry.silicon": "硅", "item.mindustry.surge_alloy": "巨浪合金", + "item.mindustry.swarmer_turret": "蜂群", + "item.mindustry.spectre_turret": "幽灵", + + "entity.mindustry.missile_bullet": "导弹", + "entity.mindustry.basic_bullet": "普通子弹", "config.jade.plugin_mindustry.crafting_block": "显示工厂制作进度", "config.jade.plugin_mindustry.drill": "显示钻头属性", diff --git a/src/main/resources/assets/mindustry/models/item/spectre_turret.json b/src/main/resources/assets/mindustry/models/item/spectre_turret.json new file mode 100644 index 0000000..77f29aa --- /dev/null +++ b/src/main/resources/assets/mindustry/models/item/spectre_turret.json @@ -0,0 +1,7 @@ +{ + "parent": "minecraft:block/cube_column", + "textures": { + "end": "minecraft:block/target_top", + "side": "minecraft:block/target_side" + } +} diff --git a/src/main/resources/assets/mindustry/models/item/swarmer_turret.json b/src/main/resources/assets/mindustry/models/item/swarmer_turret.json new file mode 100644 index 0000000..77f29aa --- /dev/null +++ b/src/main/resources/assets/mindustry/models/item/swarmer_turret.json @@ -0,0 +1,7 @@ +{ + "parent": "minecraft:block/cube_column", + "textures": { + "end": "minecraft:block/target_top", + "side": "minecraft:block/target_side" + } +} diff --git a/src/main/resources/assets/mindustry/textures/entity/bullets/missile_bullet.png b/src/main/resources/assets/mindustry/textures/entity/bullets/missile_bullet.png new file mode 100644 index 0000000..2d890a4 Binary files /dev/null and b/src/main/resources/assets/mindustry/textures/entity/bullets/missile_bullet.png differ