Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/main/java/mc/duzo/timeless/Timeless.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import dev.amble.lib.container.RegistryContainer;
import net.fabricmc.api.ModInitializer;
import net.minecraft.util.Identifier;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down Expand Up @@ -38,4 +39,8 @@ public void onInitialize() {
// Networking
Network.init();
}

public static Identifier id(String path) {
return new Identifier(MOD_ID, path);
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package mc.duzo.timeless.mixin.client;

import mc.duzo.timeless.suit.client.render.SuitModel;
import net.minecraft.entity.EquipmentSlot;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
Expand Down Expand Up @@ -35,6 +36,20 @@ public PlayerEntityRendererMixin(EntityRendererFactory.Context ctx, PlayerEntity
}

@Inject(method = "renderArm" , at = @At("HEAD"), cancellable = true)
private void timeless$stopArmRender(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, AbstractClientPlayerEntity player, ModelPart arm, ModelPart sleeve, CallbackInfo ci){
Suit suit = Suit.findSuit(player, EquipmentSlot.CHEST).orElse(null);
if (suit == null) return;
ClientSuit clientSuit = suit.toClient();
if (!(clientSuit.hasModel())) return;

boolean isRight = player.getMainArm() == Arm.RIGHT;
// todo - this will create a new model every frame, which is bad
SuitModel model = clientSuit.model().get();

if (!model.shouldRenderOriginalArm(isRight, player)) ci.cancel();
}

@Inject(method = "renderArm" , at = @At("TAIL"))
private void timeless$renderArm(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, AbstractClientPlayerEntity player, ModelPart arm, ModelPart sleeve, CallbackInfo ci){
Suit suit = Suit.findSuit(player, EquipmentSlot.CHEST).orElse(null);
if (suit == null) return;
Expand All @@ -43,7 +58,7 @@ public PlayerEntityRendererMixin(EntityRendererFactory.Context ctx, PlayerEntity

boolean isRight = player.getMainArm() == Arm.RIGHT;
// todo - this will create a new model every frame, which is bad
clientSuit.model().get().renderArm(isRight, player, 0, matrices, vertexConsumers.getBuffer(RenderLayer.getEntityTranslucent(clientSuit.texture())), light, 1, 1, 1, 1);
ci.cancel();
SuitModel model = clientSuit.model().get();
model.renderArm(isRight, player, 0, matrices, vertexConsumers.getBuffer(RenderLayer.getEntityTranslucent(clientSuit.texture())), light, 1, 1, 1, 1);
}
}
67 changes: 67 additions & 0 deletions src/main/java/mc/duzo/timeless/power/BasicTogglePower.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package mc.duzo.timeless.power;

import mc.duzo.timeless.suit.api.EquipSoundSupplier;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.sound.SoundEvent;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

import java.util.Optional;
import java.util.function.Consumer;

public class BasicTogglePower extends TogglePower<EquipSoundSupplier> {
@Nullable
protected final Consumer<ServerPlayerEntity> toggleAction;
@Nullable
protected final Consumer<ServerPlayerEntity> enabledTick;
@Nullable
protected final Consumer<ServerPlayerEntity> disabledTick;

public BasicTogglePower(String modid, String key,
@Nullable Consumer<ServerPlayerEntity> enabled,
@Nullable Consumer<ServerPlayerEntity> toggle,
@Nullable Consumer<ServerPlayerEntity> disabledTick) {
super(modid, key);

this.toggleAction = toggle;
this.enabledTick = enabled;
this.disabledTick = disabledTick;
}

@Override
public boolean run(ServerPlayerEntity player) {
if (toggleAction != null) {
toggleAction.accept(player);
}

return super.run(player);
}

@Override
public void tick(ServerPlayerEntity player) {
boolean value = getValue(player);

if (value && enabledTick != null) {
enabledTick.accept(player);
} else if (!value && disabledTick != null) {
disabledTick.accept(player);
}

super.tick(player);
}

@Override
protected Class<EquipSoundSupplier> getSuitClass() {
return EquipSoundSupplier.class;
}

@Override
public Identifier getAnimation(boolean isOpening, EquipSoundSupplier suit) {
return null;
}

@Override
public Optional<SoundEvent> getSound(EquipSoundSupplier suit) {
return suit.getEquipSound();
}
}
4 changes: 4 additions & 0 deletions src/main/java/mc/duzo/timeless/power/PowerRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,10 @@ public static <T extends Power> T register(T entry) {
})
.build().register();
public static Power SWIFT_SNEAK = Power.Builder.create(new Identifier(Timeless.MOD_ID, "swift_sneak")).build().register();
public static BasicTogglePower INVISIBILITY = new BasicTogglePower(Timeless.MOD_ID, "invisibility", (player) -> {
if (player.getServer().getTicks() % 20 != 0) return; // Run every second
player.addStatusEffect(new StatusEffectInstance(StatusEffects.INVISIBILITY, 22, 3, false, false));
}, null, null).register();

public static void init() {}
}
14 changes: 14 additions & 0 deletions src/main/java/mc/duzo/timeless/suit/api/SimpleSuitItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package mc.duzo.timeless.suit.api;

import mc.duzo.timeless.core.items.SuitItem;
import mc.duzo.timeless.core.items.SuitMaterial;
import mc.duzo.timeless.datagen.provider.lang.AutomaticSuitEnglish;
import mc.duzo.timeless.datagen.provider.model.AutomaticModel;
import mc.duzo.timeless.suit.Suit;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;

