-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4b3b1f8
commit a0b351c
Showing
15 changed files
with
544 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,16 @@ | ||
package danilcus.magnetism; | ||
|
||
import danilcus.magnetism.entity.SawBladeModel; | ||
import danilcus.magnetism.entity.SawRenderer; | ||
import net.fabricmc.api.ClientModInitializer; | ||
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry; | ||
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry; | ||
|
||
public class MagnetismClient implements ClientModInitializer { | ||
@Override | ||
public void onInitializeClient() { | ||
// This entrypoint is suitable for setting up client-specific logic, such as rendering. | ||
EntityRendererRegistry.register(Magnetism.SAW, SawRenderer::new); | ||
EntityModelLayerRegistry.registerModelLayer(SawBladeModel.SAWBLADE, SawBladeModel::getTexturedModelData); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
src/client/java/danilcus/magnetism/entity/SawBladeModel.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package danilcus.magnetism.entity; | ||
|
||
import danilcus.magnetism.Magnetism; | ||
import net.minecraft.client.model.*; | ||
import net.minecraft.client.render.VertexConsumer; | ||
import net.minecraft.client.render.entity.model.EntityModelLayer; | ||
import net.minecraft.client.render.entity.model.SinglePartEntityModel; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
|
||
public class SawBladeModel<T extends SawEntity> extends SinglePartEntityModel<T> { | ||
private final ModelPart Saw; | ||
public SawBladeModel(ModelPart root) { | ||
this.Saw = root.getChild("Saw"); | ||
} | ||
public static final EntityModelLayer SAWBLADE = new EntityModelLayer(Magnetism.ID("sawblade"), "main"); | ||
public static TexturedModelData getTexturedModelData() { | ||
ModelData modelData = new ModelData(); | ||
ModelPartData modelPartData = modelData.getRoot(); | ||
ModelPartData bb_main = modelPartData.addChild("Saw", ModelPartBuilder.create().uv(-16, 0).cuboid(-8.0F, 0.8F, -8.0F, 16.0F, 0.1F, 16.0F, new Dilation(0.0F)), ModelTransform.pivot(0.0F, 0.0F, 0.0F)); | ||
return TexturedModelData.of(modelData, 32, 16); | ||
} | ||
@Override | ||
public void setAngles(SawEntity entity, float limbSwing, float limbSwingAmount, float ageInTicks, float netHeadYaw, float headPitch) { | ||
} | ||
@Override | ||
public void render(MatrixStack matrices, VertexConsumer vertexConsumer, int light, int overlay, float red, float green, float blue, float alpha) { | ||
Saw.render(matrices, vertexConsumer, light, overlay, red, green, blue, alpha); | ||
} | ||
|
||
@Override | ||
public ModelPart getPart() { | ||
return Saw; | ||
} | ||
} |
36 changes: 36 additions & 0 deletions
36
src/client/java/danilcus/magnetism/entity/SawRenderer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package danilcus.magnetism.entity; | ||
|
||
import danilcus.magnetism.Magnetism; | ||
import net.minecraft.client.render.OverlayTexture; | ||
import net.minecraft.client.render.VertexConsumer; | ||
import net.minecraft.client.render.VertexConsumerProvider; | ||
import net.minecraft.client.render.entity.EntityRenderer; | ||
import net.minecraft.client.render.entity.EntityRendererFactory; | ||
import net.minecraft.client.render.entity.ProjectileEntityRenderer; | ||
import net.minecraft.client.render.entity.model.TridentEntityModel; | ||
import net.minecraft.client.render.item.ItemRenderer; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.entity.projectile.TridentEntity; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.math.MathHelper; | ||
import net.minecraft.util.math.Vec3f; | ||
|
||
public class SawRenderer extends EntityRenderer<SawEntity> { | ||
public static final Identifier TEXTURE = Magnetism.ID("textures/entity/saw_blade.png"); | ||
private final SawBladeModel model; | ||
|
||
public SawRenderer(EntityRendererFactory.Context context) { | ||
super(context); | ||
this.model = new SawBladeModel<>(context.getPart(SawBladeModel.SAWBLADE)); | ||
} | ||
|
||
public void render(SawEntity sawEntity, float f, float g, MatrixStack matrixStack, VertexConsumerProvider vertexConsumerProvider, int i) { | ||
VertexConsumer vertexConsumer = vertexConsumerProvider.getBuffer(this.model.getLayer(TEXTURE)); | ||
this.model.render(matrixStack, vertexConsumer, i, OverlayTexture.DEFAULT_UV, 1.0F, 1.0F, 1.0F, 1.0F); | ||
super.render(sawEntity, f, g, matrixStack, vertexConsumerProvider, i); | ||
} | ||
|
||
public Identifier getTexture(SawEntity entity) { | ||
return TEXTURE; | ||
} | ||
} |
15 changes: 0 additions & 15 deletions
15
src/client/java/danilcus/magnetism/mixin/client/ExampleClientMixin.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,22 +1,49 @@ | ||
package danilcus.magnetism; | ||
|
||
import danilcus.magnetism.entity.SawEntity; | ||
import danilcus.magnetism.item.SawBladeItem; | ||
import danilcus.magnetism.item.SawbladeLauncherItem; | ||
import net.fabricmc.api.ModInitializer; | ||
|
||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings; | ||
import net.fabricmc.fabric.api.object.builder.v1.entity.FabricEntityTypeBuilder; | ||
import net.minecraft.entity.EntityDimensions; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.SpawnGroup; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemGroup; | ||
import net.minecraft.item.ToolMaterials; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.registry.Registry; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
|
||
public class Magnetism implements ModInitializer { | ||
// This logger is used to write text to the console and the log file. | ||
// It is considered best practice to use your mod id as the logger's name. | ||
// That way, it's clear which mod wrote info, warnings, and errors. | ||
public static final Logger LOGGER = LoggerFactory.getLogger("magnetism"); | ||
public static final String MOD_ID = "magnetism"; | ||
public static final Logger LOGGER = LoggerFactory.getLogger(MOD_ID); | ||
|
||
public static final EntityType<SawEntity> SAW = Registry.register( | ||
Registry.ENTITY_TYPE, | ||
ID("saw_entity"), | ||
FabricEntityTypeBuilder.<SawEntity>create(SpawnGroup.MISC, SawEntity::new) | ||
.dimensions(EntityDimensions.fixed(1.0f, 0.2F)) | ||
.build() | ||
); | ||
|
||
public static final Item SAWBLADE_LAUNCHER = Registry.register(Registry.ITEM, ID("sawblade_launcher"), new SawbladeLauncherItem(new FabricItemSettings().group(ItemGroup.COMBAT).fireproof())); | ||
public static final Item SAW_BLADE = Registry.register(Registry.ITEM, ID("saw_blade"), new SawBladeItem(new FabricItemSettings().group(ItemGroup.COMBAT))); | ||
|
||
@Override | ||
public void onInitialize() { | ||
// This code runs as soon as Minecraft is in a mod-load-ready state. | ||
// However, some things (like resources) may still be uninitialized. | ||
// Proceed with mild caution. | ||
} | ||
|
||
LOGGER.info("Hello Fabric world!"); | ||
public static Identifier ID(String path) { | ||
return new Identifier(MOD_ID, path); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,165 @@ | ||
package danilcus.magnetism.entity; | ||
|
||
import com.google.common.collect.Lists; | ||
import danilcus.magnetism.Magnetism; | ||
import danilcus.magnetism.item.SawBladeItem; | ||
import it.unimi.dsi.fastutil.ints.IntOpenHashSet; | ||
import net.minecraft.advancement.criterion.Criteria; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.enchantment.EnchantmentHelper; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.MovementType; | ||
import net.minecraft.entity.attribute.EntityAttributes; | ||
import net.minecraft.entity.damage.DamageSource; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.projectile.PersistentProjectileEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.network.packet.s2c.play.GameStateChangeS2CPacket; | ||
import net.minecraft.particle.ParticleTypes; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.sound.SoundEvent; | ||
import net.minecraft.sound.SoundEvents; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.hit.EntityHitResult; | ||
import net.minecraft.util.hit.HitResult; | ||
import net.minecraft.util.math.*; | ||
import net.minecraft.util.shape.VoxelShape; | ||
import net.minecraft.world.RaycastContext; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
public class SawEntity extends PersistentProjectileEntity { | ||
@Nullable | ||
private BlockState inBlockState; | ||
private int life; | ||
private double damage = 8.0; | ||
private int punch; | ||
|
||
public SawEntity(EntityType<? extends PersistentProjectileEntity> entityType, World world) { | ||
super(entityType, world); | ||
} | ||
|
||
public SawEntity(World world, LivingEntity owner) { | ||
super(Magnetism.SAW, owner, world); | ||
} | ||
|
||
@Override | ||
public void tick() { | ||
super.tick(); | ||
|
||
} | ||
|
||
@Override | ||
protected void onEntityHit(EntityHitResult entityHitResult) { | ||
Entity entity = entityHitResult.getEntity(); | ||
float f = (float)this.getVelocity().length(); | ||
int i = (int) this.damage; | ||
|
||
Entity entity2 = this.getOwner(); | ||
DamageSource damageSource; | ||
if (entity2 == null) { | ||
damageSource = DamageSource.arrow(this, this); | ||
} else { | ||
damageSource = DamageSource.arrow(this, entity2); | ||
if (entity2 instanceof LivingEntity) { | ||
((LivingEntity)entity2).onAttacking(entity); | ||
} | ||
} | ||
|
||
boolean bl = entity.getType() == EntityType.ENDERMAN; | ||
int j = entity.getFireTicks(); | ||
if (this.isOnFire() && !bl) { | ||
entity.setOnFireFor(5); | ||
} | ||
|
||
if (entity.damage(damageSource, (float)i)) { | ||
if (bl) { | ||
return; | ||
} | ||
|
||
if (entity instanceof LivingEntity livingEntity) { | ||
if (this.punch > 0) { | ||
double d = Math.max(0.0, 1.0 - livingEntity.getAttributeValue(EntityAttributes.GENERIC_KNOCKBACK_RESISTANCE)); | ||
Vec3d vec3d = this.getVelocity().multiply(1.0, 0.0, 1.0).normalize().multiply((double)this.punch * 0.6 * d); | ||
if (vec3d.lengthSquared() > 0.0) { | ||
livingEntity.addVelocity(vec3d.x, 0.1, vec3d.z); | ||
} | ||
} | ||
|
||
if (!this.world.isClient && entity2 instanceof LivingEntity) { | ||
EnchantmentHelper.onUserDamaged(livingEntity, entity2); | ||
EnchantmentHelper.onTargetDamaged((LivingEntity)entity2, livingEntity); | ||
} | ||
|
||
this.onHit(livingEntity); | ||
if (livingEntity != entity2 && livingEntity instanceof PlayerEntity && entity2 instanceof ServerPlayerEntity && !this.isSilent()) { | ||
((ServerPlayerEntity)entity2) | ||
.networkHandler | ||
.sendPacket(new GameStateChangeS2CPacket(GameStateChangeS2CPacket.PROJECTILE_HIT_PLAYER, GameStateChangeS2CPacket.DEMO_OPEN_SCREEN)); | ||
} | ||
|
||
if (!this.world.isClient && entity2 instanceof ServerPlayerEntity serverPlayerEntity) { | ||
if (!entity.isAlive() && this.isShotFromCrossbow()) { | ||
Criteria.KILLED_BY_CROSSBOW.trigger(serverPlayerEntity, Arrays.asList(entity)); | ||
} | ||
} | ||
} | ||
|
||
this.playSound(this.getSound(), 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F)); | ||
} else { | ||
entity.setFireTicks(j); | ||
this.setVelocity(this.getVelocity().multiply(-0.1)); | ||
this.setYaw(this.getYaw() + 180.0F); | ||
this.prevYaw += 180.0F; | ||
if (!this.world.isClient && this.getVelocity().lengthSquared() < 1.0E-7) { | ||
if (this.pickupType == PersistentProjectileEntity.PickupPermission.ALLOWED) { | ||
this.dropStack(this.asItemStack(), 0.1F); | ||
} | ||
|
||
this.discard(); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void onBlockHit(BlockHitResult blockHitResult) { | ||
this.inBlockState = this.world.getBlockState(blockHitResult.getBlockPos()); | ||
inBlockState.onProjectileHit(this.world, inBlockState, blockHitResult, this); | ||
Direction dir = blockHitResult.getSide(); | ||
if(!this.isShotFromCrossbow() || (dir != Direction.UP && dir != Direction.DOWN) || this.getVelocity().horizontalLength() == 0) { | ||
Vec3d vec3d = blockHitResult.getPos().subtract(this.getX(), this.getY(), this.getZ()); | ||
this.setVelocity(vec3d); | ||
Vec3d vec3d2 = vec3d.normalize().multiply(0.05F); | ||
this.setPos(this.getX() - vec3d2.x, this.getY() - vec3d2.y, this.getZ() - vec3d2.z); | ||
this.playSound(this.getSound(), 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F)); | ||
this.inGround = true; | ||
this.shake = 7; | ||
this.setCritical(false); | ||
this.setSound(SoundEvents.ITEM_TRIDENT_HIT_GROUND); | ||
this.setShotFromCrossbow(false); | ||
} else { | ||
Vec3d vec3d = this.getVelocity(); | ||
this.setVelocity(vec3d.multiply(0.8d)); | ||
Vec3d vec3d2 = this.getVelocity(); | ||
double bounce = Math.abs(vec3d2.x + vec3d2.z) * 1000d * 0.1d; | ||
this.setVelocity(vec3d2.x, bounce / 1000d, vec3d2.z); | ||
this.playSound(SoundEvents.BLOCK_RESPAWN_ANCHOR_CHARGE, 1.0F, 1.2F / (this.random.nextFloat() * 0.2F + 0.9F)); | ||
} | ||
} | ||
|
||
protected SoundEvent getHitSound() { | ||
return SoundEvents.BLOCK_ANVIL_LAND; | ||
} | ||
|
||
@Override | ||
protected ItemStack asItemStack() { | ||
return new ItemStack(Magnetism.SAW_BLADE); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package danilcus.magnetism.item; | ||
|
||
import danilcus.magnetism.entity.SawEntity; | ||
import net.minecraft.entity.LivingEntity; | ||
import net.minecraft.entity.projectile.PersistentProjectileEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.world.World; | ||
|
||
public class SawBladeItem extends Item { | ||
public SawBladeItem(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
public PersistentProjectileEntity createArrow(World world, ItemStack stack, LivingEntity shooter) { | ||
return new SawEntity(world, shooter); | ||
} | ||
} |
Oops, something went wrong.