Revamped the radial menu. Removed some old code.

This commit is contained in:
Christian Knaapen
2021-12-05 14:30:57 +01:00
parent 700a3062f7
commit 80e355a806
10 changed files with 183 additions and 277 deletions

View File

@@ -51,7 +51,6 @@ public class EventHandler {
}
@SubscribeEvent
//Only called serverside (except with lilypads...)
public static void onBlockPlaced(BlockEvent.EntityPlaceEvent event) {
if (event.getWorld().isClientSide()) return;

View File

@@ -1,37 +1,16 @@
package nl.requios.effortlessbuilding.compatibility;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.item.AbstractRandomizerBagItem;
public class CompatHelper {
//TODO 1.13 compatibility
// // Get a handle to the dank null item instance. This will remain null if the mod doesn't load
// // and all checks will fail, so it works.
// @GameRegistry.ObjectHolder("danknull:dank_null")
// public static final Item dankNullItem = null;
//
// public static IChiselsAndBitsProxy chiselsAndBitsProxy;
//
public static void setup() {
//TODO 1.13 compatibility
// if (Loader.isModLoaded("chiselsandbits")) {
// // reflection to avoid hard dependency
// try {
// chiselsAndBitsProxy = Class.forName("nl.requios.effortlessbuilding.compatibility.ActiveChiselsAndBitsProxy").asSubclass(ActiveChiselsAndBitsProxy.class).newInstance();
// } catch (InstantiationException | IllegalAccessException | ClassNotFoundException e) {
// e.printStackTrace();
// }
// } else {
// chiselsAndBitsProxy = new DummyChiselsAndBitsProxy();
// }
}
// Check if the item given is a proxy for blocks. For now, we check for the randomizer bag,
@@ -41,9 +20,6 @@ public class CompatHelper {
if (item instanceof BlockItem)
return true;
return item instanceof AbstractRandomizerBagItem;
//TODO 1.13 compatibility
// if (item == dankNullItem)
// return true;
}
// Get the block to be placed by this proxy. For the /dank/null, it's the slot stack
@@ -58,21 +34,14 @@ public class CompatHelper {
if (proxyItem instanceof AbstractRandomizerBagItem) {
ItemStack itemStack = proxy;
while (!(itemStack.getItem() instanceof BlockItem || itemStack.isEmpty())) {
if (itemStack.getItem() instanceof AbstractRandomizerBagItem randomizerBagItem)
if (itemStack.getItem() instanceof AbstractRandomizerBagItem) {
AbstractRandomizerBagItem randomizerBagItem = (AbstractRandomizerBagItem) itemStack.getItem();
itemStack = randomizerBagItem.pickRandomStack(randomizerBagItem.getBagInventory(itemStack));
}
}
return itemStack;
}
//TODO 1.13 compatibility
//Dank Null
// if (proxyItem == dankNullItem) {
// int index = 0;
// if (proxy.hasTagCompound() && proxy.getTagCompound().hasKey("selectedIndex"))
// index = proxy.getTagCompound().getInteger("selectedIndex");
// return proxy.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getStackInSlot(index);
// }
return ItemStack.EMPTY;
}
@@ -82,49 +51,13 @@ public class CompatHelper {
Item blockItem = Item.byBlock(state.getBlock());
if (stack.getItem() instanceof BlockItem)
return stack;
else if (stack.getItem() instanceof AbstractRandomizerBagItem randomizerBagItem) {
else if (stack.getItem() instanceof AbstractRandomizerBagItem) {
AbstractRandomizerBagItem randomizerBagItem = (AbstractRandomizerBagItem) stack.getItem();
IItemHandler bagInventory = randomizerBagItem.getBagInventory(stack);
return randomizerBagItem.findStack(bagInventory, blockItem);
}
//TODO 1.13 compatibility
// else if (stack.getItem() == dankNullItem) {
// int index = itemHandlerSlotForItem(stack, blockItem);
// if (index >= 0)
// return stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).getStackInSlot(index);
// }
return ItemStack.EMPTY;
}
// Handle IItemHandler slot stacks not being modifiable. We must call IItemHandler#extractItem,
// because the ItemStack returned by IItemHandler#getStackInSlot isn't modifiable.
public static void shrinkStack(ItemStack origStack, ItemStack curStack, Player player) {
//TODO 1.13 compatibility, offhand support
//Hacky way to get the origstack, because given origStack is itemblock stack and never proxy
// origStack = player.getHeldItem(EnumHand.MAIN_HAND);
// if (origStack.getItem() == dankNullItem) {
// int index = itemHandlerSlotForItem(origStack, curStack.getItem());
// origStack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null).extractItem(index, 1, false);
// } else
curStack.shrink(1);
}
private static int itemHandlerSlotForItem(ItemStack stack, Item blockItem) {
LazyOptional<IItemHandler> itemHandlerLazyOptional = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
IItemHandler handler = itemHandlerLazyOptional.orElse(null);
if (handler == null) {
EffortlessBuilding.logger.warn("Itemblock proxy has no item handler capability!");
return -1;
}
for (int i = 0; i < handler.getSlots(); i++) {
ItemStack ref = handler.getStackInSlot(i);
if (ref.getItem() instanceof BlockItem)
if (ref.getItem() == blockItem)
return i;
}
return -1;
}
}

View File

@@ -19,6 +19,7 @@ import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fmlclient.gui.widget.ExtendedButton;
import net.minecraftforge.fmlclient.gui.widget.Slider;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.proxy.ClientProxy;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@@ -1,31 +1,34 @@
package nl.requios.effortlessbuilding.gui.buildmode;
import com.google.common.base.Stopwatch;
import com.mojang.blaze3d.platform.InputConstants;
import com.mojang.blaze3d.vertex.*;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.MethodsReturnNonnullByDefault;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.screens.Screen;
import net.minecraft.client.player.LocalPlayer;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.client.renderer.texture.TextureAtlas;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureManager;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.client.KeyMapping;
import net.minecraft.client.resources.sounds.SimpleSoundInstance;
import net.minecraft.core.Direction;
import net.minecraft.ChatFormatting;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import nl.requios.effortlessbuilding.EffortlessBuilding;
import nl.requios.effortlessbuilding.ModClientEventHandler;
import nl.requios.effortlessbuilding.buildmode.ModeOptions;
import nl.requios.effortlessbuilding.buildmode.ModeSettingsManager;
import nl.requios.effortlessbuilding.network.ModeActionMessage;
import nl.requios.effortlessbuilding.network.ModeSettingsMessage;
import nl.requios.effortlessbuilding.network.PacketHandler;
import nl.requios.effortlessbuilding.proxy.ClientProxy;
import org.apache.commons.lang3.text.WordUtils;
import org.lwjgl.opengl.GL11;
import javax.annotation.ParametersAreNonnullByDefault;
import java.util.ArrayList;
import java.util.concurrent.TimeUnit;
import static nl.requios.effortlessbuilding.buildmode.ModeOptions.*;
@@ -43,55 +46,46 @@ import nl.requios.effortlessbuilding.buildmode.ModeOptions.OptionEnum;
public class RadialMenu extends Screen {
public static final RadialMenu instance = new RadialMenu();
private final float TIME_SCALE = 0.01f;
public BuildModeEnum switchTo = null;
public ActionEnum doAction = null;
public boolean actionUsed = false;
private float visibility = 0.0f;
private Stopwatch lastChange = Stopwatch.createStarted();
public boolean performedActionUsingMouse;
private float visibility;
public RadialMenu() {
super(new TranslatableComponent("effortlessbuilding.screen.radial_menu"));
}
private float clampVis(final float f) {
return Math.max(0.0f, Math.min(1.0f, f));
}
public void raiseVisibility() {
visibility = clampVis(visibility + lastChange.elapsed(TimeUnit.MILLISECONDS) * TIME_SCALE);
lastChange = Stopwatch.createStarted();
}
public void decreaseVisibility() {
visibility = clampVis(visibility - lastChange.elapsed(TimeUnit.MILLISECONDS) * TIME_SCALE);
lastChange = Stopwatch.createStarted();
}
public void setVisibility(float visibility) {
this.visibility = visibility;
}
public boolean isVisible() {
return visibility > 0.001;
return Minecraft.getInstance().screen instanceof RadialMenu;
}
public void configure(final int scaledWidth, final int scaledHeight) {
Minecraft mc = Minecraft.getInstance();
font = mc.font;
width = scaledWidth;
height = scaledHeight;
@Override
protected void init() {
super.init();
performedActionUsingMouse = false;
visibility = 0f;
}
@Override
public void tick() {
super.tick();
if (!ClientProxy.isKeybindDown(2)) {
onClose();
}
}
@Override
public void render(PoseStack ms, final int mouseX, final int mouseY, final float partialTicks) {
if (!isVisible()) return;
BuildModeEnum currentBuildMode = ModeSettingsManager.getModeSettings(Minecraft.getInstance().player).getBuildMode();
ms.pushPose();
ms.translate(0, 0, 200);
visibility += 0.3f * partialTicks;
if (visibility > 1f) visibility = 1f;
final int startColor = (int) (visibility * 98) << 24;
final int endColor = (int) (visibility * 128) << 24;
@@ -110,9 +104,8 @@ public class RadialMenu extends Screen {
//Fix for high def (retina) displays: use custom mouse coordinates
//Borrowed from GameRenderer::updateCameraAndRender
Minecraft mc = Minecraft.getInstance();
int mouseXX = (int) (mc.mouseHandler.xpos() * (double) mc.getWindow().getGuiScaledWidth() / (double) mc.getWindow().getScreenWidth());
int mouseYY = (int) (mc.mouseHandler.ypos() * (double) mc.getWindow().getGuiScaledHeight() / (double) mc.getWindow().getScreenHeight());
int mouseXX = (int) (minecraft.mouseHandler.xpos() * (double) minecraft.getWindow().getGuiScaledWidth() / (double) minecraft.getWindow().getScreenWidth());
int mouseYY = (int) (minecraft.mouseHandler.ypos() * (double) minecraft.getWindow().getGuiScaledHeight() / (double) minecraft.getWindow().getScreenHeight());
final double mouseXCenter = mouseXX - middleX;
final double mouseYCenter = mouseYY - middleY;
@@ -162,6 +155,8 @@ public class RadialMenu extends Screen {
drawActionBackgrounds(buffer, middleX, middleY, mouseXCenter, mouseYCenter, buttons);
tessellator.end();
RenderSystem.disableBlend();
RenderSystem.enableTexture();
drawIcons(ms, tessellator, buffer, middleX, middleY, ringInnerEdge, ringOuterEdge, modes, buttons);
@@ -381,8 +376,8 @@ public class RadialMenu extends Screen {
private String findKeybind(MenuButton button, BuildModeEnum currentBuildMode){
String result = "";
int keybindingIndex = -1;
if (button.action == ActionEnum.UNDO) keybindingIndex = 4;
if (button.action == ActionEnum.REDO) keybindingIndex = 5;
if (button.action == ActionEnum.UNDO) keybindingIndex = 3;
if (button.action == ActionEnum.REDO) keybindingIndex = 4;
if (button.action == ActionEnum.REPLACE) keybindingIndex = 1;
if (button.action == ActionEnum.OPEN_MODIFIER_SETTINGS) keybindingIndex = 0;
@@ -399,7 +394,7 @@ public class RadialMenu extends Screen {
//Add (ctrl) to first two actions of first option
if (button.action == currentBuildMode.options[0].actions[0]
|| button.action == currentBuildMode.options[0].actions[1]) {
result = I18n.get(ClientProxy.keyBindings[6].getKey().getName());
result = I18n.get(ClientProxy.keyBindings[5].getKey().getName());
if (result.equals("Left Control")) result = "Ctrl";
}
}
@@ -418,26 +413,62 @@ public class RadialMenu extends Screen {
return n > 0 ? 1 : -1;
}
/**
* Called when the mouse is clicked. Args : mouseX, mouseY, clickedButton
*/
@Override
public boolean isPauseScreen() {
return false;
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
EffortlessBuilding.log("mouse clicked");
performAction(true);
KeyMapping.setAll();
KeyMapping.set(ClientProxy.keyBindings[3].getKey(), true);
if (mouseButton == 0) {
this.minecraft.setScreen(null);
if (this.minecraft.screen == null) {
this.minecraft.setWindowActive(true);
}
}
return super.mouseClicked(mouseX, mouseY, mouseButton);
}
@Override
public void onClose() {
super.onClose();
//After onClose so it can open another screen
if (!performedActionUsingMouse) performAction(false);
}
private void performAction(boolean fromMouseClick) {
LocalPlayer player = Minecraft.getInstance().player;
ModeSettingsManager.ModeSettings modeSettings = ModeSettingsManager.getModeSettings(player);
if (switchTo != null) {
playRadialMenuSound();
modeSettings.setBuildMode(switchTo);
ModeSettingsManager.setModeSettings(player, modeSettings);
PacketHandler.INSTANCE.sendToServer(new ModeSettingsMessage(modeSettings));
EffortlessBuilding.log(player, I18n.get(modeSettings.getBuildMode().name), true);
performedActionUsingMouse = true;
}
//Perform button action
ModeOptions.ActionEnum action = doAction;
if (action != null) {
playRadialMenuSound();
ModeOptions.performAction(player, action);
PacketHandler.INSTANCE.sendToServer(new ModeActionMessage(action));
performedActionUsingMouse = true;
}
}
public static void playRadialMenuSound() {
final float volume = 0.1f;
if (volume >= 0.0001f) {
SimpleSoundInstance sound = new SimpleSoundInstance(SoundEvents.UI_BUTTON_CLICK, SoundSource.MASTER, volume, 1.0f, Minecraft.getInstance().player.blockPosition());
Minecraft.getInstance().getSoundManager().play(sound);
}
}
private static class MenuButton {
public final ActionEnum action;

View File

@@ -87,17 +87,27 @@ public class ModifierSettingsGui extends Screen {
public boolean charTyped(char typedChar, int keyCode) {
super.charTyped(typedChar, keyCode);
scrollPane.charTyped(typedChar, keyCode);
return false;
}
@Override
public boolean keyPressed(int keyCode, int p_96553_, int p_96554_) {
if (keyCode == ClientProxy.keyBindings[0].getKey().getValue()) {
minecraft.player.closeContainer();
return true;
}
return false;
return super.keyPressed(keyCode, p_96553_, p_96554_);
}
@Override
public boolean mouseClicked(double mouseX, double mouseY, int mouseButton) {
super.mouseClicked(mouseX, mouseY, mouseButton);
renderables.forEach(renderable -> {
if (renderable instanceof Button button) button.mouseClicked(mouseX, mouseY, mouseButton);
if (renderable instanceof Button) {
Button button = (Button) renderable;
button.mouseClicked(mouseX, mouseY, mouseButton);
}
});
return scrollPane.mouseClicked(mouseX, mouseY, mouseButton);
}

View File

@@ -85,7 +85,7 @@ public class SurvivalHelper {
}
if (!player.isCreative() && Block.byItem(itemstack.getItem()) == block) {
CompatHelper.shrinkStack(origstack, itemstack, player);
itemstack.shrink(1);
}
return true;

View File

@@ -65,6 +65,33 @@ public class ClientProxy implements IProxy {
private static int placeCooldown = 0;
private static int breakCooldown = 0;
@Override
public void setup(FMLCommonSetupEvent event) {
}
@Override
public void clientSetup(FMLClientSetupEvent event) {
// register key bindings
keyBindings = new KeyMapping[6];
// instantiate the key bindings
keyBindings[0] = new KeyMapping("key.effortlessbuilding.hud.desc", KeyConflictContext.UNIVERSAL, InputConstants.getKey(GLFW.GLFW_KEY_KP_ADD, 0), "key.effortlessbuilding.category");
keyBindings[1] = new KeyMapping("key.effortlessbuilding.replace.desc", KeyConflictContext.IN_GAME, InputConstants.getKey(GLFW.GLFW_KEY_KP_SUBTRACT, 0), "key.effortlessbuilding.category");
keyBindings[2] = new KeyMapping("key.effortlessbuilding.mode.desc", KeyConflictContext.IN_GAME, InputConstants.getKey(GLFW.GLFW_KEY_LEFT_ALT, 0), "key.effortlessbuilding.category");
keyBindings[3] = new KeyMapping("key.effortlessbuilding.undo.desc", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, InputConstants.getKey(GLFW.GLFW_KEY_Z, 0), "key.effortlessbuilding.category");
keyBindings[4] = new KeyMapping("key.effortlessbuilding.redo.desc", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, InputConstants.getKey(GLFW.GLFW_KEY_Y, 0), "key.effortlessbuilding.category");
keyBindings[5] = new KeyMapping("key.effortlessbuilding.altplacement.desc", KeyConflictContext.IN_GAME, InputConstants.getKey(GLFW.GLFW_KEY_LEFT_CONTROL, 0), "key.effortlessbuilding.category");
// register all the key bindings
for (KeyMapping keyBinding : keyBindings) {
ClientRegistry.registerKeyBinding(keyBinding);
}
MenuScreens.register(EffortlessBuilding.RANDOMIZER_BAG_CONTAINER.get(), RandomizerBagScreen::new);
MenuScreens.register(EffortlessBuilding.GOLDEN_RANDOMIZER_BAG_CONTAINER.get(), GoldenRandomizerBagScreen::new);
MenuScreens.register(EffortlessBuilding.DIAMOND_RANDOMIZER_BAG_CONTAINER.get(), DiamondRandomizerBagScreen::new);
}
@SubscribeEvent
public static void onClientTick(TickEvent.ClientTickEvent event) {
@@ -93,7 +120,6 @@ public class ClientProxy implements IProxy {
}
}
}
} else if (event.phase == TickEvent.Phase.END) {
Screen gui = Minecraft.getInstance().screen;
if (gui == null || !gui.isPauseScreen()) {
@@ -226,31 +252,33 @@ public class ClientProxy implements IProxy {
PacketHandler.INSTANCE.sendToServer(new ModifierSettingsMessage(modifierSettings));
}
//Creative/survival mode toggle
if (keyBindings[2].consumeClick()) {
if (player.isCreative()) {
player.chat("/gamemode survival");
//Radial menu
if (keyBindings[2].isDown()) {
if (ReachHelper.getMaxReach(player) > 0) {
if (!RadialMenu.instance.isVisible()) {
Minecraft.getInstance().setScreen(RadialMenu.instance);
}
} else {
player.chat("/gamemode creative");
EffortlessBuilding.log(player, "Build modes are disabled until your reach has increased. Increase your reach with craftable reach upgrades.");
}
}
//Undo (Ctrl+Z)
if (keyBindings[4].consumeClick()) {
if (keyBindings[3].consumeClick()) {
ModeOptions.ActionEnum action = ModeOptions.ActionEnum.UNDO;
ModeOptions.performAction(player, action);
PacketHandler.INSTANCE.sendToServer(new ModeActionMessage(action));
}
//Redo (Ctrl+Y)
if (keyBindings[5].consumeClick()) {
if (keyBindings[4].consumeClick()) {
ModeOptions.ActionEnum action = ModeOptions.ActionEnum.REDO;
ModeOptions.performAction(player, action);
PacketHandler.INSTANCE.sendToServer(new ModeActionMessage(action));
}
//Change placement mode
if (keyBindings[6].consumeClick()) {
if (keyBindings[5].consumeClick()) {
//Toggle between first two actions of the first option of the current build mode
BuildModes.BuildModeEnum currentBuildMode = ModeSettingsManager.getModeSettings(player).getBuildMode();
if (currentBuildMode.options.length > 0) {
@@ -272,37 +300,19 @@ public class ClientProxy implements IProxy {
public static void openModifierSettings() {
Minecraft mc = Minecraft.getInstance();
LocalPlayer player = mc.player;
if (player == null)
return;
RadialMenu.instance.setVisibility(0f);
if (player == null) return;
//Disabled if max reach is 0, might be set in the config that way.
if (ReachHelper.getMaxReach(player) == 0) {
EffortlessBuilding.log(player, "Build modifiers are disabled until your reach has increased. Increase your reach with craftable reach upgrades.");
} else {
if (mc.screen == null) {
mc.setScreen(new ModifierSettingsGui());
} else {
player.closeContainer();
}
mc.setScreen(new ModifierSettingsGui());
}
}
public static void openPlayerSettings() {
Minecraft mc = Minecraft.getInstance();
LocalPlayer player = mc.player;
if (player == null)
return;
RadialMenu.instance.setVisibility(0f);
//Disabled if max reach is 0, might be set in the config that way.
if (mc.screen == null) {
mc.setScreen(new PlayerSettingsGui());
} else {
player.closeContainer();
}
mc.setScreen(new PlayerSettingsGui());
}
@SubscribeEvent
@@ -313,6 +323,12 @@ public class ClientProxy implements IProxy {
}
}
public static boolean isKeybindDown(int keybindIndex) {
return InputConstants.isKeyDown(
Minecraft.getInstance().getWindow().getWindow(),
ClientProxy.keyBindings[2].getKey().getValue());
}
public static HitResult getLookingAt(Player player) {
Level world = player.level;
@@ -327,42 +343,6 @@ public class ClientProxy implements IProxy {
return world.clip(new ClipContext(start, end, ClipContext.Block.COLLIDER, ClipContext.Fluid.NONE, player));
}
@Override
public void setup(FMLCommonSetupEvent event) {
}
@Override
public void clientSetup(FMLClientSetupEvent event) {
// register key bindings
keyBindings = new KeyMapping[7];
// instantiate the key bindings
keyBindings[0] = new KeyMapping("key.effortlessbuilding.hud.desc", KeyConflictContext.UNIVERSAL, InputConstants.getKey(GLFW.GLFW_KEY_KP_ADD, 0), "key.effortlessbuilding.category");
keyBindings[1] = new KeyMapping("key.effortlessbuilding.replace.desc", KeyConflictContext.IN_GAME, InputConstants.getKey(GLFW.GLFW_KEY_KP_SUBTRACT, 0), "key.effortlessbuilding.category");
keyBindings[2] = new KeyMapping("key.effortlessbuilding.creative.desc", KeyConflictContext.IN_GAME, InputConstants.getKey(GLFW.GLFW_KEY_F4, 0), "key.effortlessbuilding.category");
keyBindings[3] = new KeyMapping("key.effortlessbuilding.mode.desc", KeyConflictContext.IN_GAME, InputConstants.getKey(GLFW.GLFW_KEY_LEFT_ALT, 0), "key.effortlessbuilding.category") {
@Override
public boolean same(KeyMapping other) {
//Does not conflict with Chisels and Bits radial menu
if (other.getKey().getValue() == getKey().getValue() && other.getName().equals("mod.chiselsandbits.other.mode"))
return false;
return super.same(other);
}
};
keyBindings[4] = new KeyMapping("key.effortlessbuilding.undo.desc", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, InputConstants.getKey(GLFW.GLFW_KEY_Z, 0), "key.effortlessbuilding.category");
keyBindings[5] = new KeyMapping("key.effortlessbuilding.redo.desc", KeyConflictContext.IN_GAME, KeyModifier.CONTROL, InputConstants.getKey(GLFW.GLFW_KEY_Y, 0), "key.effortlessbuilding.category");
keyBindings[6] = new KeyMapping("key.effortlessbuilding.altplacement.desc", KeyConflictContext.IN_GAME, InputConstants.getKey(GLFW.GLFW_KEY_LEFT_CONTROL, 0), "key.effortlessbuilding.category");
// register all the key bindings
for (KeyMapping keyBinding : keyBindings) {
ClientRegistry.registerKeyBinding(keyBinding);
}
MenuScreens.register(EffortlessBuilding.RANDOMIZER_BAG_CONTAINER.get(), RandomizerBagScreen::new);
MenuScreens.register(EffortlessBuilding.GOLDEN_RANDOMIZER_BAG_CONTAINER.get(), GoldenRandomizerBagScreen::new);
MenuScreens.register(EffortlessBuilding.DIAMOND_RANDOMIZER_BAG_CONTAINER.get(), DiamondRandomizerBagScreen::new);
}
public Player getPlayerEntityFromContext(Supplier<NetworkEvent.Context> ctx) {
return (ctx.get().getDirection().getReceptionSide() == LogicalSide.CLIENT ? Minecraft.getInstance().player : ctx.get().getSender());
}

View File

@@ -79,82 +79,35 @@ public class RenderHandler {
Minecraft mc = Minecraft.getInstance();
LocalPlayer player = mc.player;
//check if chisel and bits tool in hand (and has menu)
// final boolean hasChiselInHand = CompatHelper.chiselsAndBitsProxy.isHoldingChiselTool(EnumHand.MAIN_HAND);
//TODO delete
// if (event.getType() == RenderGameOverlayEvent.ElementType.ALL) {
// final boolean wasVisible = RadialMenu.instance.isVisible();
//
// if (RadialMenu.instance.isVisible()) {
// int scaledWidth = mc.getWindow().getGuiScaledWidth();
// int scaledHeight = mc.getWindow().getGuiScaledHeight();
// RadialMenu.instance.configure(scaledWidth, scaledHeight);
final RenderGameOverlayEvent.ElementType type = event.getType();
//TODO 1.13 compatibility
if (type == RenderGameOverlayEvent.ElementType.ALL /*&& !hasChiselInHand*/) {
final boolean wasVisible = RadialMenu.instance.isVisible();
// if (!wasVisible) {
// mc.mouseHandler.releaseMouse();
// }
//
// if (mc.mouseHandler.isMouseGrabbed()) {
// KeyMapping.releaseAll();
// }
if (ClientProxy.keyBindings[3].isDown()) {
if (ReachHelper.getMaxReach(player) > 0) {
RadialMenu.instance.actionUsed = false;
RadialMenu.instance.raiseVisibility();
} else if (ClientProxy.keyBindings[3].consumeClick()) {
EffortlessBuilding.log(player, "Build modes are disabled until your reach has increased. Increase your reach with craftable reach upgrades.");
}
} else {
if (!RadialMenu.instance.actionUsed) {
ModeSettingsManager.ModeSettings modeSettings = ModeSettingsManager.getModeSettings(player);
//final int mouseX = ((int) mc.mouseHandler.xpos()) * scaledWidth / mc.getWindow().getWidth();
//final int mouseY = scaledHeight - ((int) mc.mouseHandler.ypos()) * scaledHeight / mc.getWindow().getHeight() - 1;
if (RadialMenu.instance.switchTo != null) {
playRadialMenuSound();
modeSettings.setBuildMode(RadialMenu.instance.switchTo);
ModeSettingsManager.setModeSettings(player, modeSettings);
PacketHandler.INSTANCE.sendToServer(new ModeSettingsMessage(modeSettings));
EffortlessBuilding.log(player, I18n.get(modeSettings.getBuildMode().name), true);
}
//Perform button action
ModeOptions.ActionEnum action = RadialMenu.instance.doAction;
if (action != null) {
ModeOptions.performAction(player, action);
PacketHandler.INSTANCE.sendToServer(new ModeActionMessage(action));
}
playRadialMenuSound();
}
RadialMenu.instance.actionUsed = true;
RadialMenu.instance.decreaseVisibility();
}
if (RadialMenu.instance.isVisible()) {
int scaledWidth = mc.getWindow().getGuiScaledWidth();
int scaledHeight = mc.getWindow().getGuiScaledHeight();
RadialMenu.instance.configure(scaledWidth, scaledHeight);
if (!wasVisible) {
mc.mouseHandler.releaseMouse();
}
if (mc.mouseHandler.isMouseGrabbed()) {
KeyMapping.releaseAll();
}
final int mouseX = ((int) mc.mouseHandler.xpos()) * scaledWidth / mc.getWindow().getWidth();
final int mouseY = scaledHeight - ((int) mc.mouseHandler.ypos()) * scaledHeight / mc.getWindow().getHeight() - 1;
net.minecraftforge.client.ForgeHooksClient.drawScreen(RadialMenu.instance, event.getMatrixStack(), mouseX, mouseY, event.getPartialTicks());
} else {
if (wasVisible &&
RadialMenu.instance.doAction != ModeOptions.ActionEnum.OPEN_MODIFIER_SETTINGS &&
RadialMenu.instance.doAction != ModeOptions.ActionEnum.OPEN_PLAYER_SETTINGS) {
mc.mouseHandler.grabMouse();
}
}
}
}
public static void playRadialMenuSound() {
final float volume = 0.1f;
if (volume >= 0.0001f) {
SimpleSoundInstance sound = new SimpleSoundInstance(SoundEvents.UI_BUTTON_CLICK, SoundSource.MASTER, volume, 1.0f, Minecraft.getInstance().player.blockPosition());
Minecraft.getInstance().getSoundManager().play(sound);
}
//net.minecraftforge.client.ForgeHooksClient.drawScreen(RadialMenu.instance, event.getMatrixStack(), mouseX, mouseY, event.getPartialTicks());
// } else {
// if (wasVisible &&
// RadialMenu.instance.doAction != ModeOptions.ActionEnum.OPEN_MODIFIER_SETTINGS &&
// RadialMenu.instance.doAction != ModeOptions.ActionEnum.OPEN_PLAYER_SETTINGS) {
// mc.mouseHandler.grabMouse();
// }
// }
// }
}
protected static VertexConsumer beginLines(MultiBufferSource.BufferSource renderTypeBuffer) {
@@ -231,7 +184,7 @@ public class RenderHandler {
LevelRenderer.renderVoxelShape(matrixStack, buffer, collisionShape, pos.getX(), pos.getY(), pos.getZ(), (float) color.x, (float) color.y, (float) color.z, 0.4f);
}
//TODO 1.14
//TODO
//Sends breaking progress for all coordinates to renderglobal, so all blocks get visually broken
// @Override
// public void sendBlockBreakProgress(int breakerId, BlockPos pos, int progress) {

View File

@@ -6,7 +6,6 @@
"key.effortlessbuilding.category": "Effortless Building",
"key.effortlessbuilding.hud.desc": "Modifier Menu",
"key.effortlessbuilding.replace.desc": "Toggle QuickReplace",
"key.effortlessbuilding.creative.desc": "Toggle Survival/Creative Mode",
"key.effortlessbuilding.mode.desc": "Radial Menu",
"key.effortlessbuilding.undo.desc": "Undo",
"key.effortlessbuilding.redo.desc": "Redo",