public class SimpleSuitItem extends SuitItem implements AutomaticModel, AutomaticSuitEnglish {
public SimpleSuitItem(Suit suit, Type type, SuitMaterial material) {
super(suit, material, type, new FabricItemSettings().maxCount(1));
}
}
21 changes: 21 additions & 0 deletions src/main/java/mc/duzo/timeless/suit/api/SimpleSuitMaterial.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package mc.duzo.timeless.suit.api;

import mc.duzo.timeless.core.items.SuitMaterial;
import net.minecraft.item.ArmorItem;
import net.minecraft.item.Item;
import net.minecraft.recipe.Ingredient;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Util;

import java.util.EnumMap;

public class SimpleSuitMaterial extends SuitMaterial {
public SimpleSuitMaterial(Item repair, String name) {
super(name, 33, Util.make(new EnumMap(ArmorItem.Type.class), map -> {
map.put(ArmorItem.Type.BOOTS, 3);
map.put(ArmorItem.Type.LEGGINGS, 6);
map.put(ArmorItem.Type.CHESTPLATE, 8);
map.put(ArmorItem.Type.HELMET, 3);
}), 10, SoundEvents.ITEM_ARMOR_EQUIP_CHAIN, 2.0F, 0.0F, () -> Ingredient.ofItems(repair));
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package mc.duzo.timeless.suit.client.render;

import mc.duzo.animation.generic.AnimationInfo;
import mc.duzo.animation.generic.VisiblePart;
import mc.duzo.timeless.suit.client.ClientSuit;
import mc.duzo.timeless.suit.client.animation.SuitAnimationHolder;
import mc.duzo.timeless.suit.client.animation.SuitAnimationTracker;
Expand All @@ -26,6 +27,12 @@ public abstract class SuitModel extends EntityModel<LivingEntity> {
public abstract void render(LivingEntity entity, float tickDelta, MatrixStack matrices, VertexConsumer vertexConsumers, int light, float r, float g, float b, float alpha);
public abstract void renderArm(boolean isRight, AbstractClientPlayerEntity player, int i, MatrixStack matrices, VertexConsumer buffer, int light, int i1, int i2, int i3, int i4);

public boolean shouldRenderOriginalArm(boolean isRight, AbstractClientPlayerEntity player) {
VisiblePart requiredPart = isRight ? VisiblePart.RIGHT_ARM : VisiblePart.LEFT_ARM;

return this.getSuit().getVisibleParts(player).contains(requiredPart);
}

/**
* Sets the visibility of the model parts for the given slot.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,21 +80,26 @@ public void render(LivingEntity entity, float tickDelta, MatrixStack matrices, V
}
}

float factor = 1.01f;
matrices.scale(factor, factor, factor);
matrices.translate(0.0F, 1 - factor, 1 - factor);

this.getPart().render(matrices, vertexConsumers, light, OverlayTexture.DEFAULT_UV, r, g, b, alpha);
matrices.pop();
}

@Override
public void renderArm(boolean isRight, AbstractClientPlayerEntity player, int i, MatrixStack matrices, VertexConsumer buffer, int light, int i1, int i2, int i3, int i4) {
if (isRight) this.renderRightArm(player, i, matrices, buffer, light, i1, i2, i3, i4);
if (isRight) this.renderRightArm(player, i, matrices, buffer, light, i1, i2, i3, i4);
else this.renderLeftArm(player, i, matrices, buffer, light, i1, i2, i3, i4);
}

private void renderRightArm(AbstractClientPlayerEntity player, int i, MatrixStack matrices, VertexConsumer buffer, int light, int i1, int i2, int i3, int i4) {
matrices.push();

this.rightArm.resetTransform();
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(-0.5f));
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(5f));
matrices.translate(0.015F, -0.015F, -0.055F);
this.rightArm.render(matrices, buffer, light, OverlayTexture.DEFAULT_UV, 1f, 1f, 1f, 1f);

matrices.pop();
Expand All @@ -104,6 +109,8 @@ private void renderLeftArm(AbstractClientPlayerEntity player, int i, MatrixStack
matrices.push();

this.leftArm.resetTransform();
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(-5f));
matrices.translate(0.015F, -0.015F, -0.055F);
this.leftArm.render(matrices, buffer, light, OverlayTexture.DEFAULT_UV, 1f, 1f, 1f, 1f);

matrices.pop();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,10 @@ public void render(LivingEntity entity, float tickDelta, MatrixStack matrices, V
}
}

float factor = 1.01f;
matrices.scale(factor, factor, factor);
matrices.translate(0.0F, 1 - factor, 1 - factor);

this.getPart().render(matrices, vertexConsumers, light, OverlayTexture.DEFAULT_UV, r, g, b, alpha);
matrices.pop();
}
Expand All @@ -94,7 +98,8 @@ private void renderRightArm(AbstractClientPlayerEntity player, int i, MatrixStac
matrices.push();

this.rightArm.resetTransform();
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(-0.5f));
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(5f));
matrices.translate(0.015F, -0.015F, -0.055F);
this.rightArm.render(matrices, buffer, light, OverlayTexture.DEFAULT_UV, 1f, 1f, 1f, 1f);

matrices.pop();
Expand All @@ -104,6 +109,8 @@ private void renderLeftArm(AbstractClientPlayerEntity player, int i, MatrixStack
matrices.push();

this.leftArm.resetTransform();
matrices.multiply(RotationAxis.POSITIVE_Z.rotationDegrees(-5f));
matrices.translate(0.015F, -0.015F, -0.055F);
this.leftArm.render(matrices, buffer, light, OverlayTexture.DEFAULT_UV, 1f, 1f, 1f, 1f);

matrices.pop();
Expand Down
Loading
Loading