-
-
Notifications
You must be signed in to change notification settings - Fork 74
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
164 additions
and
32 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
29 changes: 29 additions & 0 deletions
29
src/main/java/de/srendi/advancedperipherals/client/smartglasses/objects/ItemRenderer.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,29 @@ | ||
package de.srendi.advancedperipherals.client.smartglasses.objects; | ||
|
||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.ItemObject; | ||
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects.RenderableObject; | ||
import de.srendi.advancedperipherals.common.util.inventory.ItemUtil; | ||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.world.item.Item; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraftforge.client.gui.overlay.ForgeGui; | ||
import net.minecraftforge.registries.ForgeRegistries; | ||
|
||
import java.util.List; | ||
|
||
public class ItemRenderer implements IObjectRenderer { | ||
|
||
@Override | ||
public void renderBatch(List<RenderableObject> objects, ForgeGui gui, PoseStack poseStack, float partialTick, int screenWidth, int screenHeight) { | ||
Minecraft minecraft = Minecraft.getInstance(); | ||
|
||
for (RenderableObject object : objects) { | ||
Item renderItem = ItemUtil.getRegistryEntry(((ItemObject) object).item, ForgeRegistries.ITEMS); | ||
if (renderItem == null) | ||
continue; | ||
minecraft.getItemRenderer().renderGuiItem(new ItemStack(renderItem), object.x, object.y); | ||
} | ||
|
||
} | ||
} |
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
93 changes: 93 additions & 0 deletions
93
...de/srendi/advancedperipherals/common/smartglasses/modules/overlay/objects/ItemObject.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,93 @@ | ||
package de.srendi.advancedperipherals.common.smartglasses.modules.overlay.objects; | ||
|
||
import dan200.computercraft.api.lua.IArguments; | ||
import dan200.computercraft.api.lua.LuaException; | ||
import de.srendi.advancedperipherals.AdvancedPeripherals; | ||
import de.srendi.advancedperipherals.client.smartglasses.objects.IObjectRenderer; | ||
import de.srendi.advancedperipherals.client.smartglasses.objects.ItemRenderer; | ||
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.OverlayModule; | ||
import de.srendi.advancedperipherals.common.smartglasses.modules.overlay.propertytypes.StringProperty; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
|
||
import java.util.UUID; | ||
|
||
public class ItemObject extends RenderableObject { | ||
public static final int TYPE_ID = 3; | ||
|
||
private final IObjectRenderer renderer = new ItemRenderer(); | ||
|
||
@StringProperty | ||
public String item = "minecraft:air"; | ||
|
||
public ItemObject(OverlayModule module, IArguments arguments) throws LuaException { | ||
super(module, arguments); | ||
reflectivelyMapProperties(arguments); | ||
} | ||
|
||
public ItemObject(UUID player) { | ||
super(player); | ||
} | ||
|
||
public void setItem(String item) { | ||
this.item = item; | ||
} | ||
|
||
public String getItem() { | ||
return item; | ||
} | ||
|
||
@Override | ||
public void encode(FriendlyByteBuf buffer) { | ||
buffer.writeInt(TYPE_ID); | ||
super.encode(buffer); | ||
buffer.writeUtf(item); | ||
} | ||
|
||
public static ItemObject decode(FriendlyByteBuf buffer) { | ||
int objectId = buffer.readInt(); | ||
boolean hasValidUUID = buffer.readBoolean(); | ||
if (!hasValidUUID) { | ||
AdvancedPeripherals.exception("Tried to decode a buffer for an OverlayObject but without a valid player as target.", new IllegalArgumentException()); | ||
return null; | ||
} | ||
UUID player = buffer.readUUID(); | ||
int color = buffer.readInt(); | ||
float opacity = buffer.readFloat(); | ||
|
||
int x = buffer.readInt(); | ||
int y = buffer.readInt(); | ||
int maxX = buffer.readInt(); | ||
int maxY = buffer.readInt(); | ||
String item = buffer.readUtf(); | ||
|
||
ItemObject clientObject = new ItemObject(player); | ||
clientObject.setId(objectId); | ||
clientObject.color = color; | ||
clientObject.opacity = opacity; | ||
clientObject.x = x; | ||
clientObject.y = y; | ||
clientObject.maxX = maxX; | ||
clientObject.maxY = maxY; | ||
clientObject.item = item; | ||
|
||
return clientObject; | ||
} | ||
|
||
@Override | ||
public IObjectRenderer getRenderObject() { | ||
return renderer; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ItemObject{" + | ||
"item='" + item + '\'' + | ||
", opacity=" + opacity + | ||
", color=" + color + | ||
", x=" + x + | ||
", y=" + y + | ||
", maxX=" + maxX + | ||
", maxY=" + maxY + | ||
'}'; | ||
} | ||
} |
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