完善重铸台的存取物品逻辑
This commit is contained in:
parent
854fb5ed34
commit
8448e1ee25
2 changed files with 64 additions and 14 deletions
|
@ -17,6 +17,8 @@ import net.minecraft.world.inventory.DataSlot;
|
||||||
import net.minecraft.world.inventory.Slot;
|
import net.minecraft.world.inventory.Slot;
|
||||||
import net.minecraft.world.item.ItemStack;
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public class ReforgingTableMenu extends AbstractContainerMenu {
|
public class ReforgingTableMenu extends AbstractContainerMenu {
|
||||||
protected final Container container;
|
protected final Container container;
|
||||||
protected final ContainerLevelAccess access;
|
protected final ContainerLevelAccess access;
|
||||||
|
@ -50,9 +52,9 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
||||||
this.container = container;
|
this.container = container;
|
||||||
this.access = pContainerLevelAccess;
|
this.access = pContainerLevelAccess;
|
||||||
|
|
||||||
this.ammoPerkLevel.set(1);
|
this.ammoPerkLevel.set(0);
|
||||||
this.funcPerkLevel.set(1);
|
this.funcPerkLevel.set(0);
|
||||||
this.damagePerkLevel.set(1);
|
this.damagePerkLevel.set(0);
|
||||||
|
|
||||||
this.addDataSlot(ammoPerkLevel);
|
this.addDataSlot(ammoPerkLevel);
|
||||||
this.addDataSlot(funcPerkLevel);
|
this.addDataSlot(funcPerkLevel);
|
||||||
|
@ -206,6 +208,10 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.ammoPerkLevel.set(0);
|
||||||
|
this.funcPerkLevel.set(0);
|
||||||
|
this.damagePerkLevel.set(0);
|
||||||
|
|
||||||
this.container.setItem(INPUT_SLOT, ItemStack.EMPTY);
|
this.container.setItem(INPUT_SLOT, ItemStack.EMPTY);
|
||||||
this.container.setItem(RESULT_SLOT, result);
|
this.container.setItem(RESULT_SLOT, result);
|
||||||
this.container.setChanged();
|
this.container.setChanged();
|
||||||
|
@ -223,14 +229,14 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (perk.getItem() instanceof PerkItem perkItem) {
|
if (perk.getItem() instanceof PerkItem perkItem) {
|
||||||
if (PerkHelper.getItemPerkLevel(perkItem.getPerk(), gun) <= 0) {
|
switch (perkItem.getPerk().type) {
|
||||||
return;
|
case AMMO -> this.ammoPerkLevel.set(0);
|
||||||
|
case FUNCTIONAL -> this.funcPerkLevel.set(0);
|
||||||
|
case DAMAGE -> this.damagePerkLevel.set(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
switch (perkItem.getPerk().type) {
|
if (PerkHelper.getItemPerkLevel(perkItem.getPerk(), gun) <= 0) {
|
||||||
case AMMO -> this.ammoPerkLevel.set(1);
|
return;
|
||||||
case FUNCTIONAL -> this.funcPerkLevel.set(1);
|
|
||||||
case DAMAGE -> this.damagePerkLevel.set(1);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
ItemStack output = gun.copy();
|
ItemStack output = gun.copy();
|
||||||
|
@ -241,6 +247,23 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* 放置perk物品时,将对应位置的level设置为1
|
||||||
|
*
|
||||||
|
* @param pStack Perk物品
|
||||||
|
*/
|
||||||
|
private void onPlacePerk(ItemStack pStack) {
|
||||||
|
if (!(pStack.getItem() instanceof PerkItem perkItem)) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (perkItem.getPerk().type) {
|
||||||
|
case AMMO -> this.ammoPerkLevel.set(1);
|
||||||
|
case FUNCTIONAL -> this.funcPerkLevel.set(1);
|
||||||
|
case DAMAGE -> this.damagePerkLevel.set(1);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 将枪械放入输入槽中时,根据枪械上已有的Perk生成对应的Perk物品,并将等级调整为当前的等级
|
* 将枪械放入输入槽中时,根据枪械上已有的Perk生成对应的Perk物品,并将等级调整为当前的等级
|
||||||
*
|
*
|
||||||
|
@ -291,6 +314,7 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
||||||
if (ammoPerk != null) {
|
if (ammoPerk != null) {
|
||||||
if (this.container.getItem(AMMO_PERK_SLOT).getItem() instanceof PerkItem perkItem && perkItem.getPerk() == ammoPerk) {
|
if (this.container.getItem(AMMO_PERK_SLOT).getItem() instanceof PerkItem perkItem && perkItem.getPerk() == ammoPerk) {
|
||||||
this.container.setItem(AMMO_PERK_SLOT, ItemStack.EMPTY);
|
this.container.setItem(AMMO_PERK_SLOT, ItemStack.EMPTY);
|
||||||
|
this.ammoPerkLevel.set(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -298,6 +322,7 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
||||||
if (funcPerk != null) {
|
if (funcPerk != null) {
|
||||||
if (this.container.getItem(FUNC_PERK_SLOT).getItem() instanceof PerkItem perkItem && perkItem.getPerk() == funcPerk) {
|
if (this.container.getItem(FUNC_PERK_SLOT).getItem() instanceof PerkItem perkItem && perkItem.getPerk() == funcPerk) {
|
||||||
this.container.setItem(FUNC_PERK_SLOT, ItemStack.EMPTY);
|
this.container.setItem(FUNC_PERK_SLOT, ItemStack.EMPTY);
|
||||||
|
this.funcPerkLevel.set(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -305,12 +330,22 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
||||||
if (damagePerk != null) {
|
if (damagePerk != null) {
|
||||||
if (this.container.getItem(DAMAGE_PERK_SLOT).getItem() instanceof PerkItem perkItem && perkItem.getPerk() == damagePerk) {
|
if (this.container.getItem(DAMAGE_PERK_SLOT).getItem() instanceof PerkItem perkItem && perkItem.getPerk() == damagePerk) {
|
||||||
this.container.setItem(DAMAGE_PERK_SLOT, ItemStack.EMPTY);
|
this.container.setItem(DAMAGE_PERK_SLOT, ItemStack.EMPTY);
|
||||||
|
this.damagePerkLevel.set(0);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.container.setChanged();
|
this.container.setChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Nullable
|
||||||
|
public ItemStack getPerkItemBySlot(Perk.Type type) {
|
||||||
|
return switch (type) {
|
||||||
|
case AMMO -> this.container.getItem(AMMO_PERK_SLOT);
|
||||||
|
case FUNCTIONAL -> this.container.getItem(FUNC_PERK_SLOT);
|
||||||
|
case DAMAGE -> this.container.getItem(DAMAGE_PERK_SLOT);
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
class InputSlot extends Slot {
|
class InputSlot extends Slot {
|
||||||
public InputSlot(Container pContainer, int pSlot, int pX, int pY) {
|
public InputSlot(Container pContainer, int pSlot, int pX, int pY) {
|
||||||
super(pContainer, pSlot, pX, pY);
|
super(pContainer, pSlot, pX, pY);
|
||||||
|
@ -369,6 +404,12 @@ public class ReforgingTableMenu extends AbstractContainerMenu {
|
||||||
onTakePerk(pStack);
|
onTakePerk(pStack);
|
||||||
super.onTake(pPlayer, pStack);
|
super.onTake(pPlayer, pStack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void setByPlayer(ItemStack pStack) {
|
||||||
|
onPlacePerk(pStack);
|
||||||
|
super.setByPlayer(pStack);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static class ResultSlot extends Slot {
|
static class ResultSlot extends Slot {
|
||||||
|
|
|
@ -13,6 +13,7 @@ import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||||
import net.minecraft.network.chat.Component;
|
import net.minecraft.network.chat.Component;
|
||||||
import net.minecraft.resources.ResourceLocation;
|
import net.minecraft.resources.ResourceLocation;
|
||||||
import net.minecraft.world.entity.player.Inventory;
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.api.distmarker.OnlyIn;
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
|
||||||
|
@ -90,7 +91,7 @@ public class ReforgingTableScreen extends AbstractContainerScreen<ReforgingTable
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderWidget(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
|
protected void renderWidget(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
|
||||||
pGuiGraphics.blit(TEXTURE, this.getX(), this.getY(), this.isHoveredOrFocused() ? 81 : 51, 184, 29, 15, 200, 200);
|
pGuiGraphics.blit(TEXTURE, this.getX(), this.getY(), this.isHovered() ? 81 : 51, 184, 29, 15, 200, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public ReforgeButton(int pX, int pY) {
|
public ReforgeButton(int pX, int pY) {
|
||||||
|
@ -114,7 +115,7 @@ public class ReforgingTableScreen extends AbstractContainerScreen<ReforgingTable
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
static class UpgradeButton extends AbstractButton {
|
class UpgradeButton extends AbstractButton {
|
||||||
public Perk.Type type;
|
public Perk.Type type;
|
||||||
|
|
||||||
public UpgradeButton(int pX, int pY, Perk.Type type) {
|
public UpgradeButton(int pX, int pY, Perk.Type type) {
|
||||||
|
@ -124,11 +125,15 @@ public class ReforgingTableScreen extends AbstractContainerScreen<ReforgingTable
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderWidget(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
|
protected void renderWidget(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
|
||||||
pGuiGraphics.blit(TEXTURE, this.getX(), this.getY(), 187, this.isHoveredOrFocused() ? 10 : 0, 9, 9, 200, 200);
|
pGuiGraphics.blit(TEXTURE, this.getX(), this.getY(), 187, this.isHovered() ? 10 : 0, 9, 9, 200, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPress() {
|
public void onPress() {
|
||||||
|
if (ReforgingTableScreen.this.menu.getPerkItemBySlot(type) == ItemStack.EMPTY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ModUtils.PACKET_HANDLER.sendToServer(new SetPerkLevelMessage(type.ordinal(), true));
|
ModUtils.PACKET_HANDLER.sendToServer(new SetPerkLevelMessage(type.ordinal(), true));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -139,12 +144,12 @@ public class ReforgingTableScreen extends AbstractContainerScreen<ReforgingTable
|
||||||
}
|
}
|
||||||
|
|
||||||
@OnlyIn(Dist.CLIENT)
|
@OnlyIn(Dist.CLIENT)
|
||||||
static class DowngradeButton extends AbstractButton {
|
class DowngradeButton extends AbstractButton {
|
||||||
public Perk.Type type;
|
public Perk.Type type;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void renderWidget(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
|
protected void renderWidget(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
|
||||||
pGuiGraphics.blit(TEXTURE, this.getX(), this.getY(), 177, this.isHoveredOrFocused() ? 10 : 0, 9, 9, 200, 200);
|
pGuiGraphics.blit(TEXTURE, this.getX(), this.getY(), 177, this.isHovered() ? 10 : 0, 9, 9, 200, 200);
|
||||||
}
|
}
|
||||||
|
|
||||||
public DowngradeButton(int pX, int pY, Perk.Type type) {
|
public DowngradeButton(int pX, int pY, Perk.Type type) {
|
||||||
|
@ -154,6 +159,10 @@ public class ReforgingTableScreen extends AbstractContainerScreen<ReforgingTable
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onPress() {
|
public void onPress() {
|
||||||
|
if (ReforgingTableScreen.this.menu.getPerkItemBySlot(type) == ItemStack.EMPTY) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
ModUtils.PACKET_HANDLER.sendToServer(new SetPerkLevelMessage(type.ordinal(), false));
|
ModUtils.PACKET_HANDLER.sendToServer(new SetPerkLevelMessage(type.ordinal(), false));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue