-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added on texture for crusher. Added ore scanning debug item
- Loading branch information
1 parent
382fd95
commit 29268be
Showing
23 changed files
with
365 additions
and
12 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
52 changes: 52 additions & 0 deletions
52
src/main/java/com/teammetallurgy/metallurgyclassic/debug/OreScannerItem.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,52 @@ | ||
package com.teammetallurgy.metallurgyclassic.debug; | ||
|
||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.screen.NamedScreenHandlerFactory; | ||
import net.minecraft.screen.ScreenHandler; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.TypedActionResult; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class OreScannerItem extends Item { | ||
|
||
public OreScannerItem(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
public TypedActionResult<ItemStack> use(World world, PlayerEntity user, Hand hand) { | ||
ItemStack itemStack = user.getStackInHand(hand); | ||
user.openHandledScreen(new NamedScreenHandlerFactory() { | ||
@Override | ||
public Text getDisplayName() { | ||
return Text.of("Ore Scanner"); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) { | ||
return new OreScannerScreenHandler(syncId, inv); | ||
} | ||
}); | ||
|
||
// for(int x = 0; x < 16; x++) { | ||
// for(int y = 0; y < 64; y++) { | ||
// for(int z = 0; z < 16; z++) { | ||
// BlockPos pos = new BlockPos(user.getChunkPos().x * 16 + x, y, user.getChunkPos().z * 16 + z); | ||
// BlockPos pos2 = new BlockPos(user.getChunkPos().x * 16 + x, y + 64, user.getChunkPos().z * 16 + z); | ||
// BlockState state = world.getBlockState(pos); | ||
// if(state.toString().contains("ore") && state.toString().contains("metallurgy")) { | ||
// world.setBlockState(pos2, world.getBlockState(pos)); | ||
// } | ||
// } | ||
// } | ||
// } | ||
|
||
return TypedActionResult.success(itemStack); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
src/main/java/com/teammetallurgy/metallurgyclassic/debug/OreScannerKeybind.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,51 @@ | ||
package com.teammetallurgy.metallurgyclassic.debug; | ||
|
||
import net.fabricmc.fabric.api.client.event.lifecycle.v1.ClientTickEvents; | ||
import net.fabricmc.fabric.api.client.keybinding.v1.KeyBindingHelper; | ||
import net.fabricmc.fabric.api.client.screenhandler.v1.ScreenRegistry; | ||
import net.fabricmc.fabric.api.screenhandler.v1.ScreenHandlerRegistry; | ||
import net.minecraft.client.option.KeyBinding; | ||
import net.minecraft.client.util.InputUtil; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.screen.NamedScreenHandlerFactory; | ||
import net.minecraft.screen.ScreenHandler; | ||
import net.minecraft.screen.ScreenHandlerType; | ||
import net.minecraft.text.Text; | ||
import org.jetbrains.annotations.Nullable; | ||
import org.lwjgl.glfw.GLFW; | ||
|
||
import static com.teammetallurgy.metallurgyclassic.MetallurgyClassic.MOD_ID; | ||
import static com.teammetallurgy.metallurgyclassic.MetallurgyClassic.id; | ||
|
||
public class OreScannerKeybind { | ||
public static ScreenHandlerType<OreScannerScreenHandler> ORE_SCANNER_SCREEN_HANDLER = ScreenHandlerRegistry.registerSimple(id("ore_scanner"), OreScannerScreenHandler::new); | ||
|
||
public static void setup() { | ||
ScreenRegistry.register(ORE_SCANNER_SCREEN_HANDLER, OreScannerScreen::new); | ||
var keyBinding = KeyBindingHelper.registerKeyBinding(new KeyBinding( | ||
MOD_ID + ".openscreen", | ||
InputUtil.Type.KEYSYM, | ||
GLFW.GLFW_KEY_R, | ||
"category." + MOD_ID | ||
)); | ||
ClientTickEvents.END_CLIENT_TICK.register(client -> { | ||
while(keyBinding.wasPressed()) { | ||
System.out.println("Key was pressed"); | ||
|
||
client.player.openHandledScreen(new NamedScreenHandlerFactory() { | ||
@Override | ||
public Text getDisplayName() { | ||
return Text.of("Ore Scanner"); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public ScreenHandler createMenu(int syncId, PlayerInventory inv, PlayerEntity player) { | ||
return new OreScannerScreenHandler(ORE_SCANNER_SCREEN_HANDLER, syncId); | ||
} | ||
}); | ||
} | ||
}); | ||
} | ||
} |
130 changes: 130 additions & 0 deletions
130
src/main/java/com/teammetallurgy/metallurgyclassic/debug/OreScannerScreen.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,130 @@ | ||
package com.teammetallurgy.metallurgyclassic.debug; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import com.teammetallurgy.metallurgyclassic.utils.NineSlice; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.client.gui.screen.ingame.HandledScreen; | ||
import net.minecraft.client.render.GameRenderer; | ||
import net.minecraft.client.util.math.MatrixStack; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.item.BlockItem; | ||
import net.minecraft.screen.slot.Slot; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.math.BlockPos; | ||
|
||
import java.awt.*; | ||
import java.util.*; | ||
import java.util.List; | ||
|
||
import static com.teammetallurgy.metallurgyclassic.MetallurgyClassic.id; | ||
|
||
public class OreScannerScreen extends HandledScreen<OreScannerScreenHandler> { | ||
private final NineSlice background = new NineSlice(id("textures/gui/gui_background.png"), 4, 16, 16); | ||
private final Identifier SLOT = id("textures/gui/slot_background.png"); | ||
private final NineSlice bar = new NineSlice(id("textures/gui/slot_background.png"), 1, 16, -18, -18); | ||
private final NineSlice slot = new NineSlice(id("textures/gui/slot_background.png"), 6, 18, 18); | ||
|
||
public OreScannerScreen(OreScannerScreenHandler handler, PlayerInventory inventory, Text title) { | ||
super(handler, inventory, title); | ||
this.backgroundWidth = 176; | ||
this.backgroundHeight = 266; | ||
this.playerInventoryTitleY = 10000; | ||
} | ||
|
||
@Override | ||
protected void drawBackground(MatrixStack matrices, float delta, int mouseX, int mouseY) { | ||
RenderSystem.setShader(GameRenderer::getPositionTexShader); | ||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); | ||
background.renderCentered(matrices, this.backgroundWidth, this.backgroundHeight); | ||
|
||
RenderSystem.setShaderTexture(0, SLOT); | ||
int i = (this.width - this.backgroundWidth) / 2; | ||
int j = (this.height - this.backgroundHeight) / 2; | ||
|
||
List<Block> countables = new ArrayList<>(); | ||
for(Slot slot : this.handler.slots) { | ||
if(slot.getStack() != null && slot.getStack().getItem() != null && slot.getStack().getItem() instanceof BlockItem) { | ||
Block block = ((BlockItem)(slot.getStack().getItem())).getBlock(); | ||
countables.add(block); | ||
} | ||
} | ||
|
||
Map<Block, Integer> counts = getBlockCount(); | ||
Optional<Integer> maxCount = this.handler.slots.stream() | ||
.filter(slot -> slot instanceof OreScannerScreenHandler.DisplaySlot) | ||
.filter(slot -> !slot.getStack().isEmpty()) | ||
.filter(slot -> slot.getStack().getItem() instanceof BlockItem) | ||
.filter(slot -> counts.containsKey(((BlockItem) slot.getStack().getItem()).getBlock())) | ||
.map(slot -> counts.get(((BlockItem) slot.getStack().getItem()).getBlock())) | ||
.max(Comparator.naturalOrder()); | ||
|
||
int maxValue = 200; | ||
if(maxCount.isPresent()) { | ||
//maxValue = maxCount.get(); | ||
} | ||
|
||
int slotY = 266 - 5 - 18 - 5; | ||
int slot_height = 220 - 20; | ||
for(Slot slot : this.handler.slots) { | ||
drawTexture(matrices, i + slot.x - 1, j + slot.y - 1, 0, 0, 18, 18, 18, 18); | ||
} | ||
for(Slot slot : this.handler.slots) { | ||
if (slot instanceof OreScannerScreenHandler.DisplaySlot) { | ||
if (slot.getStack() != null && slot.getStack().getItem() != null && slot.getStack().getItem() instanceof BlockItem) { | ||
if(!slot.getStack().isEmpty()) { | ||
Block block = ((BlockItem) (slot.getStack().getItem())).getBlock(); | ||
int count = 0; | ||
if(counts.containsKey(block)) { | ||
count = counts.get(block); | ||
} | ||
drawBar(matrices, x + slot.x, y + slot.y - 1, slot_height, count * 200/maxValue); | ||
} else { | ||
drawBar(matrices, x + slot.x, y + slot.y - 1, slot_height, 0); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
|
||
private void drawBar(MatrixStack matrices, int x, int y, int height, int value) { | ||
int min = 4; | ||
slot.render(matrices, x, y - height, 16, height); | ||
if(value > -1) { | ||
int renderedValue = value + 4; | ||
if(value <= 0) { | ||
RenderSystem.setShaderColor(0.9f, 0.1f, 0.1f, 1.0f); | ||
} else if (value < min) { | ||
RenderSystem.setShaderColor(1f, 0.7f, 0.2f, 1.0f); | ||
} else { | ||
RenderSystem.setShaderColor(0.1f, 0.9f, 0.1f, 1.0f); | ||
} | ||
bar.render(matrices, x + 1, y - renderedValue - 1, 14, renderedValue); | ||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); | ||
String text = "" + value; | ||
drawCenteredText(matrices, textRenderer, text, x + 8, y - 11, Color.WHITE.getRGB()); | ||
} | ||
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F); | ||
} | ||
|
||
private Map<Block, Integer> getBlockCount() { | ||
var counts = new HashMap<Block, Integer>(); | ||
if(client.world != null && client.player != null) { | ||
for(int x = 0; x < 16; x++) { | ||
for(int y = 0; y < 256; y++) { | ||
for(int z = 0; z < 16; z++) { | ||
BlockPos pos = new BlockPos(client.player.getChunkPos().x * 16 + x, y, client.player.getChunkPos().z * 16 + z); | ||
Block block = client.world.getBlockState(pos).getBlock(); | ||
|
||
if(counts.containsKey(block)) { | ||
counts.put(block, counts.get(block) + 1); | ||
} else { | ||
counts.put(block, 1); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
return counts; | ||
} | ||
} |
88 changes: 88 additions & 0 deletions
88
src/main/java/com/teammetallurgy/metallurgyclassic/debug/OreScannerScreenHandler.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,88 @@ | ||
package com.teammetallurgy.metallurgyclassic.debug; | ||
|
||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.entity.player.PlayerInventory; | ||
import net.minecraft.inventory.Inventory; | ||
import net.minecraft.inventory.SimpleInventory; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.screen.ScreenHandler; | ||
import net.minecraft.screen.ScreenHandlerType; | ||
import net.minecraft.screen.slot.Slot; | ||
import net.minecraft.screen.slot.SlotActionType; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class OreScannerScreenHandler extends ScreenHandler { | ||
|
||
static List<DisplaySlot> scanSlots = new ArrayList<>(); | ||
|
||
static { | ||
int slotY = 266 - 5 - 18; | ||
int scannerOffset = -22; | ||
scanSlots.add(new DisplaySlot(Items.IRON_ORE.getDefaultStack(), 8, slotY + scannerOffset)); | ||
scanSlots.add(new DisplaySlot(Items.DIAMOND_ORE.getDefaultStack(), 8 + 18, slotY + scannerOffset)); | ||
scanSlots.add(new DisplaySlot(Items.COAL_ORE.getDefaultStack(), 8 + 18 * 2, slotY + scannerOffset)); | ||
scanSlots.add(new DisplaySlot(Items.DIRT.getDefaultStack(), 8 + 18 * 3, slotY + scannerOffset)); | ||
scanSlots.add(new DisplaySlot(Items.GRAVEL.getDefaultStack(), 8 + 18 * 4, slotY + scannerOffset)); | ||
scanSlots.add(new DisplaySlot(ItemStack.EMPTY, 8 + 18 * 5, slotY + scannerOffset)); | ||
scanSlots.add(new DisplaySlot(ItemStack.EMPTY, 8 + 18 * 6, slotY + scannerOffset)); | ||
scanSlots.add(new DisplaySlot(ItemStack.EMPTY, 8 + 18 * 7, slotY + scannerOffset)); | ||
scanSlots.add(new DisplaySlot(ItemStack.EMPTY, 8 + 18 * 8, slotY + scannerOffset)); | ||
} | ||
|
||
public static class DisplaySlot extends Slot { | ||
public DisplaySlot(ItemStack itemStack, int x, int y) { | ||
super(new SimpleInventory(itemStack), 0, x, y); | ||
} | ||
|
||
@Override | ||
public boolean canInsert(ItemStack stack) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public boolean canTakeItems(PlayerEntity playerEntity) { | ||
return false; | ||
} | ||
|
||
// @Override | ||
// public ItemStack insertStack(ItemStack stack, int count) { | ||
// return stack; | ||
// } | ||
} | ||
|
||
public OreScannerScreenHandler(int syncId, PlayerInventory playerInventory) { | ||
this(OreScannerKeybind.ORE_SCANNER_SCREEN_HANDLER, syncId); | ||
|
||
|
||
int slotY = 266 - 5 - 18; | ||
for(int y = 0; y < 9; ++y) { | ||
this.addSlot(new Slot(playerInventory, y, 8 + y * 18, slotY)); | ||
} | ||
scanSlots.forEach(this::addSlot); | ||
} | ||
|
||
protected OreScannerScreenHandler(ScreenHandlerType<?> type, int syncId) { | ||
super(type, syncId); | ||
} | ||
|
||
@Override | ||
public boolean canUse(PlayerEntity player) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public void onSlotClick(int slotIndex, int button, SlotActionType actionType, PlayerEntity player) { | ||
try { | ||
if(slots.get(slotIndex) instanceof DisplaySlot) { | ||
slots.get(slotIndex).setStack(this.getCursorStack().copy()); | ||
} else { | ||
} | ||
} catch(Exception e) { | ||
System.out.println(e); | ||
} | ||
super.onSlotClick(slotIndex, button, actionType, player); | ||
} | ||
} |
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
Oops, something went wrong.