gambling 1 - slot machine
This commit is contained in:
149
src/client/java/dev/tggamesyt/szar/client/SlotMachineScreen.java
Normal file
149
src/client/java/dev/tggamesyt/szar/client/SlotMachineScreen.java
Normal file
@@ -0,0 +1,149 @@
|
||||
package dev.tggamesyt.szar.client;
|
||||
|
||||
import com.mojang.blaze3d.systems.RenderSystem;
|
||||
import dev.tggamesyt.szar.SlotMachineBlockEntity;
|
||||
import dev.tggamesyt.szar.SlotMachineScreenHandler;
|
||||
import dev.tggamesyt.szar.Szar;
|
||||
import net.minecraft.client.gui.DrawContext;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.Screen;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreen;
|
||||
import net.minecraft.client.util.math.MatrixStack;
|
||||
import net.minecraft.entity.player.PlayerInventory;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.Items;
|
||||
import net.minecraft.text.Text;
|
||||
import net.minecraft.util.Identifier;
|
||||
import dev.tggamesyt.szar.SlotSymbol;
|
||||
|
||||
public class SlotMachineScreen extends HandledScreen<SlotMachineScreenHandler> {
|
||||
|
||||
private static final Identifier BG_TEXTURE =
|
||||
new Identifier(Szar.MOD_ID, "textures/gui/slot_machine.png");
|
||||
|
||||
private static final Identifier HANDLE_1 =
|
||||
new Identifier(Szar.MOD_ID, "textures/gui/handle1.png");
|
||||
private static final Identifier HANDLE_2 =
|
||||
new Identifier(Szar.MOD_ID, "textures/gui/handle2.png");
|
||||
private static final Identifier HANDLE_3 =
|
||||
new Identifier(Szar.MOD_ID, "textures/gui/handle3.png");
|
||||
|
||||
private final int handleX = 120;
|
||||
private final int handleY = 20;
|
||||
|
||||
private boolean handleClicked = false;
|
||||
private int handleAnimTicks = 0;
|
||||
private Identifier currentHandleTexture = HANDLE_1;
|
||||
|
||||
public SlotMachineScreen(SlotMachineScreenHandler handler,
|
||||
PlayerInventory inventory,
|
||||
Text title) {
|
||||
super(handler, inventory, title);
|
||||
this.backgroundWidth = 176;
|
||||
this.backgroundHeight = 166;
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// BACKGROUND
|
||||
// ----------------------------
|
||||
|
||||
@Override
|
||||
protected void drawBackground(DrawContext context, float delta, int mouseX, int mouseY) {
|
||||
int guiLeft = (width - backgroundWidth) / 2;
|
||||
int guiTop = (height - backgroundHeight) / 2;
|
||||
|
||||
context.drawTexture(BG_TEXTURE, guiLeft, guiTop,
|
||||
0, 0, backgroundWidth, backgroundHeight);
|
||||
|
||||
drawReels(context, guiLeft, guiTop);
|
||||
}
|
||||
|
||||
private void drawReels(DrawContext context, int guiLeft, int guiTop) {
|
||||
|
||||
SlotMachineBlockEntity be = handler.blockEntity;
|
||||
if (be == null) return;
|
||||
|
||||
int reelX = guiLeft + 70;
|
||||
int reelY = guiTop + 35;
|
||||
|
||||
for (int i = 0; i < 3; i++) {
|
||||
|
||||
int idx = be.getSymbol(i);
|
||||
if (idx < 0 || idx >= SlotSymbol.values().length)
|
||||
idx = 0;
|
||||
|
||||
SlotSymbol symbol = SlotSymbol.values()[idx];
|
||||
ItemStack stack = new ItemStack(symbol.item);
|
||||
|
||||
context.drawItem(stack, reelX + i * 18, reelY);
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// RENDER
|
||||
// ----------------------------
|
||||
|
||||
@Override
|
||||
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
|
||||
|
||||
renderBackground(context);
|
||||
super.render(context, mouseX, mouseY, delta);
|
||||
if (client != null && client.player != null) {
|
||||
handler.tick(client.player);
|
||||
}
|
||||
drawMouseoverTooltip(context, mouseX, mouseY);
|
||||
|
||||
int guiLeft = (width - backgroundWidth) / 2;
|
||||
int guiTop = (height - backgroundHeight) / 2;
|
||||
|
||||
// Handle animation
|
||||
if (handleClicked) {
|
||||
handleAnimTicks++;
|
||||
|
||||
if (handleAnimTicks < 5) {
|
||||
currentHandleTexture = HANDLE_2;
|
||||
} else if (handleAnimTicks < 10) {
|
||||
currentHandleTexture = HANDLE_3;
|
||||
} else {
|
||||
currentHandleTexture = HANDLE_1;
|
||||
handleClicked = false;
|
||||
handleAnimTicks = 0;
|
||||
|
||||
// CALL SCREEN HANDLER LOGIC HERE
|
||||
if (client != null && client.player != null && client.interactionManager != null) {
|
||||
client.interactionManager.clickButton(handler.syncId, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Draw handle
|
||||
context.drawTexture(currentHandleTexture,
|
||||
guiLeft + handleX,
|
||||
guiTop + handleY,
|
||||
0, 0,
|
||||
32, 32,
|
||||
32, 32);
|
||||
}
|
||||
|
||||
// ----------------------------
|
||||
// MOUSE
|
||||
// ----------------------------
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked(double mouseX, double mouseY, int button) {
|
||||
|
||||
int guiLeft = (width - backgroundWidth) / 2;
|
||||
int guiTop = (height - backgroundHeight) / 2;
|
||||
|
||||
double relX = mouseX - (guiLeft + handleX);
|
||||
double relY = mouseY - (guiTop + handleY);
|
||||
|
||||
if (relX >= 0 && relX <= 32 && relY >= 0 && relY <= 32) {
|
||||
handleClicked = true;
|
||||
handleAnimTicks = 0;
|
||||
return true;
|
||||
}
|
||||
|
||||
return super.mouseClicked(mouseX, mouseY, button);
|
||||
}
|
||||
}
|
||||
@@ -9,12 +9,15 @@ import net.fabricmc.fabric.api.client.command.v2.ClientCommandRegistrationCallba
|
||||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents;
|
||||
import net.fabricmc.fabric.api.client.model.ModelLoadingRegistry;
|
||||
import net.fabricmc.fabric.api.client.networking.v1.ClientPlayNetworking;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.BlockEntityRendererRegistry;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.EntityModelLayerRegistry;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.EntityRendererRegistry;
|
||||
import net.fabricmc.fabric.api.client.rendering.v1.HudRenderCallback;
|
||||
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry;
|
||||
import net.fabricmc.fabric.api.networking.v1.PacketByteBufs;
|
||||
import net.fabricmc.fabric.api.object.builder.v1.client.model.FabricModelPredicateProviderRegistry;
|
||||
import net.minecraft.client.MinecraftClient;
|
||||
import net.minecraft.client.gui.screen.ingame.HandledScreens;
|
||||
import net.minecraft.client.option.KeyBinding;
|
||||
import net.minecraft.client.render.entity.FlyingItemEntityRenderer;
|
||||
import net.minecraft.client.render.entity.animation.Animation;
|
||||
@@ -86,6 +89,7 @@ public class SzarClient implements ClientModInitializer {
|
||||
});
|
||||
ThirdpersonModelRegisterer.register(new Identifier(MOD_ID, "weed_joint"), new Identifier(MOD_ID, "weed_joint_in_hand"));
|
||||
ThirdpersonModelRegisterer.register(new Identifier(MOD_ID, "fasz"), new Identifier(MOD_ID, "fasz_in_hand"));
|
||||
ThirdpersonModelRegisterer.register(new Identifier(MOD_ID, "slot_machine"), new Identifier(MOD_ID, "slot_machine_3d"));
|
||||
ClientTickEvents.END_CLIENT_TICK.register(client -> {
|
||||
if (client.player == null) return;
|
||||
|
||||
@@ -224,6 +228,12 @@ public class SzarClient implements ClientModInitializer {
|
||||
});
|
||||
}
|
||||
);
|
||||
/*BlockEntityRendererRegistry.register(
|
||||
SLOT_MACHINE_BLOCKENTITY,
|
||||
SlotMachineRenderer::new
|
||||
);*/
|
||||
HandledScreens.register(Szar.SLOT_MACHINE_SCREEN_HANDLER_TYPE, SlotMachineScreen::new);
|
||||
|
||||
EntityRendererRegistry.register(
|
||||
Szar.NiggerEntityType,
|
||||
NiggerEntityRenderer::new
|
||||
|
||||
Reference in New Issue
Block a user