-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Headset, with noise cancelling to block out other loudspeakers - Portable radio which plays radio to the headset - Portable record player which plays discs to the headset
- Loading branch information
1 parent
a7e57d1
commit df1c5de
Showing
40 changed files
with
1,069 additions
and
23 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
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
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
55 changes: 55 additions & 0 deletions
55
src/main/java/io/github/foundationgames/phonos/client/model/HeadsetModel.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,55 @@ | ||
package io.github.foundationgames.phonos.client.model; | ||
|
||
import io.github.foundationgames.phonos.item.HeadsetItem; | ||
import net.minecraft.client.model.ModelPart; | ||
import net.minecraft.client.model.ModelTransform; | ||
import net.minecraft.client.render.RenderLayer; | ||
import net.minecraft.client.render.VertexConsumerProvider; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.item.ItemStack; | ||
|
||
public class HeadsetModel extends BasicModel { | ||
private final ModelPart main; | ||
private final ModelPart innerTube; | ||
private final ModelPart microphone; | ||
|
||
public HeadsetModel(ModelPart root) { | ||
super(root); | ||
|
||
this.main = root.getChild("main"); | ||
this.innerTube = root.getChild("inner_tube"); | ||
this.microphone = root.getChild("microphone"); | ||
} | ||
|
||
public void render(MatrixStack matrices, VertexConsumerProvider buffers, ModelTransform transform, int light, int overlay, ItemStack stack, HeadsetItem item) { | ||
matrices.push(); | ||
this.root.setTransform(transform); | ||
var texture = item.getTexture(stack); | ||
|
||
this.microphone.visible = false; // Todo? | ||
this.main.visible = true; | ||
this.innerTube.visible = false; | ||
|
||
var buffer = buffers.getBuffer(RenderLayer.getEntityCutoutNoCull(texture)); | ||
this.render(matrices, buffer, light, overlay, 1, 1, 1, 1); | ||
|
||
this.main.visible = false; | ||
// this.microphone.visible = false; | ||
this.innerTube.visible = true; | ||
|
||
int color = item.getColor(stack); | ||
float r = ((color >> 16) & 0xFF) / 255f; | ||
float g = ((color >> 8) & 0xFF) / 255f; | ||
float b = (color & 0xFF) / 255f; | ||
|
||
this.render(matrices, buffer, light, overlay, r, g, b, 1); | ||
|
||
if (item.isGlowing(stack)) { | ||
buffer = buffers.getBuffer(RenderLayer.getEyes(texture)); | ||
|
||
this.render(matrices, buffer, light, overlay, r, g, b, 1); | ||
} | ||
|
||
matrices.pop(); | ||
} | ||
} |
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
31 changes: 31 additions & 0 deletions
31
...in/java/io/github/foundationgames/phonos/client/render/entity/HeadsetFeatureRenderer.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,31 @@ | ||
package io.github.foundationgames.phonos.client.render.entity; | ||
|
||
import io.github.foundationgames.phonos.PhonosClient; | ||
import io.github.foundationgames.phonos.client.model.HeadsetModel; | ||
import io.github.foundationgames.phonos.item.HeadsetItem; | ||
import net.minecraft.client.render.OverlayTexture; | ||
import net.minecraft.client.render.VertexConsumerProvider; | ||
import net.minecraft.client.render.entity.feature.FeatureRenderer; | ||
import net.minecraft.client.render.entity.feature.FeatureRendererContext; | ||
import net.minecraft.client.render.entity.model.BipedEntityModel; | ||
import net.minecraft.client.render.entity.model.EntityModelLoader; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.entity.EquipmentSlot; | ||
import net.minecraft.entity.LivingEntity; | ||
|
||
public class HeadsetFeatureRenderer<E extends LivingEntity, M extends BipedEntityModel<E>> extends FeatureRenderer<E, M> { | ||
private final HeadsetModel headsetModel; | ||
|
||
public HeadsetFeatureRenderer(FeatureRendererContext<E, M> context, EntityModelLoader models) { | ||
super(context); | ||
this.headsetModel = new HeadsetModel(models.getModelPart(PhonosClient.HEADSET_LAYER)); | ||
} | ||
|
||
@Override | ||
public void render(MatrixStack matrices, VertexConsumerProvider vertexConsumers, int light, E entity, float limbAngle, float limbDistance, float tickDelta, float animationProgress, float headYaw, float headPitch) { | ||
var headset = entity.getEquippedStack(EquipmentSlot.HEAD); | ||
if (headset.getItem() instanceof HeadsetItem item) { | ||
this.headsetModel.render(matrices, vertexConsumers, this.getContextModel().getHead().getTransform(), light, OverlayTexture.DEFAULT_UV, headset, item); | ||
} | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/io/github/foundationgames/phonos/item/GlowableItem.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,14 @@ | ||
package io.github.foundationgames.phonos.item; | ||
|
||
import net.minecraft.item.ItemStack; | ||
|
||
public interface GlowableItem { | ||
default void setGlowing(ItemStack stack, boolean glowing) { | ||
stack.getOrCreateSubNbt("display").putBoolean("glowing", glowing); | ||
} | ||
|
||
default boolean isGlowing(ItemStack stack) { | ||
var display = stack.getSubNbt("display"); | ||
return display != null && display.contains("glowing") && display.getBoolean("glowing"); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
src/main/java/io/github/foundationgames/phonos/item/HeadsetItem.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,76 @@ | ||
package io.github.foundationgames.phonos.item; | ||
|
||
import io.github.foundationgames.phonos.Phonos; | ||
import net.minecraft.client.item.TooltipContext; | ||
import net.minecraft.entity.EquipmentSlot; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.inventory.StackReference; | ||
import net.minecraft.item.DyeableItem; | ||
import net.minecraft.item.Equipment; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.screen.slot.Slot; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.*; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.List; | ||
|
||
public class HeadsetItem extends Item implements DyeableItem, GlowableItem, Equipment { | ||
public static final Text NOISE_CANCELLING = Text.translatable("tooltip.phonos.item.noise_cancelling").formatted(Formatting.YELLOW); | ||
public static final Text GLOWING = Text.translatable("tooltip.phonos.item.glowing").formatted(Formatting.GRAY, Formatting.ITALIC); | ||
|
||
public static final Identifier DEFAULT_TEXTURE = Phonos.id("textures/entity/headset.png"); | ||
public static final Identifier NOISE_CANCELLING_TEXTURE = Phonos.id("textures/entity/headset_noise_cancelling.png"); | ||
|
||
public HeadsetItem(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) { | ||
return this.equipAndSwap(this, world, user, hand); | ||
} | ||
|
||
public boolean isNoiseCancelling(ItemStack stack) { | ||
return stack.hasNbt() && stack.getNbt().getBoolean("noise_cancelling"); | ||
} | ||
|
||
public void setNoiseCancelling(ItemStack stack, boolean noiseCancelling) { | ||
stack.getOrCreateNbt().putBoolean("noise_cancelling", noiseCancelling); | ||
} | ||
|
||
@Override | ||
public boolean onClicked(ItemStack stack, ItemStack otherStack, Slot slot, ClickType clickType, PlayerEntity player, StackReference cursorStackReference) { | ||
if (clickType == ClickType.RIGHT && otherStack.isEmpty()) { | ||
setNoiseCancelling(stack, !isNoiseCancelling(stack)); | ||
|
||
return true; | ||
} | ||
|
||
return super.onClicked(stack, otherStack, slot, clickType, player, cursorStackReference); | ||
} | ||
|
||
@Override | ||
public EquipmentSlot getSlotType() { | ||
return EquipmentSlot.HEAD; | ||
} | ||
|
||
@Override | ||
public void appendTooltip(ItemStack stack, @Nullable World world, List<Text> tooltip, TooltipContext context) { | ||
super.appendTooltip(stack, world, tooltip, context); | ||
|
||
if (isNoiseCancelling(stack)) { | ||
tooltip.add(NOISE_CANCELLING); | ||
} | ||
|
||
if (isGlowing(stack)) { | ||
tooltip.add(GLOWING); | ||
} | ||
} | ||
|
||
public Identifier getTexture(ItemStack stack) { | ||
return isNoiseCancelling(stack) ? NOISE_CANCELLING_TEXTURE : DEFAULT_TEXTURE; | ||
} | ||
} |
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
Oops, something went wrong.