Skip to content

Commit

Permalink
Very Very MVP Backpack
Browse files Browse the repository at this point in the history
  • Loading branch information
hammy275 committed Apr 29, 2022
1 parent a1795bf commit d8374ac
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 18 deletions.
4 changes: 2 additions & 2 deletions src/main/java/net/blf02/immersivemc/ImmersiveMC.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public class ImmersiveMC {
public static final String MOD_ID = "immersivemc";
public static final Logger LOGGER = LogManager.getLogger(MOD_ID);

public static final String keyCategory = "key.categories." + MOD_ID;
public static final String vrKeyCategory = "key.categories." + MOD_ID + ".vr";
public static KeyBinding SUMMON_BACKPACK = null;

public ImmersiveMC() {
Expand All @@ -46,7 +46,7 @@ public ImmersiveMC() {
protected void clientSetup(FMLClientSetupEvent event) {
// Map to a very obscure key, so it has no conflicts for VR users
SUMMON_BACKPACK = new KeyBinding("key." + MOD_ID + ".backpack", KeyConflictContext.IN_GAME,
InputMappings.Type.KEYSYM, GLFW.GLFW_KEY_F23, keyCategory);
InputMappings.Type.KEYSYM, GLFW.GLFW_KEY_F23, vrKeyCategory);
event.enqueueWork(() -> {
MinecraftForge.EVENT_BUS.register(new ClientLogicSubscriber());
MinecraftForge.EVENT_BUS.register(new ClientRenderSubscriber());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public BackpackImmersive() {
@Override
public void tick(BackpackInfo info, boolean isInVR) {
super.tick(info, isInVR);
int controllerNum = 1; // TODO: Replace with config key lookup
int controllerNum = 1;
IVRData backpackController = VRPlugin.API.getVRPlayer(Minecraft.getInstance().player).getController(controllerNum);
IVRData handController = VRPlugin.API.getVRPlayer(Minecraft.getInstance().player).getController(controllerNum == 1 ? 0 : 1);
info.handPos = backpackController.position();
Expand All @@ -44,23 +44,30 @@ public void tick(BackpackInfo info, boolean isInVR) {

// Render backpack closer to the player, and attached to the inner-side of the arm
info.backVec = info.lookVec.normalize().multiply(-1, -1, -1);
info.renderPos = info.handPos.add(0, -0.675, 0);
info.renderPos = info.handPos.add(0, -0.75, 0);
info.renderPos = info.renderPos.add(info.backVec.multiply(1d/6d, 1d/6d, 1d/6d));

info.rgb = new Vector3f(ActiveConfig.backpackColor >> 16, ActiveConfig.backpackColor >> 8 & 255,
ActiveConfig.backpackColor & 255);
info.rgb.mul(1f/255f);


info.centerTopPos = info.handPos;
info.centerTopPos = info.handPos.add(0, -0.15, 0);
info.centerTopPos = info.centerTopPos.add(info.backVec.multiply(1d/6d, 1d/6d, 1d/6d)); // Back on arm
Vector3d rightVec = info.lookVec.multiply(1E8D, 0, 1E8D).normalize();
rightVec = new Vector3d(-rightVec.z, 0, rightVec.x).multiply(0.25, 0, 0.25);
if (ActiveConfig.leftHandedBackpack) {
rightVec = new Vector3d(rightVec.z, 0, -rightVec.x).multiply(0.25, 0, 0.25);
} else {
rightVec = new Vector3d(-rightVec.z, 0, rightVec.x).multiply(0.25, 0, 0.25);
}
info.centerTopPos = info.centerTopPos.add(rightVec);


Vector3d leftVec = rightVec.multiply(-1, 0, -1);

// Note: rightVec and leftVec refer to the vectors for right-handed people. Swap the names if referring to
// left-handed guys, gals, and non-binary pals.

// Item hitboxes and positions
Vector3d leftOffset = new Vector3d(
leftVec.x * spacing, leftVec.y * spacing, leftVec.z * spacing);
Expand Down Expand Up @@ -158,8 +165,7 @@ protected void render(BackpackInfo info, MatrixStack stack, boolean isInVR) {
stack.translate(0, -1.5, 0); // Move back to where we started

// Basically move the model to the side of the origin
// TODO: Move the other way when attached to the other controller
stack.translate(0.5, 0, 0);
stack.translate(ActiveConfig.leftHandedBackpack ? -0.5 : 0.5, 0, 0);

// Render the model (finally!)
model.renderToBuffer(stack,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.blf02.immersivemc.ImmersiveMC;
import net.minecraft.client.renderer.entity.model.EntityModel;
import net.minecraft.client.renderer.model.ModelRenderer;
import net.minecraft.entity.Entity;
Expand All @@ -11,8 +10,7 @@
// 99% exported from BlockBench
public class BackpackModel extends EntityModel<Entity> {

public static final ResourceLocation textureLocation = new ResourceLocation(ImmersiveMC.MOD_ID,
"backpack.png");
public static final ResourceLocation textureLocation = new ResourceLocation("textures/block/white_wool.png");

private final ModelRenderer wall;
private final ModelRenderer lower;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public class ActiveConfig {

// Non-synced values
public static int backpackColor = 11901820;
public static boolean leftHandedBackpack = false;

public static void loadConfigFromPacket(PacketBuffer buffer) {
int serverNetworkVersion = buffer.readInt();
Expand Down Expand Up @@ -69,6 +70,7 @@ public static void loadConfigFromFile() {

// Non-synced values
backpackColor = ImmersiveMCConfig.backpackColor.get();
leftHandedBackpack = ImmersiveMCConfig.leftHandedBackpack.get();
ImmersiveMC.LOGGER.debug("Loaded config from file: \n" + asString());
}

Expand Down Expand Up @@ -101,7 +103,8 @@ public static String asString() {
"Use campfire immersion: " + useCampfireImmersion + "\n" +
"Use lever: " + useLever + "\n" +
"Use backpack: " + useBackpack + "\n" +
"Backpack color: " + backpackColor;
"Backpack color: " + backpackColor + "\n" +
"Left handed backpack: " + leftHandedBackpack;
return stringOut;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,10 @@ public class ImmersiveMCConfig {
public static ForgeConfigSpec.BooleanValue useCampfireImmersion;
public static ForgeConfigSpec.BooleanValue useLever;
public static ForgeConfigSpec.BooleanValue useBackpack;
public static ForgeConfigSpec.IntValue backpackColor;

//Non-synced values
public static ForgeConfigSpec.IntValue backpackColor;
public static ForgeConfigSpec.BooleanValue leftHandedBackpack;

static {
ForgeConfigSpec.Builder configBuilder = new ForgeConfigSpec.Builder();
Expand Down Expand Up @@ -69,13 +70,16 @@ protected static void setupConfig(ForgeConfigSpec.Builder builder) {
.comment("Whether VR users can physically toggle levers")
.define("lever_immersion", true);
useBackpack = builder
.comment("Allow VR players to use a backpack to manage their inventory")
.define("backpack_inventory", true);
.comment("Allow VR players to use a bag to manage their inventory")
.define("bag_inventory", true);

// Non-synced Values
backpackColor = builder
.comment("Color for backpack as a base-10 RGB number.")
.defineInRange("backpack_color", 11901820, 0, 0xFFFFFF);
.comment("Color for the bag as a base-10 RGB number.")
.defineInRange("bag_color", 11901820, 0, 0xFFFFFF);
leftHandedBackpack = builder
.comment("Puts the bag on the other side of your arm. Set to true if you're left-handed.")
.define("left_handed_bag", false);
}

public static void encode(PacketBuffer buffer) {
Expand Down
Binary file removed src/main/resources/assets/immersivemc/backpack.png
Binary file not shown.
3 changes: 2 additions & 1 deletion src/main/resources/assets/immersivemc/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"key.immersivemc.backpack": "Open/Close Backpack"
"key.categories.immersivemc.vr": "ImmersiveMC VR Bindings",
"key.immersivemc.backpack": "Open/Close Bag"
}

0 comments on commit d8374ac

Please sign in to comment.