2019-09-03 08:34:02 +02:00
|
|
|
package com.simibubi.create;
|
|
|
|
|
2019-09-14 18:21:30 +02:00
|
|
|
import java.util.ArrayList;
|
|
|
|
import java.util.List;
|
|
|
|
|
2019-09-07 13:12:12 +02:00
|
|
|
import com.simibubi.create.foundation.block.IBlockWithScrollableValue;
|
2019-09-03 08:34:02 +02:00
|
|
|
import com.simibubi.create.foundation.gui.ScreenOpener;
|
2019-09-14 18:21:30 +02:00
|
|
|
import com.simibubi.create.foundation.utility.TooltipHelper;
|
2019-09-03 08:34:02 +02:00
|
|
|
import com.simibubi.create.modules.contraptions.receivers.TurntableHandler;
|
|
|
|
import com.simibubi.create.modules.contraptions.relays.belt.BeltItemHandler;
|
|
|
|
|
|
|
|
import net.minecraft.client.Minecraft;
|
2019-09-14 18:21:30 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
|
|
|
import net.minecraft.util.text.ITextComponent;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.api.distmarker.Dist;
|
|
|
|
import net.minecraftforge.client.event.InputEvent.KeyInputEvent;
|
|
|
|
import net.minecraftforge.client.event.InputEvent.MouseInputEvent;
|
2019-09-03 23:03:52 +02:00
|
|
|
import net.minecraftforge.client.event.InputEvent.MouseScrollEvent;
|
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
|
2019-09-03 23:03:52 +02:00
|
|
|
import net.minecraftforge.client.event.RenderWorldLastEvent;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.event.TickEvent.ClientTickEvent;
|
|
|
|
import net.minecraftforge.event.TickEvent.Phase;
|
|
|
|
import net.minecraftforge.event.TickEvent.RenderTickEvent;
|
2019-09-14 18:21:30 +02:00
|
|
|
import net.minecraftforge.event.entity.player.ItemTooltipEvent;
|
2019-09-03 08:34:02 +02:00
|
|
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
|
|
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
|
|
|
|
|
|
|
@EventBusSubscriber(value = Dist.CLIENT)
|
|
|
|
public class ClientEvents {
|
|
|
|
|
2019-09-14 18:21:30 +02:00
|
|
|
private static final String itemPrefix = "item." + Create.ID;
|
|
|
|
private static final String blockPrefix = "block." + Create.ID;
|
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onTick(ClientTickEvent event) {
|
|
|
|
if (event.phase == Phase.START)
|
|
|
|
return;
|
|
|
|
if (!isGameActive())
|
|
|
|
return;
|
|
|
|
|
|
|
|
ScreenOpener.tick();
|
|
|
|
onGameTick();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void onGameTick() {
|
|
|
|
CreateClient.gameTick();
|
|
|
|
BeltItemHandler.gameTick();
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onRenderWorld(RenderWorldLastEvent event) {
|
|
|
|
CreateClient.schematicHandler.render();
|
|
|
|
CreateClient.schematicAndQuillHandler.render();
|
|
|
|
CreateClient.schematicHologram.render();
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onRenderOverlay(RenderGameOverlayEvent.Post event) {
|
|
|
|
if (event.getType() != ElementType.HOTBAR)
|
|
|
|
return;
|
|
|
|
|
|
|
|
onRenderHotbar();
|
|
|
|
}
|
|
|
|
|
|
|
|
public static void onRenderHotbar() {
|
|
|
|
CreateClient.schematicHandler.renderOverlay();
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onKeyInput(KeyInputEvent event) {
|
|
|
|
int key = event.getKey();
|
|
|
|
boolean pressed = !(event.getAction() == 0);
|
|
|
|
|
|
|
|
if (Minecraft.getInstance().currentScreen != null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
CreateClient.schematicHandler.onKeyInput(key, pressed);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
2019-09-03 23:03:52 +02:00
|
|
|
public static void onMouseScrolled(MouseScrollEvent event) {
|
|
|
|
if (Minecraft.getInstance().currentScreen != null)
|
2019-09-03 08:34:02 +02:00
|
|
|
return;
|
2019-09-07 13:12:12 +02:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
double delta = event.getScrollDelta();
|
|
|
|
|
|
|
|
boolean cancelled = CreateClient.schematicHandler.mouseScrolled(delta)
|
2019-09-07 13:12:12 +02:00
|
|
|
|| CreateClient.schematicAndQuillHandler.mouseScrolled(delta)
|
|
|
|
|| IBlockWithScrollableValue.onScroll(delta);
|
2019-09-03 08:34:02 +02:00
|
|
|
event.setCanceled(cancelled);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onMouseInput(MouseInputEvent event) {
|
|
|
|
if (Minecraft.getInstance().currentScreen != null)
|
|
|
|
return;
|
|
|
|
|
|
|
|
int button = event.getButton();
|
|
|
|
boolean pressed = !(event.getAction() == 0);
|
|
|
|
|
|
|
|
CreateClient.schematicHandler.onMouseInput(button, pressed);
|
|
|
|
CreateClient.schematicAndQuillHandler.onMouseInput(button, pressed);
|
|
|
|
}
|
|
|
|
|
2019-09-14 18:21:30 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void addToItemTooltip(ItemTooltipEvent event) {
|
|
|
|
ItemStack stack = event.getItemStack();
|
|
|
|
String translationKey = stack.getItem().getTranslationKey(stack);
|
|
|
|
if (!translationKey.startsWith(itemPrefix) && !translationKey.startsWith(blockPrefix))
|
|
|
|
return;
|
|
|
|
|
|
|
|
if (TooltipHelper.hasTooltip(stack)) {
|
|
|
|
List<ITextComponent> toolTip = new ArrayList<>();
|
|
|
|
TooltipHelper.getTooltip(stack).addInformation(toolTip);
|
|
|
|
event.getToolTip().addAll(1, toolTip);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onRenderTick(RenderTickEvent event) {
|
|
|
|
if (!isGameActive())
|
|
|
|
return;
|
2019-09-07 13:12:12 +02:00
|
|
|
|
2019-09-03 08:34:02 +02:00
|
|
|
TurntableHandler.gameRenderTick();
|
|
|
|
}
|
|
|
|
|
|
|
|
protected static boolean isGameActive() {
|
|
|
|
return !(Minecraft.getInstance().world == null || Minecraft.getInstance().player == null);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|