Skip to content

Commit

Permalink
高亮光剑
Browse files Browse the repository at this point in the history
  • Loading branch information
EDGtheXu committed Oct 10, 2024
1 parent da6123c commit 4fd60c9
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -1,14 +1,15 @@
package org.confluence.mod.client.model.item;

import net.minecraft.client.renderer.RenderType;
import net.minecraft.resources.ResourceLocation;
import org.confluence.mod.Confluence;
import org.confluence.mod.item.sword.LightSaber;
import software.bernie.geckolib.model.GeoModel;

public class LightSaberModel extends GeoModel<LightSaber> {
public static final ResourceLocation barModel = Confluence.asResource("geo/item/light_saber_bar.geo.json");
private static final ResourceLocation model = Confluence.asResource("geo/item/light_saber.geo.json");
private final ResourceLocation texture;
public static final ResourceLocation model = Confluence.asResource("geo/item/light_saber.geo.json");
public final ResourceLocation texture;
private static final ResourceLocation animation = Confluence.asResource("animations/item/light_saber.animation.json");

public LightSaberModel(String color) {
Expand All @@ -29,4 +30,6 @@ public ResourceLocation getTextureResource(LightSaber animatable) {
public ResourceLocation getAnimationResource(LightSaber animatable) {
return animation;
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -14,24 +14,57 @@
import software.bernie.geckolib.renderer.layer.AutoGlowingGeoLayer;

public class LightSaberRenderer extends GeoItemRenderer<LightSaber> {

private boolean isTurningOn = false;
AutoGlowingGeoLayer<LightSaber> autoGlowingGeoLayer = new AutoGlowingGeoLayer<>(this){
@Override
protected RenderType getRenderType(LightSaber animatable) {
animatable.frame++;
//可以修改贴图
//return RenderType.energySwirl(((LightSaberModel)this.getGeoModel()).texture, (float) (Math.sin(frame * 0.01F)/4+Math.sin(frame * 0.02F)/2 + Math.sin(frame * 0.04F))%0.1f, (float) (Math.cos(frame * 0.01F)/4+Math.cos(frame * 0.02F)/2 + Math.cos(frame * 0.04F)));
return RenderType.energySwirl(((LightSaberModel)this.getGeoModel()).texture, 0, (float) (Math.cos(animatable.frame * 0.001F)/4+Math.cos(animatable.frame * 0.002F)/2 + Math.cos(animatable.frame * 0.004F)));

}

@Override
public void render(PoseStack poseStack, LightSaber animatable, BakedGeoModel bakedModel, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, float partialTick, int packedLight, int packedOverlay) {
if(!isTurningOn) return;
super.render(poseStack, animatable, bakedModel, renderType, bufferSource, buffer, partialTick, packedLight, packedOverlay);
}
};
public LightSaberRenderer(String color) {
super(new LightSaberModel(color));
addRenderLayer(new AutoGlowingGeoLayer<>(this));
addRenderLayer(autoGlowingGeoLayer);
}

@Override
public void actuallyRender(PoseStack poseStack, LightSaber animatable, BakedGeoModel model, RenderType renderType, MultiBufferSource bufferSource, VertexConsumer buffer, boolean isReRender, float partialTick, int packedLight, int packedOverlay, float red, float green, float blue, float alpha) {
CompoundTag nbt = getCurrentItemStack().getTag();

isTurningOn = true;
if (nbt != null && nbt.getBoolean("turnOff")) {
isTurningOn = false;
AnimationController<GeoAnimatable> controller = animatable
.getAnimatableInstanceCache()
.getManagerForId(nbt.getLong("GeckoLibID"))
.getAnimationControllers()
.get("light");
if (controller != null && controller.getCurrentRawAnimation() != LightSaber.TURN_OFF) {
model = getGeoModel().getBakedModel(LightSaberModel.barModel);

}
}
/*
poseStack.pushPose();
poseStack.scale(2,2,2);
var bModel = getGeoModel().getBakedModel(LightSaberModel.model);
for (GeoBone group : bModel.topLevelBones()) {
this.renderRecursively(poseStack, animatable, group, barRendertype, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha);
}
poseStack.popPose();
*/
super.actuallyRender(poseStack, animatable, model, renderType, bufferSource, buffer, isReRender, partialTick, packedLight, packedOverlay, red, green, blue, alpha);
}


}
3 changes: 2 additions & 1 deletion src/main/java/org/confluence/mod/item/sword/LightSaber.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import java.util.function.Consumer;

public abstract class LightSaber extends BoardSwordItem implements GeoItem {

public static final RawAnimation TURN_OFF = RawAnimation.begin().thenPlay("turn_off");
private static final ImmutableMultimap<Attribute, AttributeModifier> ON = ImmutableMultimap.of(
Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Weapon modifier", 9, AttributeModifier.Operation.ADDITION),
Expand All @@ -48,7 +49,7 @@ Attributes.ATTACK_DAMAGE, new AttributeModifier(BASE_ATTACK_DAMAGE_UUID, "Weapon
Attributes.ATTACK_SPEED, new AttributeModifier(BASE_ATTACK_SPEED_UUID, "Weapon modifier", -1, AttributeModifier.Operation.ADDITION)
);
private final AnimatableInstanceCache cache = GeckoLibUtil.createInstanceCache(this);

public int frame = 0;
public LightSaber() {
super(new Tier() {
@Override
Expand Down

0 comments on commit 4fd60c9

Please sign in to comment.