generated from NeoForgeMDKs/MDK-1.21-ModDevGradle
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
25 changed files
with
609 additions
and
1 deletion.
There are no files selected for viewing
211 changes: 211 additions & 0 deletions
211
src/main/java/org/hiedacamellia/whispergrove/content/client/menu/SpringingMenu.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,211 @@ | ||
package org.hiedacamellia.whispergrove.content.client.menu; | ||
|
||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.network.FriendlyByteBuf; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.tags.ItemTags; | ||
import net.minecraft.world.entity.Entity; | ||
import net.minecraft.world.entity.player.Inventory; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.inventory.AbstractContainerMenu; | ||
import net.minecraft.world.inventory.ContainerLevelAccess; | ||
import net.minecraft.world.inventory.Slot; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; | ||
import net.minecraft.world.level.block.entity.BlockEntity; | ||
import net.neoforged.neoforge.capabilities.Capabilities; | ||
import net.neoforged.neoforge.items.IItemHandler; | ||
import net.neoforged.neoforge.items.ItemStackHandler; | ||
import net.neoforged.neoforge.items.SlotItemHandler; | ||
import net.neoforged.neoforge.items.wrapper.InvWrapper; | ||
import org.hiedacamellia.whispergrove.registers.WGMenu; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.function.Supplier; | ||
|
||
public class SpringingMenu extends AbstractContainerMenu implements Supplier<Map<Integer, Slot>>{ | ||
public final static HashMap<String, Object> guistate = new HashMap<>(); | ||
public final Level world; | ||
public final Player entity; | ||
public int x, y, z; | ||
public BlockPos pos; | ||
private ContainerLevelAccess access = ContainerLevelAccess.NULL; | ||
private IItemHandler internal; | ||
private final Map<Integer, Slot> customSlots = new HashMap<>(); | ||
private boolean bound = false; | ||
private Supplier<Boolean> boundItemMatcher = null; | ||
private Entity boundEntity = null; | ||
private BlockEntity boundBlockEntity = null; | ||
|
||
public SpringingMenu(int id, Inventory inv, FriendlyByteBuf extraData) { | ||
super(WGMenu.VISCERA.get(), id); | ||
this.entity = inv.player; | ||
this.world = inv.player.level(); | ||
this.internal = new ItemStackHandler(10); | ||
BlockPos pos = null; | ||
if (extraData != null) { | ||
pos = extraData.readBlockPos(); | ||
this.x = pos.getX(); | ||
this.y = pos.getY(); | ||
this.z = pos.getZ(); | ||
this.pos = pos; | ||
access = ContainerLevelAccess.create(world, pos); | ||
} | ||
if (pos != null) { | ||
if (extraData.readableBytes() == 1) { // bound to item | ||
byte hand = extraData.readByte(); | ||
ItemStack itemstack = hand == 0 ? this.entity.getMainHandItem() : this.entity.getOffhandItem(); | ||
this.boundItemMatcher = () -> itemstack == (hand == 0 ? this.entity.getMainHandItem() : this.entity.getOffhandItem()); | ||
IItemHandler cap = itemstack.getCapability(Capabilities.ItemHandler.ITEM); | ||
if (cap != null) { | ||
this.internal = cap; | ||
this.bound = true; | ||
} | ||
} else if (extraData.readableBytes() > 1) { // bound to entity | ||
extraData.readByte(); // drop padding | ||
boundEntity = world.getEntity(extraData.readVarInt()); | ||
if (boundEntity != null) { | ||
IItemHandler cap = boundEntity.getCapability(Capabilities.ItemHandler.ENTITY); | ||
if (cap != null) { | ||
this.internal = cap; | ||
this.bound = true; | ||
} | ||
} | ||
} else { // might be bound to block | ||
boundBlockEntity = this.world.getBlockEntity(pos); | ||
if (boundBlockEntity instanceof BaseContainerBlockEntity baseContainerBlockEntity) { | ||
this.internal = new InvWrapper(baseContainerBlockEntity); | ||
this.bound = true; | ||
} | ||
} | ||
} | ||
|
||
|
||
for(int ni=0;ni<3;++ni){ | ||
for(int nj=0;nj<3;++nj){ | ||
this.customSlots.put(ni*3+nj, this.addSlot(new SlotItemHandler(internal, ni*3+nj, 20 + nj * 18, 30 + ni * 18) { | ||
|
||
})); | ||
} | ||
} | ||
|
||
this.customSlots.put(9, this.addSlot(new SlotItemHandler(internal, 9, 132, 41) { | ||
|
||
})); | ||
|
||
|
||
|
||
|
||
for (int si = 0; si < 3; ++si) | ||
for (int sj = 0; sj < 9; ++sj) | ||
this.addSlot(new Slot(inv, sj + (si + 1) * 9, 7 + sj * 18, 99 + si * 18)); | ||
for (int si = 0; si < 9; ++si) | ||
this.addSlot(new Slot(inv, si, 7 + si * 18, 158 )); | ||
} | ||
|
||
@Override | ||
public boolean stillValid(Player player) { | ||
return true; | ||
} | ||
|
||
|
||
@Override | ||
public ItemStack quickMoveStack(Player playerIn, int index) { | ||
ItemStack itemstack = ItemStack.EMPTY; | ||
Slot slot = this.slots.get(index); | ||
if (slot != null && slot.hasItem()) { | ||
ItemStack itemstack1 = slot.getItem(); | ||
itemstack = itemstack1.copy(); | ||
if (index < 9) { | ||
if (!this.moveItemStackTo(itemstack1, 9, this.slots.size(), true)) | ||
return ItemStack.EMPTY; | ||
slot.onQuickCraft(itemstack1, itemstack); | ||
} else if (!this.moveItemStackTo(itemstack1, 0, 9, false)) { | ||
if (index < 9 + 27) { | ||
if (!this.moveItemStackTo(itemstack1, 9 + 27, this.slots.size(), true)) | ||
return ItemStack.EMPTY; | ||
} else { | ||
if (!this.moveItemStackTo(itemstack1, 9, 9 + 27, false)) | ||
return ItemStack.EMPTY; | ||
} | ||
return ItemStack.EMPTY; | ||
} | ||
if (itemstack1.getCount() == 0) | ||
slot.set(ItemStack.EMPTY); | ||
else | ||
slot.setChanged(); | ||
if (itemstack1.getCount() == itemstack.getCount()) | ||
return ItemStack.EMPTY; | ||
slot.onTake(playerIn, itemstack1); | ||
} | ||
return itemstack; | ||
} | ||
|
||
@Override | ||
protected boolean moveItemStackTo(ItemStack stack, int p_38905_, int p_38906_, boolean p_38907_) { | ||
boolean flag = false; | ||
int i = p_38905_; | ||
if (p_38907_) { | ||
i = p_38906_ - 1; | ||
} | ||
if (stack.isStackable()) { | ||
while (!stack.isEmpty() && (p_38907_ ? i >= p_38905_ : i < p_38906_)) { | ||
Slot slot = this.slots.get(i); | ||
ItemStack itemstack = slot.getItem(); | ||
if (slot.mayPlace(itemstack) && !itemstack.isEmpty() && ItemStack.isSameItemSameComponents(stack, itemstack)) { | ||
int j = itemstack.getCount() + stack.getCount(); | ||
int k = slot.getMaxStackSize(itemstack); | ||
if (j <= k) { | ||
stack.setCount(0); | ||
itemstack.setCount(j); | ||
slot.set(itemstack); | ||
flag = true; | ||
} else if (itemstack.getCount() < k) { | ||
stack.shrink(k - itemstack.getCount()); | ||
itemstack.setCount(k); | ||
slot.set(itemstack); | ||
flag = true; | ||
} | ||
} | ||
if (p_38907_) { | ||
i--; | ||
} else { | ||
i++; | ||
} | ||
} | ||
} | ||
if (!stack.isEmpty()) { | ||
if (p_38907_) { | ||
i = p_38906_ - 1; | ||
} else { | ||
i = p_38905_; | ||
} | ||
while (p_38907_ ? i >= p_38905_ : i < p_38906_) { | ||
Slot slot1 = this.slots.get(i); | ||
ItemStack itemstack1 = slot1.getItem(); | ||
if (itemstack1.isEmpty() && slot1.mayPlace(stack)) { | ||
int l = slot1.getMaxStackSize(stack); | ||
slot1.setByPlayer(stack.split(Math.min(stack.getCount(), l))); | ||
slot1.setChanged(); | ||
flag = true; | ||
break; | ||
} | ||
if (p_38907_) { | ||
i--; | ||
} else { | ||
i++; | ||
} | ||
} | ||
} | ||
return flag; | ||
} | ||
|
||
|
||
public Map<Integer, Slot> get() { | ||
return customSlots; | ||
} | ||
} |
109 changes: 109 additions & 0 deletions
109
src/main/java/org/hiedacamellia/whispergrove/content/client/screen/SpringingScreen.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,109 @@ | ||
package org.hiedacamellia.whispergrove.content.client.screen; | ||
|
||
import com.mojang.blaze3d.systems.RenderSystem; | ||
import com.mojang.blaze3d.vertex.PoseStack; | ||
import net.minecraft.client.gui.GuiGraphics; | ||
import net.minecraft.client.gui.components.Button; | ||
import net.minecraft.client.gui.components.ImageButton; | ||
import net.minecraft.client.gui.components.WidgetSprites; | ||
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.network.chat.Component; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.entity.player.Inventory; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.level.Level; | ||
import net.neoforged.neoforge.network.PacketDistributor; | ||
import org.hiedacamellia.whispergrove.WhisperGrove; | ||
import org.hiedacamellia.whispergrove.content.client.menu.SpringingMenu; | ||
|
||
import java.util.HashMap; | ||
|
||
public class SpringingScreen extends AbstractContainerScreen<SpringingMenu> { | ||
|
||
private static final HashMap<String, Object> guistate = SpringingMenu.guistate; | ||
private final Level world; | ||
private final int x,y,z; | ||
private final BlockPos pos; | ||
private final Player entity; | ||
//Button button_confirm; | ||
Button button_confirm; | ||
|
||
public SpringingScreen(SpringingMenu container, Inventory inventory, Component title) { | ||
super(container, inventory, title); | ||
this.world = container.world; | ||
this.x = container.x; | ||
this.y = container.y; | ||
this.z = container.z; | ||
this.pos = container.pos; | ||
this.entity = container.entity; | ||
this.imageWidth = 280; | ||
this.imageHeight = 166; | ||
} | ||
|
||
private static final ResourceLocation texture =ResourceLocation.fromNamespaceAndPath(WhisperGrove.MODID, "textures/screens/springing_background.png"); | ||
|
||
@Override | ||
public void render(GuiGraphics guiGraphics, int mouseX, int mouseY, float partialTicks) { | ||
this.renderBackground(guiGraphics, mouseX, mouseY, partialTicks); | ||
super.render(guiGraphics, mouseX, mouseY, partialTicks); | ||
this.renderTooltip(guiGraphics, mouseX, mouseY); | ||
} | ||
|
||
@Override | ||
protected void renderBg(GuiGraphics guiGraphics, float partialTicks, int gx, int gy) { | ||
RenderSystem.setShaderColor(1, 1, 1, 1); | ||
RenderSystem.enableBlend(); | ||
RenderSystem.defaultBlendFunc(); | ||
guiGraphics.blit(texture, this.leftPos, this.topPos, 0, 0, this.imageWidth, this.imageHeight, this.imageWidth, | ||
this.imageHeight); | ||
RenderSystem.disableBlend(); | ||
} | ||
|
||
@Override | ||
public boolean keyPressed(int key, int b, int c) { | ||
if (key == 256) { | ||
this.minecraft.player.closeContainer(); | ||
return true; | ||
} | ||
return super.keyPressed(key, b, c); | ||
} | ||
|
||
@Override | ||
public void containerTick() { | ||
super.containerTick(); | ||
} | ||
|
||
@Override | ||
protected void renderLabels(GuiGraphics guiGraphics, int mouseX, int mouseY) { | ||
guiGraphics.drawString(this.font, "", 44, 29, -1, false); | ||
} | ||
|
||
@Override | ||
public void onClose() { | ||
super.onClose(); | ||
} | ||
|
||
@Override | ||
public void init() { | ||
super.init(); | ||
button_confirm = new ImageButton(220,23,234-220,37-23, | ||
new WidgetSprites(ResourceLocation.fromNamespaceAndPath(WhisperGrove.MODID,"textures/screens/springing_conform_button.png"), | ||
ResourceLocation.fromNamespaceAndPath(WhisperGrove.MODID,"textures/screens/springing_conform_button_pressed.png")), | ||
e -> { | ||
// PacketDistributor.sendToServer(new CookingRangeUiButton(0, pos)); | ||
// CookingRangeUiButton.handleButtonAction(entity, 0, pos); | ||
}){ | ||
@Override | ||
public void renderWidget(GuiGraphics guiGraphics, int gx, int gy, float ticks) { | ||
if (true) | ||
super.renderWidget(guiGraphics, gx, gy, ticks); | ||
} | ||
}; | ||
|
||
|
||
|
||
guistate.put("button:button_confirm", button_confirm); | ||
this.addRenderableWidget(button_confirm); | ||
} | ||
} |
Oops, something went wrong.