Skip to content

Commit

Permalink
Better Particle Guides
Browse files Browse the repository at this point in the history
  • Loading branch information
hammy275 committed Jun 19, 2022
1 parent 255dbca commit e3c5cc5
Show file tree
Hide file tree
Showing 23 changed files with 117 additions and 50 deletions.
1 change: 1 addition & 0 deletions model/ASingleCube.bbmodel
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"meta":{"format_version":"4.0","creation_time":1655654437,"model_format":"modded_entity","box_uv":true},"name":"custom_model","geometry_name":"","modded_entity_version":"1.15_mojmaps","visible_box":[1,1,0],"variable_placeholders":"","variable_placeholder_buttons":[],"resolution":{"width":16,"height":16},"elements":[{"name":"head","rescale":false,"locked":false,"from":[-1,0,-1],"to":[1,2,1],"autouv":0,"color":0,"origin":[0,0,0],"faces":{"north":{"uv":[2,2,4,4],"texture":0},"east":{"uv":[0,2,2,4],"texture":0},"south":{"uv":[6,2,8,4],"texture":0},"west":{"uv":[4,2,6,4],"texture":0},"up":{"uv":[4,2,2,0],"texture":0},"down":{"uv":[6,0,4,2],"texture":0}},"type":"cube","uuid":"77bb293a-b53e-ea59-a080-52e385f7f082"}],"outliner":["77bb293a-b53e-ea59-a080-52e385f7f082"],"textures":[{"path":"C:\\Users\\hammy3502\\Desktop\\Forge\\immersive-mc\\src\\main\\resources\\assets\\immersivemc\\cube.png","name":"cube.png","folder":"block","namespace":"","id":"0","particle":false,"render_mode":"default","visible":true,"mode":"bitmap","saved":false,"uuid":"6d262a4e-d3e6-24fa-d0f7-560c704d2ae2","source":"data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABAAAAAQCAYAAAAf8/9hAAAAAXNSR0IArs4c6QAAAD5JREFUOE9jZICC/////4exQTQjIyMjMh8XG66IbAPQNaLbRMgljBQbQIw/8akhKqBGDcAfzKOByMAw8GEAAKh+EBHhoURsAAAAAElFTkSuQmCC","relative_path":"../../src/main/resources/assets/immersivemc/cube.png"}]}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import net.blf02.immersivemc.client.config.ClientConstants;
import net.blf02.immersivemc.client.immersive.info.AbstractImmersiveInfo;
import net.blf02.immersivemc.client.immersive.info.InfoTriggerHitboxes;
import net.blf02.immersivemc.client.model.Cube1x1;
import net.blf02.immersivemc.common.config.ActiveConfig;
import net.blf02.immersivemc.common.vr.VRPlugin;
import net.blf02.immersivemc.common.vr.VRPluginVerify;
Expand Down Expand Up @@ -39,6 +40,7 @@ public abstract class AbstractImmersive<I extends AbstractImmersiveInfo> {

protected final List<I> infos;
public final int maxImmersives;
protected static final Cube1x1 cubeModel = new Cube1x1();

public AbstractImmersive(int maxImmersives) {
Immersives.IMMERSIVES.add(this);
Expand Down Expand Up @@ -114,10 +116,10 @@ public int getCooldownDesktop() {

protected void doTick(I info, boolean isInVR) {
// Set the cooldown (transition time) based on how long we've existed or until we stop existing
if (info.getCountdown() > 1 && info.getTicksLeft() > 20) {
info.changeCountdown(-1);
} else if (info.getCountdown() < ClientConstants.transitionTime && info.getTicksLeft() <= 20) {
info.changeCountdown(1);
if (info.getItemTransitionCountdown() > 1 && info.getTicksLeft() > 20) {
info.changeItemTransitionCountdown(-1);
} else if (info.getItemTransitionCountdown() < ClientConstants.transitionTime && info.getTicksLeft() <= 20) {
info.changeItemTransitionCountdown(1);
}

if (info.getTicksLeft() > 0) {
Expand All @@ -143,8 +145,11 @@ public void doRender(I info, MatrixStack stack, boolean isInVR) {
for (int i = 0; i < info.getInputSlots().length; i++) {
if (slotShouldRenderHelpHitbox(info, i)) {
AxisAlignedBB itemBox = info.getInputSlots()[i];
AxisAlignedBB toShow = itemBox.deflate(itemBox.getSize() / 4);
renderItemGuide(stack, toShow);
AxisAlignedBB toShow = itemBox
.move(0, itemBox.getYsize() / 2, 0);
renderItemGuide(stack, toShow,
Math.min(0.2f, (info.ticksSinceLastClick - 100) * 0.05f));
// Alpha value starts at 0.05f and climbs up to 0.2f
}
}
}
Expand Down Expand Up @@ -258,8 +263,20 @@ public void renderItem(ItemStack item, MatrixStack stack, Vector3d pos, float si
renderHitbox(stack, hitbox, pos);
}

protected void renderItemGuide(MatrixStack stack, AxisAlignedBB hitbox) {
renderHitbox(stack, hitbox, hitbox.getCenter(), true, 0, 1, 1);
protected void renderItemGuide(MatrixStack stack, AxisAlignedBB hitbox, float alpha) {
if (hitbox != null) {
ActiveRenderInfo renderInfo = Minecraft.getInstance().gameRenderer.getMainCamera();
Vector3d pos = hitbox.getCenter();
stack.pushPose();
stack.translate(-renderInfo.getPosition().x + pos.x,
-renderInfo.getPosition().y + pos.y,
-renderInfo.getPosition().z + pos.z);
IRenderTypeBuffer.Impl buffer = Minecraft.getInstance().renderBuffers().bufferSource();
cubeModel.render(stack, buffer.getBuffer(RenderType.entityTranslucent(Cube1x1.textureLocation)),
0, 1, 1, alpha, (float) (hitbox.getSize() / 2f));
stack.popPose();
buffer.endBatch();
}
}

protected void renderHitbox(MatrixStack stack, AxisAlignedBB hitbox, Vector3d pos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public boolean shouldRender(BackpackInfo info, boolean isInVR) {
@Override
protected void render(BackpackInfo info, MatrixStack stack, boolean isInVR) {
for (int i = 0; i <= 31; i++) {
AxisAlignedBB hitbox = info.getHibtox(i);
AxisAlignedBB hitbox = info.getHitbox(i);
renderHitbox(stack, hitbox, info.getPosition(i));
}

Expand All @@ -214,14 +214,14 @@ protected void render(BackpackInfo info, MatrixStack stack, boolean isInVR) {
if (!item.isEmpty() && info.getPosition(i) != null) {
final float size =
info.slotHovered == i ? ClientConstants.itemScaleSizeBackpackSelected : ClientConstants.itemScaleSizeBackpack;
renderItem(item, stack, info.getPosition(i), size, null, info.getHibtox(i), true);
renderItem(item, stack, info.getPosition(i), size, null, info.getHitbox(i), true);
}
}

for (int i = 27; i <= 31; i++) {
ItemStack item = i == 31 ? info.craftingOutput : info.craftingInput[i - 27];
if (!item.isEmpty() && info.getPosition(i) != null) {
renderItem(item, stack, info.getPosition(i), ClientConstants.itemScaleSizeBackpack, null, info.getHibtox(i), i == 31);
renderItem(item, stack, info.getPosition(i), ClientConstants.itemScaleSizeBackpack, null, info.getHitbox(i), i == 31);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public boolean shouldRender(AnvilInfo info, boolean isInVR) {

@Override
protected void render(AnvilInfo info, MatrixStack stack, boolean isInVR) {
float itemSize = ClientConstants.itemScaleSizeAnvil / info.getCountdown();
float itemSize = ClientConstants.itemScaleSizeAnvil / info.getItemTransitionCountdown();

// Render experience levels needed if we have an experience cost to show
if (info.isReallyAnvil && ClientStorage.anvilCost > 0) {
Expand All @@ -146,7 +146,7 @@ protected void render(AnvilInfo info, MatrixStack stack, boolean isInVR) {
for (int i = 0; i <= 2; i++) {
ItemStack item = info.isReallyAnvil ? ClientStorage.anvilStorage[i] : ClientStorage.smithingStorage[i];
renderItem(item, stack, info.getPosition(i),
itemSize, info.renderDirection, Direction.UP, info.getHibtox(i), false);
itemSize, info.renderDirection, Direction.UP, info.getHitbox(i), false);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,13 @@ protected void doTick(BrewingInfo info, boolean isInVR) {
protected void render(BrewingInfo info, MatrixStack stack, boolean isInVR) {
Direction forward = getForwardFromPlayer(Minecraft.getInstance().player);

float size = ClientConstants.itemScaleSizeBrewing / info.getCountdown();
float size = ClientConstants.itemScaleSizeBrewing / info.getItemTransitionCountdown();

renderItem(info.items[0], stack, info.getPosition(0), size, forward, info.getHibtox(0), false);
renderItem(info.items[1], stack, info.getPosition(1), size, forward, info.getHibtox(1), false);
renderItem(info.items[2], stack, info.getPosition(2), size, forward, info.getHibtox(2), false);
renderItem(info.items[3], stack, info.getPosition(3), size, forward, info.getHibtox(3), true);
renderItem(info.items[4], stack, info.getPosition(4), size, forward, info.getHibtox(4), true);
renderItem(info.items[0], stack, info.getPosition(0), size, forward, info.getHitbox(0), false);
renderItem(info.items[1], stack, info.getPosition(1), size, forward, info.getHitbox(1), false);
renderItem(info.items[2], stack, info.getPosition(2), size, forward, info.getHitbox(2), false);
renderItem(info.items[3], stack, info.getPosition(3), size, forward, info.getHitbox(3), true);
renderItem(info.items[4], stack, info.getPosition(4), size, forward, info.getHitbox(4), true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ protected void doTick(ChestInfo info, boolean isInVR) {

@Override
protected void render(ChestInfo info, MatrixStack stack, boolean isInVR) {
float itemSize = ClientConstants.itemScaleSizeChest / info.getCountdown();
float itemSize = ClientConstants.itemScaleSizeChest / info.getItemTransitionCountdown();
Direction forward = info.forward;

if (info.isOpen) {
Expand All @@ -178,7 +178,7 @@ protected void render(ChestInfo info, MatrixStack stack, boolean isInVR) {
int endTop = startTop + 9;
boolean showCount = i >= startTop && i <= endTop;
renderItem(info.items[i], stack, info.getPosition(i),
itemSize, forward, Direction.UP, info.getHibtox(i), showCount);
itemSize, forward, Direction.UP, info.getHitbox(i), showCount);
}

if (info.other != null) {
Expand All @@ -187,7 +187,7 @@ protected void render(ChestInfo info, MatrixStack stack, boolean isInVR) {
int endTop = startTop + 9 + 27;
boolean showCount = i >= startTop && i <= endTop;
renderItem(info.items[i], stack, info.getPosition(i),
itemSize, forward, Direction.UP, info.getHibtox(i), showCount);
itemSize, forward, Direction.UP, info.getHitbox(i), showCount);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -132,12 +132,12 @@ public void handleTriggerHitboxRightClick(InfoTriggerHitboxes info, PlayerEntity

@Override
protected void render(CraftingInfo info, MatrixStack stack, boolean isInVR) {
float itemSize = ClientConstants.itemScaleSizeCrafting / info.getCountdown();
float itemSize = ClientConstants.itemScaleSizeCrafting / info.getItemTransitionCountdown();
Direction forward = getForwardFromPlayer(Minecraft.getInstance().player);

for (int i = 0; i < 9; i++) {
renderItem(ClientStorage.craftingStorage[i], stack, info.getPosition(i),
itemSize, forward, Direction.UP, info.getHibtox(i), false);
itemSize, forward, Direction.UP, info.getHitbox(i), false);
}
renderItem(ClientStorage.craftingOutput, stack, info.resultPosition,
itemSize * 3, forward, info.resultHitbox, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,7 @@ protected void doTick(EnchantingInfo info, boolean isInVR) {
Vector3d end = player.getEyePosition(1).add(viewVec.x * dist, viewVec.y * dist,
viewVec.z * dist);
Optional<Integer> closest = Util.rayTraceClosest(start, end,
info.getHibtox(1), info.getHibtox(2), info.getHibtox(3));
info.getHitbox(1), info.getHitbox(2), info.getHitbox(3));
closest.ifPresent(targetSlot -> info.lookingAtIndex = targetSlot);
}

Expand All @@ -142,14 +142,14 @@ public boolean shouldRender(EnchantingInfo info, boolean isInVR) {

@Override
protected void render(EnchantingInfo info, MatrixStack stack, boolean isInVR) {
float itemSize = ClientConstants.itemScaleSizeETable / info.getCountdown();
float itemSize = ClientConstants.itemScaleSizeETable / info.getItemTransitionCountdown();

if (!ClientStorage.eTableEnchCopy.isEmpty()) { // If one is active, all are
for (int i = 0; i <= 2; i++) {
ClientStorage.ETableInfo enchInfo =
i == 0 ? ClientStorage.weakInfo : i == 1 ? ClientStorage.midInfo : ClientStorage.strongInfo;
renderItem(ClientStorage.eTableEnchCopy, stack, info.getPosition(i + 1), itemSize,
getForwardFromPlayer(Minecraft.getInstance().player), info.getHibtox(i + 1), false);
getForwardFromPlayer(Minecraft.getInstance().player), info.getHitbox(i + 1), false);
if (info.lookingAtIndex == i) {
if (enchInfo.isPresent()) {
renderText(new StringTextComponent(enchInfo.levelsNeeded + " (" + (i + 1) + ")"),
Expand All @@ -168,7 +168,9 @@ protected void render(EnchantingInfo info, MatrixStack stack, boolean isInVR) {
}
if (!ClientStorage.eTableItem.isEmpty()) {
renderItem(ClientStorage.eTableItem, stack, info.getPosition(0), itemSize,
getForwardFromPlayer(Minecraft.getInstance().player), info.getHibtox(0), false);
getForwardFromPlayer(Minecraft.getInstance().player), info.getHitbox(0), false);
} else {
renderHitbox(stack, info.getHitbox(0), info.getPosition(0));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,15 @@ protected void doTick(ImmersiveFurnaceInfo info, boolean isInVR) {
}

protected void render(ImmersiveFurnaceInfo info, MatrixStack stack, boolean isInVR) {
float size = ClientConstants.itemScaleSizeFurnace / info.getCountdown();
float size = ClientConstants.itemScaleSizeFurnace / info.getItemTransitionCountdown();

// Render all of the items

renderItem(info.items[0], stack, info.getPosition(0), size, info.forward, info.getHibtox(0), true);
renderItem(info.items[1], stack, info.getPosition(1), size, info.forward, info.getHibtox(1), true);
renderItem(info.items[0], stack, info.getPosition(0), size, info.forward, info.getHitbox(0), true);
renderItem(info.items[1], stack, info.getPosition(1), size, info.forward, info.getHitbox(1), true);
if (info.items[2] != null && !info.items[2].isEmpty()) {
// If empty, we don't need to render, AND it might be null because of autoCenterFurnace
renderItem(info.items[2], stack, info.getPosition(2), size, info.forward, info.getHibtox(2), true);
renderItem(info.items[2], stack, info.getPosition(2), size, info.forward, info.getHitbox(2), true);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,12 @@ protected void initInfo(JukeboxInfo info) {

@Override
protected void render(JukeboxInfo info, MatrixStack stack, boolean isInVR) {
renderHitbox(stack, info.getHibtox(0), info.getPosition(0));
renderHitbox(stack, info.getHitbox(0), info.getPosition(0));
}

@Override
protected boolean slotShouldRenderHelpHitbox(JukeboxInfo info, int slotNum) {
return VRPluginVerify.clientInVR;
return false;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,7 @@ public boolean shouldRender(RepeaterInfo info, boolean isInVR) {
@Override
protected void render(RepeaterInfo info, MatrixStack stack, boolean isInVR) {
for (int i = 0; i <= 3; i++) {
renderHitbox(stack, info.getHibtox(i), info.getPosition(i));
renderHitbox(stack, info.getHitbox(i), info.getPosition(i));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
public abstract class AbstractImmersiveInfo {

protected int ticksLeft;
protected int countdown = 10; // Used for transitions for the items
protected int itemTransitionCountdown = 10; // Used for transitions for the items
public int ticksActive = 0;
public boolean initCompleted = false;
protected AxisAlignedBB[] inputHitboxes = null;
Expand Down Expand Up @@ -39,7 +39,7 @@ public void setTicksLeft(int value) {
this.ticksLeft = value;
}

public abstract AxisAlignedBB getHibtox(int slot);
public abstract AxisAlignedBB getHitbox(int slot);

public abstract AxisAlignedBB[] getAllHitboxes();

Expand All @@ -55,12 +55,12 @@ public void setTicksLeft(int value) {

public abstract boolean hasPositions();

public int getCountdown() {
return this.countdown;
public int getItemTransitionCountdown() {
return this.itemTransitionCountdown;
}

public void changeCountdown(int amount) {
this.countdown += amount;
public void changeItemTransitionCountdown(int amount) {
this.itemTransitionCountdown += amount;
}

public abstract boolean readyToRender();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public void setInputSlots() {
}

@Override
public AxisAlignedBB getHibtox(int slot) {
public AxisAlignedBB getHitbox(int slot) {
return hitboxes[slot];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void setInputSlots() {
}

@Override
public AxisAlignedBB getHibtox(int slot) {
public AxisAlignedBB getHitbox(int slot) {
return hitboxes[slot];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void setInputSlots() {
}

@Override
public AxisAlignedBB getHibtox(int slot) {
public AxisAlignedBB getHitbox(int slot) {
if (slot < 0 || slot > 4) {
throw new IllegalArgumentException("Only supports slots 0-4");
} else if (slot < 3) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public void setInputSlots() {
}

@Override
public AxisAlignedBB getHibtox(int slot) {
public AxisAlignedBB getHitbox(int slot) {
return hitboxes[slot];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public void setInputSlots() {
}

@Override
public AxisAlignedBB getHibtox(int slot) {
public AxisAlignedBB getHitbox(int slot) {
return inputs[slot];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public void setInputSlots() {
}

@Override
public AxisAlignedBB getHibtox(int slot) {
public AxisAlignedBB getHitbox(int slot) {
return this.hitboxes[slot];
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public void setInputSlots() {
this.inputHitboxes = new AxisAlignedBB[]{this.toSmeltHitbox, this.fuelHitbox};
}

public AxisAlignedBB getHibtox(int slot) {
public AxisAlignedBB getHitbox(int slot) {
switch (slot) {
case 0:
return toSmeltHitbox;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public void setInputSlots() {
}

@Override
public AxisAlignedBB getHibtox(int slot) {
public AxisAlignedBB getHitbox(int slot) {
return discHitbox;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ public void setInputSlots() {
}

@Override
public AxisAlignedBB getHibtox(int index) {
public AxisAlignedBB getHitbox(int index) {
return hitboxes[index];
}

Expand Down
Loading

0 comments on commit e3c5cc5

Please sign in to comment.