Skip to content

Commit

Permalink
Merge pull request #351 from RUGMJ/rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
RUGMJ authored Jan 2, 2024
2 parents b97bf84 + fb2bf3f commit 6e300a5
Show file tree
Hide file tree
Showing 8 changed files with 41 additions and 37 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tools.redstone.redstonetools.features.commands;

import com.google.auto.service.AutoService;
import com.sk89q.worldedit.function.pattern.Pattern;
import tools.redstone.redstonetools.features.AbstractFeature;
import tools.redstone.redstonetools.features.Feature;
import tools.redstone.redstonetools.features.arguments.Argument;
Expand Down Expand Up @@ -81,8 +82,8 @@ protected Feedback execute(ServerCommandSource source) throws CommandSyntaxExcep
var playerSession = worldEdit.getSessionManager().get(wePlayer);

// for each block in the selection
final World world = FabricAdapter.adapt(player.method_48926());
try (EditSession session = worldEdit.newEditSession(FabricAdapter.adapt(player.method_48926()))) {
final World world = FabricAdapter.adapt(player.getWorld());
try (EditSession session = worldEdit.newEditSession(FabricAdapter.adapt(player.getWorld()))) {
// create mask and pattern and execute block set
int blocksColored = session.replaceBlocks(selection,
new Mask() {
Expand All @@ -97,7 +98,7 @@ public Mask2D toMask2D() {
return null;
}
},
new com.sk89q.worldedit.function.pattern.Pattern() {
new Pattern() {
@Override
public BaseBlock applyBlock(BlockVector3 position) {
return getColoredBlock(world, position, color.getValue());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,8 @@ public static BlockHitResult findAirPlaceBlockHit(PlayerEntity playerEntity) {
HitResult hitResult = findAirPlacePosition(client);
if (hitResult == null)
return true;
BlockPos blockPos = new BlockPos(hitResult.getPos());
Vec3d pos = hitResult.getPos();
BlockPos blockPos = new BlockPos((int) pos.x, (int) pos.y, (int) pos.z);

BlockState blockState = ItemUtils.getUseState(client.player,
ItemUtils.getMainItem(client.player),
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tools.redstone.redstonetools.macros.gui.screen;

import net.minecraft.client.gui.DrawContext;
import tools.redstone.redstonetools.macros.gui.MacroCommandSuggestor;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.gui.screen.Screen;
Expand All @@ -21,28 +22,27 @@ public CommandEditScreen(Screen parent, GameOptions gameOptions, TextFieldWidget
super(parent, gameOptions, Text.of(""));
this.commandField = commandField;
client = MinecraftClient.getInstance();
this.commandMacroCommandSuggestor = new MacroCommandSuggestor(client, parent, commandField,client.textRenderer,true,false, commandField.y -20,5,-805306368);
this.commandMacroCommandSuggestor = new MacroCommandSuggestor(client, parent, commandField,client.textRenderer,true,false, commandField.getY() -20,5,-805306368);

commandField.setChangedListener((s) -> changed = true);
commandMacroCommandSuggestor.setWindowActive(true);
commandMacroCommandSuggestor.refresh();
}

@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
parent.render(matrices, mouseX, mouseY, delta);
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
parent.render(context, mouseX, mouseY, delta);

this.fillGradient(matrices, 0, 0, this.width, this.height, -1072689136, -804253680);
this.fillGradient(context, 0, 0, this.width, this.height, -1072689136, -804253680);

commandField.render(matrices, mouseX, mouseY, delta);
commandField.render(context, mouseX, mouseY, delta);

commandMacroCommandSuggestor.render(matrices, mouseX, mouseY);
commandMacroCommandSuggestor.render(context, mouseX, mouseY);
if (changed) {
commandMacroCommandSuggestor.refresh();
changed = false;
}

super.render(matrices, mouseX, mouseY, delta);
super.render(context, mouseX, mouseY, delta);

}

Expand All @@ -60,7 +60,7 @@ public void resize(MinecraftClient client, int width, int height) {
@Override
public void close() {
super.close();
commandField.setTextFieldFocused(false);
commandField.setFocused(false);
commandField.setChangedListener(null);
commandMacroCommandSuggestor.setWindowActive(false);
commandMacroCommandSuggestor.refresh();
Expand All @@ -73,14 +73,13 @@ public boolean mouseClicked(double mouseX, double mouseY, int button) {
if (!commandMacroCommandSuggestor.mouseClicked(mouseX, mouseY, button)) {
close();
} else {
commandField.setTextFieldFocused(true);
commandField.setFocused(true);
}
return false;
}
return super.mouseClicked(mouseX, mouseY, button);
}

@Override
public boolean mouseScrolled(double mouseX, double mouseY, double amount) {
return commandMacroCommandSuggestor.mouseScrolled(amount);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tools.redstone.redstonetools.macros.gui.screen;

import net.minecraft.client.gui.DrawContext;
import tools.redstone.redstonetools.macros.gui.widget.macrolist.MacroEntry;
import tools.redstone.redstonetools.macros.gui.widget.macrolist.MacroListWidget;
import net.minecraft.client.gui.screen.Screen;
Expand Down Expand Up @@ -35,13 +36,12 @@ public void init() {
}));
}

@Override
public void render(MatrixStack matrices, int mouseX, int mouseY, float delta) {
public void render(DrawContext context, int mouseX, int mouseY, float delta) {
this.renderBackgroundTexture(0);
macroList.render(matrices, mouseX, mouseY, delta);
macroList.render(context, mouseX, mouseY, delta);

drawCenteredTextWithShadow(matrices, this.textRenderer, this.title, this.width / 2, 8, 16777215);
super.render(matrices, mouseX, mouseY, delta);
drawCenteredTextWithShadow(context, this.textRenderer, this.title, this.width / 2, 8, 16777215);
super.render(context, mouseX, mouseY, delta);

}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.mojang.blaze3d.platform.GlStateManager;
import com.mojang.blaze3d.systems.RenderSystem;
import net.minecraft.client.gui.DrawContext;
import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
Expand All @@ -18,8 +19,8 @@ public IconButtonWidget(Identifier texture ,int x, int y, int width, int height,
this.texture = texture;
}

public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float delta) {
super.renderButton(matrices, mouseX, mouseY, delta);
public void renderButton(DrawContext context, int mouseX, int mouseY, float delta) {
super.renderButton(context, mouseX, mouseY, delta);


RenderSystem.setShaderTexture(0, texture);
Expand All @@ -29,7 +30,7 @@ public void renderButton(MatrixStack matrices, int mouseX, int mouseY, float del
RenderSystem.enableBlend();
RenderSystem.defaultBlendFunc();
RenderSystem.blendFunc(GlStateManager.SrcFactor.SRC_ALPHA, GlStateManager.DstFactor.ONE_MINUS_SRC_ALPHA);
drawTexture(matrices, this.x, this.y, 0,0, 20, this.height, 20, 20);
drawTexture(context, this.getX(), this.getY(), 0,0, 20, this.height, 20, 20);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tools.redstone.redstonetools.macros.gui.widget.macrolist;

import net.minecraft.client.gui.DrawContext;
import tools.redstone.redstonetools.macros.Macro;
import tools.redstone.redstonetools.macros.gui.widget.IconButtonWidget;
import net.minecraft.client.gui.screen.ConfirmScreen;
Expand Down Expand Up @@ -34,10 +35,10 @@ public MacroEntry(Macro macro, MacroListWidget owner) {
}


public void render(MatrixStack matrices, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
renderWidget(buttonWidget,matrices,mouseX,mouseY,tickDelta,x-30,y-2);
renderWidget(editButton,matrices,mouseX,mouseY,tickDelta,x+entryWidth,y-2);
renderWidget(deleteButton,matrices,mouseX,mouseY,tickDelta,x+entryWidth+22,y-2);
public void render(DrawContext context, int index, int y, int x, int entryWidth, int entryHeight, int mouseX, int mouseY, boolean hovered, float tickDelta) {
renderWidget(buttonWidget,context,mouseX,mouseY,tickDelta,x-30,y-2);
renderWidget(editButton,context,mouseX,mouseY,tickDelta,x+entryWidth,y-2);
renderWidget(deleteButton,context,mouseX,mouseY,tickDelta,x+entryWidth+22,y-2);

String text = macro.name;

Expand All @@ -50,13 +51,13 @@ public void render(MatrixStack matrices, int index, int y, int x, int entryWidth
}


owner.client.textRenderer.drawWithShadow(matrices, text, x, y+3,macro.enabled?16777215:8355711, true);
owner.client.textRenderer.drawWithShadow(context, text, x, y+3,macro.enabled?16777215:8355711, true);
}

private void renderWidget(PressableWidget widget, MatrixStack matrices, int mouseX, int mouseY, float tickDelta, int x, int y) {
widget.x = x;
widget.y = y;
widget.render(matrices,mouseX,mouseY,tickDelta);
private void renderWidget(PressableWidget widget, DrawContext context, int mouseX, int mouseY, float tickDelta, int x, int y) {
widget.setX(x);
widget.setY(y);
widget.render(context,mouseX,mouseY,tickDelta);
}

public boolean mouseClicked(double mouseX, double mouseY, int button) {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package tools.redstone.redstonetools.macros.gui.widget.macrolist;

import net.minecraft.client.gui.DrawContext;
import tools.redstone.redstonetools.macros.Macro;
import tools.redstone.redstonetools.macros.MacroManager;
import tools.redstone.redstonetools.macros.gui.screen.MacroSelectScreen;
Expand Down Expand Up @@ -48,11 +49,11 @@ protected int getScrollbarPositionX() {
}


protected void renderBackground(MatrixStack matrices) {
parent.renderBackground(matrices);
protected void renderBackground(DrawContext context, int mouseX, int mouseY, float delta) {
parent.renderBackground(context, mouseX, mouseY, delta);
}

protected boolean isFocused() {
public boolean isFocused() {
return parent.getFocused() == this;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package tools.redstone.redstonetools.utils;

import net.minecraft.block.Block;
import net.minecraft.registry.Registry;
import net.minecraft.registry.Registries;
import net.minecraft.util.Identifier;

public enum ColoredBlockType {
Expand Down Expand Up @@ -34,6 +34,6 @@ public String toBlockId() {
}

public Block toBlock() {
return Registry.BLOCK.get(Identifier.tryParse(toBlockId()));
return Registries.BLOCK.get(Identifier.tryParse(toBlockId()));
}
}

0 comments on commit 6e300a5

Please sign in to comment.