添加武器重铸台
This commit is contained in:
parent
6d64b57f22
commit
d66d6413f4
9 changed files with 289 additions and 23 deletions
|
@ -49,7 +49,7 @@ public class ModUtils {
|
||||||
ModMobEffects.REGISTRY.register(bus);
|
ModMobEffects.REGISTRY.register(bus);
|
||||||
ModParticleTypes.REGISTRY.register(bus);
|
ModParticleTypes.REGISTRY.register(bus);
|
||||||
ModPotion.POTIONS.register(bus);
|
ModPotion.POTIONS.register(bus);
|
||||||
ModMenus.REGISTRY.register(bus);
|
ModMenuTypes.REGISTRY.register(bus);
|
||||||
ModEnchantments.REGISTRY.register(bus);
|
ModEnchantments.REGISTRY.register(bus);
|
||||||
|
|
||||||
bus.addListener(this::onCommonSetup);
|
bus.addListener(this::onCommonSetup);
|
||||||
|
|
|
@ -1,21 +1,48 @@
|
||||||
package net.mcreator.superbwarfare.block;
|
package net.mcreator.superbwarfare.block;
|
||||||
|
|
||||||
|
import net.mcreator.superbwarfare.block.menu.ReforgingTableMenu;
|
||||||
import net.minecraft.core.BlockPos;
|
import net.minecraft.core.BlockPos;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.stats.Stats;
|
||||||
|
import net.minecraft.world.InteractionHand;
|
||||||
|
import net.minecraft.world.InteractionResult;
|
||||||
|
import net.minecraft.world.MenuProvider;
|
||||||
|
import net.minecraft.world.SimpleMenuProvider;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.inventory.ContainerLevelAccess;
|
||||||
|
import net.minecraft.world.level.Level;
|
||||||
import net.minecraft.world.level.block.Block;
|
import net.minecraft.world.level.block.Block;
|
||||||
import net.minecraft.world.level.block.EntityBlock;
|
import net.minecraft.world.level.block.SoundType;
|
||||||
import net.minecraft.world.level.block.entity.BlockEntity;
|
import net.minecraft.world.level.block.state.BlockBehaviour;
|
||||||
import net.minecraft.world.level.block.state.BlockState;
|
import net.minecraft.world.level.block.state.BlockState;
|
||||||
import org.jetbrains.annotations.Nullable;
|
import net.minecraft.world.level.block.state.properties.NoteBlockInstrument;
|
||||||
|
import net.minecraft.world.phys.BlockHitResult;
|
||||||
|
|
||||||
public class ReforgingTableBlock extends Block implements EntityBlock {
|
import javax.annotation.Nullable;
|
||||||
|
|
||||||
public ReforgingTableBlock(Properties pProperties) {
|
@SuppressWarnings("deprecation")
|
||||||
super(pProperties);
|
public class ReforgingTableBlock extends Block {
|
||||||
|
private static final Component CONTAINER_TITLE = Component.translatable("container.superbwarfare.reforging_table");
|
||||||
|
|
||||||
|
public ReforgingTableBlock() {
|
||||||
|
super(BlockBehaviour.Properties.of().instrument(NoteBlockInstrument.BASEDRUM).sound(SoundType.STONE).strength(2f));
|
||||||
|
}
|
||||||
|
|
||||||
|
public InteractionResult use(BlockState pState, Level pLevel, BlockPos pPos, Player pPlayer, InteractionHand pHand, BlockHitResult pHit) {
|
||||||
|
if (pLevel.isClientSide) {
|
||||||
|
return InteractionResult.SUCCESS;
|
||||||
|
} else {
|
||||||
|
pPlayer.openMenu(pState.getMenuProvider(pLevel, pPos));
|
||||||
|
pPlayer.awardStat(Stats.INTERACT_WITH_ANVIL);
|
||||||
|
return InteractionResult.CONSUME;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Nullable
|
|
||||||
@Override
|
@Override
|
||||||
public BlockEntity newBlockEntity(BlockPos pPos, BlockState pState) {
|
@Nullable
|
||||||
return null;
|
public MenuProvider getMenuProvider(BlockState pState, Level pLevel, BlockPos pPos) {
|
||||||
|
return new SimpleMenuProvider((i, inventory, player) ->
|
||||||
|
new ReforgingTableMenu(i, inventory, ContainerLevelAccess.create(pLevel, pPos)), CONTAINER_TITLE);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,185 @@
|
||||||
|
package net.mcreator.superbwarfare.block.menu;
|
||||||
|
|
||||||
|
import net.mcreator.superbwarfare.init.ModBlocks;
|
||||||
|
import net.mcreator.superbwarfare.init.ModMenuTypes;
|
||||||
|
import net.mcreator.superbwarfare.init.ModTags;
|
||||||
|
import net.mcreator.superbwarfare.item.PerkItem;
|
||||||
|
import net.mcreator.superbwarfare.perk.Perk;
|
||||||
|
import net.minecraft.world.Container;
|
||||||
|
import net.minecraft.world.SimpleContainer;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraft.world.entity.player.Player;
|
||||||
|
import net.minecraft.world.inventory.*;
|
||||||
|
import net.minecraft.world.item.ItemStack;
|
||||||
|
|
||||||
|
public class ReforgingTableMenu extends AbstractContainerMenu {
|
||||||
|
protected final Container container;
|
||||||
|
protected final ContainerLevelAccess access;
|
||||||
|
|
||||||
|
public static final int INPUT_SLOT = 0;
|
||||||
|
public static final int AMMO_PERK_SLOT = 1;
|
||||||
|
public static final int FUNC_PERK_SLOT = 2;
|
||||||
|
public static final int DAMAGE_PERK_SLOT = 3;
|
||||||
|
public static final int RESULT_SLOT = 4;
|
||||||
|
|
||||||
|
private final DataSlot AMMO_PERK_LEVEL = DataSlot.standalone();
|
||||||
|
private final DataSlot FUNC_PERK_LEVEL = DataSlot.standalone();
|
||||||
|
private final DataSlot DAMAGE_PERK_LEVEL = DataSlot.standalone();
|
||||||
|
|
||||||
|
public static final int X_OFFSET = 0;
|
||||||
|
public static final int Y_OFFSET = 11;
|
||||||
|
|
||||||
|
public ReforgingTableMenu(int pContainerId, Inventory pPlayerInventory) {
|
||||||
|
this(pContainerId, pPlayerInventory, new SimpleContainer(5), ContainerLevelAccess.NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReforgingTableMenu(int pContainerId, Inventory pPlayerInventory, ContainerLevelAccess access) {
|
||||||
|
this(pContainerId, pPlayerInventory, new SimpleContainer(5), access);
|
||||||
|
}
|
||||||
|
|
||||||
|
public ReforgingTableMenu(int pContainerId, Inventory inventory, Container container, ContainerLevelAccess pContainerLevelAccess) {
|
||||||
|
super(ModMenuTypes.REFORGING_TABLE_MENU.get(), pContainerId);
|
||||||
|
|
||||||
|
checkContainerSize(container, 5);
|
||||||
|
|
||||||
|
this.container = container;
|
||||||
|
this.access = pContainerLevelAccess;
|
||||||
|
|
||||||
|
this.addDataSlot(AMMO_PERK_LEVEL);
|
||||||
|
this.addDataSlot(FUNC_PERK_LEVEL);
|
||||||
|
this.addDataSlot(DAMAGE_PERK_LEVEL);
|
||||||
|
|
||||||
|
this.addSlot(new InputSlot(container, INPUT_SLOT, 20, 20));
|
||||||
|
this.addSlot(new PerkSlot(container, AMMO_PERK_SLOT, Perk.Type.AMMO, 60, 30));
|
||||||
|
this.addSlot(new PerkSlot(container, FUNC_PERK_SLOT, Perk.Type.FUNCTIONAL, 60, 50));
|
||||||
|
this.addSlot(new PerkSlot(container, DAMAGE_PERK_SLOT, Perk.Type.DAMAGE, 60, 70));
|
||||||
|
this.addSlot(new ResultSlot(container, RESULT_SLOT, 130, 50));
|
||||||
|
|
||||||
|
for (int i = 0; i < 3; ++i) {
|
||||||
|
for (int j = 0; j < 9; ++j) {
|
||||||
|
this.addSlot(new Slot(inventory, j + i * 9 + 9, 8 + j * 18 + X_OFFSET, 84 + i * 18 + Y_OFFSET));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
for (int k = 0; k < 9; ++k) {
|
||||||
|
this.addSlot(new Slot(inventory, k, 8 + k * 18 + X_OFFSET, 142 + Y_OFFSET));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack quickMoveStack(Player pPlayer, int pIndex) {
|
||||||
|
ItemStack itemstack = ItemStack.EMPTY;
|
||||||
|
Slot slot = this.slots.get(pIndex);
|
||||||
|
if (slot.hasItem()) {
|
||||||
|
ItemStack stack = slot.getItem();
|
||||||
|
itemstack = stack.copy();
|
||||||
|
if (pIndex == RESULT_SLOT) {
|
||||||
|
if (!this.moveItemStackTo(stack, RESULT_SLOT, RESULT_SLOT + 36, false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
} else if (pIndex != INPUT_SLOT) {
|
||||||
|
if (stack.is(ModTags.Items.GUN)) {
|
||||||
|
if (!this.moveItemStackTo(stack, INPUT_SLOT, INPUT_SLOT + 1, false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
} else if (stack.getItem() instanceof PerkItem perkItem) {
|
||||||
|
Perk.Type type = perkItem.getPerk().type;
|
||||||
|
if (pIndex == AMMO_PERK_SLOT && type == Perk.Type.AMMO) {
|
||||||
|
if (!this.moveItemStackTo(stack, AMMO_PERK_SLOT, AMMO_PERK_SLOT + 1, false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
} else if (pIndex == FUNC_PERK_SLOT && type == Perk.Type.FUNCTIONAL) {
|
||||||
|
if (!this.moveItemStackTo(stack, FUNC_PERK_SLOT, FUNC_PERK_SLOT + 1, false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
} else if (pIndex == DAMAGE_PERK_SLOT && type == Perk.Type.DAMAGE) {
|
||||||
|
if (!this.moveItemStackTo(stack, DAMAGE_PERK_SLOT, DAMAGE_PERK_SLOT + 1, false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
} else if (!this.moveItemStackTo(stack, RESULT_SLOT, RESULT_SLOT + 36, false)) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stack.isEmpty()) {
|
||||||
|
slot.setByPlayer(ItemStack.EMPTY);
|
||||||
|
} else {
|
||||||
|
slot.setChanged();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (stack.getCount() == itemstack.getCount()) {
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
slot.onTake(pPlayer, stack);
|
||||||
|
}
|
||||||
|
|
||||||
|
return itemstack;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean stillValid(Player pPlayer) {
|
||||||
|
return this.access.evaluate((level, pos) -> level.getBlockState(pos).is(ModBlocks.REFORGING_TABLE.get())
|
||||||
|
&& pPlayer.distanceToSqr((double) pos.getX() + 0.5D, (double) pos.getY() + 0.5D, (double) pos.getZ() + 0.5D) <= 64.0D, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void removed(Player pPlayer) {
|
||||||
|
super.removed(pPlayer);
|
||||||
|
this.access.execute((p_39796_, p_39797_) -> {
|
||||||
|
for (int i = 0; i < this.container.getContainerSize(); ++i) {
|
||||||
|
ItemStack itemstack = this.container.getItem(i);
|
||||||
|
if (!itemstack.isEmpty()) {
|
||||||
|
pPlayer.getInventory().placeItemBackInInventory(itemstack);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
this.clearContainer(pPlayer, this.container);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
static class InputSlot extends Slot {
|
||||||
|
public InputSlot(Container pContainer, int pSlot, int pX, int pY) {
|
||||||
|
super(pContainer, pSlot, pX, pY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean mayPlace(ItemStack pStack) {
|
||||||
|
return pStack.is(ModTags.Items.GUN);
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxStackSize() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class PerkSlot extends Slot {
|
||||||
|
public Perk.Type type;
|
||||||
|
|
||||||
|
public PerkSlot(Container pContainer, int pSlot, Perk.Type type, int pX, int pY) {
|
||||||
|
super(pContainer, pSlot, pX, pY);
|
||||||
|
this.type = type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean mayPlace(ItemStack pStack) {
|
||||||
|
return pStack.getItem() instanceof PerkItem perkItem && perkItem.getPerk().type == type;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxStackSize() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
static class ResultSlot extends Slot {
|
||||||
|
public ResultSlot(Container pContainer, int pSlot, int pX, int pY) {
|
||||||
|
super(pContainer, pSlot, pX, pY);
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean mayPlace(ItemStack pStack) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
public int getMaxStackSize() {
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
|
@ -0,0 +1,45 @@
|
||||||
|
package net.mcreator.superbwarfare.client.screens;
|
||||||
|
|
||||||
|
import net.mcreator.superbwarfare.ModUtils;
|
||||||
|
import net.mcreator.superbwarfare.block.menu.ReforgingTableMenu;
|
||||||
|
import net.minecraft.client.gui.GuiGraphics;
|
||||||
|
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
|
||||||
|
import net.minecraft.network.chat.Component;
|
||||||
|
import net.minecraft.resources.ResourceLocation;
|
||||||
|
import net.minecraft.world.entity.player.Inventory;
|
||||||
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
|
import net.minecraftforge.api.distmarker.OnlyIn;
|
||||||
|
|
||||||
|
@OnlyIn(Dist.CLIENT)
|
||||||
|
public class ReforgingTableScreen extends AbstractContainerScreen<ReforgingTableMenu> {
|
||||||
|
private static final ResourceLocation TEXTURE = new ResourceLocation(ModUtils.MODID, "textures/gui/reforging_table.png");
|
||||||
|
|
||||||
|
public ReforgingTableScreen(ReforgingTableMenu pMenu, Inventory pPlayerInventory, Component pTitle) {
|
||||||
|
super(pMenu, pPlayerInventory, pTitle);
|
||||||
|
imageWidth = 176;
|
||||||
|
imageHeight = 177;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void renderBg(GuiGraphics pGuiGraphics, float pPartialTick, int pMouseX, int pMouseY) {
|
||||||
|
int i = (this.width - this.imageWidth) / 2;
|
||||||
|
int j = (this.height - this.imageHeight) / 2;
|
||||||
|
pGuiGraphics.blit(TEXTURE, i, j, 0, 0, this.imageWidth, this.imageHeight);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void render(GuiGraphics pGuiGraphics, int pMouseX, int pMouseY, float pPartialTick) {
|
||||||
|
this.renderBackground(pGuiGraphics);
|
||||||
|
super.render(pGuiGraphics, pMouseX, pMouseY, pPartialTick);
|
||||||
|
this.renderTooltip(pGuiGraphics, pMouseX, pMouseY);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void init() {
|
||||||
|
super.init();
|
||||||
|
this.titleLabelX = 8;
|
||||||
|
this.titleLabelY = 2;
|
||||||
|
this.inventoryLabelX = 8;
|
||||||
|
this.inventoryLabelY = 85;
|
||||||
|
}
|
||||||
|
}
|
|
@ -18,5 +18,6 @@ public class ModBlocks {
|
||||||
public static final RegistryObject<Block> SCHEELITE_ORE = REGISTRY.register("scheelite_ore", ScheeliteOreBlock::new);
|
public static final RegistryObject<Block> SCHEELITE_ORE = REGISTRY.register("scheelite_ore", ScheeliteOreBlock::new);
|
||||||
public static final RegistryObject<Block> DEEPSLATE_SCHEELITE_ORE = REGISTRY.register("deepslate_scheelite_ore", DeepslateScheeliteOreBlock::new);
|
public static final RegistryObject<Block> DEEPSLATE_SCHEELITE_ORE = REGISTRY.register("deepslate_scheelite_ore", DeepslateScheeliteOreBlock::new);
|
||||||
public static final RegistryObject<Block> DRAGON_TEETH = REGISTRY.register("dragon_teeth", DragonTeethBlock::new);
|
public static final RegistryObject<Block> DRAGON_TEETH = REGISTRY.register("dragon_teeth", DragonTeethBlock::new);
|
||||||
|
public static final RegistryObject<Block> REFORGING_TABLE = REGISTRY.register("reforging_table", ReforgingTableBlock::new);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -185,6 +185,7 @@ public class ModItems {
|
||||||
public static final RegistryObject<Item> SANDBAG = block(ModBlocks.SANDBAG);
|
public static final RegistryObject<Item> SANDBAG = block(ModBlocks.SANDBAG);
|
||||||
public static final RegistryObject<Item> BARBED_WIRE = block(ModBlocks.BARBED_WIRE);
|
public static final RegistryObject<Item> BARBED_WIRE = block(ModBlocks.BARBED_WIRE);
|
||||||
public static final RegistryObject<Item> DRAGON_TEETH = block(ModBlocks.DRAGON_TEETH);
|
public static final RegistryObject<Item> DRAGON_TEETH = block(ModBlocks.DRAGON_TEETH);
|
||||||
|
public static final RegistryObject<Item> REFORGING_TABLE = block(ModBlocks.REFORGING_TABLE);
|
||||||
|
|
||||||
private static RegistryObject<Item> block(RegistryObject<Block> block) {
|
private static RegistryObject<Item> block(RegistryObject<Block> block) {
|
||||||
return BLOCKS.register(block.getId().getPath(), () -> new BlockItem(block.get(), new Item.Properties()));
|
return BLOCKS.register(block.getId().getPath(), () -> new BlockItem(block.get(), new Item.Properties()));
|
||||||
|
|
|
@ -0,0 +1,17 @@
|
||||||
|
package net.mcreator.superbwarfare.init;
|
||||||
|
|
||||||
|
import net.mcreator.superbwarfare.ModUtils;
|
||||||
|
import net.mcreator.superbwarfare.block.menu.ReforgingTableMenu;
|
||||||
|
import net.minecraft.world.inventory.MenuType;
|
||||||
|
import net.minecraftforge.common.extensions.IForgeMenuType;
|
||||||
|
import net.minecraftforge.registries.DeferredRegister;
|
||||||
|
import net.minecraftforge.registries.ForgeRegistries;
|
||||||
|
import net.minecraftforge.registries.RegistryObject;
|
||||||
|
|
||||||
|
public class ModMenuTypes {
|
||||||
|
public static final DeferredRegister<MenuType<?>> REGISTRY = DeferredRegister.create(ForgeRegistries.MENU_TYPES, ModUtils.MODID);
|
||||||
|
|
||||||
|
public static final RegistryObject<MenuType<ReforgingTableMenu>> REFORGING_TABLE_MENU =
|
||||||
|
REGISTRY.register("reforging_table_menu",
|
||||||
|
() -> IForgeMenuType.create((windowId, inv, data) -> new ReforgingTableMenu(windowId, inv)));
|
||||||
|
}
|
|
@ -1,12 +0,0 @@
|
||||||
package net.mcreator.superbwarfare.init;
|
|
||||||
|
|
||||||
import net.mcreator.superbwarfare.ModUtils;
|
|
||||||
import net.minecraft.world.inventory.MenuType;
|
|
||||||
import net.minecraftforge.registries.DeferredRegister;
|
|
||||||
import net.minecraftforge.registries.ForgeRegistries;
|
|
||||||
|
|
||||||
public class ModMenus {
|
|
||||||
public static final DeferredRegister<MenuType<?>> REGISTRY = DeferredRegister.create(ForgeRegistries.MENU_TYPES, ModUtils.MODID);
|
|
||||||
|
|
||||||
|
|
||||||
}
|
|
|
@ -1,5 +1,7 @@
|
||||||
package net.mcreator.superbwarfare.init;
|
package net.mcreator.superbwarfare.init;
|
||||||
|
|
||||||
|
import net.mcreator.superbwarfare.client.screens.ReforgingTableScreen;
|
||||||
|
import net.minecraft.client.gui.screens.MenuScreens;
|
||||||
import net.minecraftforge.api.distmarker.Dist;
|
import net.minecraftforge.api.distmarker.Dist;
|
||||||
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
import net.minecraftforge.eventbus.api.SubscribeEvent;
|
||||||
import net.minecraftforge.fml.common.Mod;
|
import net.minecraftforge.fml.common.Mod;
|
||||||
|
@ -10,7 +12,7 @@ public class ModScreens {
|
||||||
@SubscribeEvent
|
@SubscribeEvent
|
||||||
public static void clientLoad(FMLClientSetupEvent event) {
|
public static void clientLoad(FMLClientSetupEvent event) {
|
||||||
event.enqueueWork(() -> {
|
event.enqueueWork(() -> {
|
||||||
|
MenuScreens.register(ModMenuTypes.REFORGING_TABLE_MENU.get(), ReforgingTableScreen::new);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue