enchant Elytra
This commit is contained in:
parent
57393f6a4f
commit
f41113f881
|
|
@ -1727,9 +1727,8 @@
|
|||
"registry_name": "portable_crafting_table",
|
||||
"metadata": {
|
||||
"files": [
|
||||
"src/main/java/ch/netquick/easysurvival/item/inventory/PortableCraftingTableInventoryCapability.java",
|
||||
"src/main/java/ch/netquick/easysurvival/item/PortableCraftingTableItem.java",
|
||||
"src/main/resources/assets/easysurvival/models/item/portable_crafting_table.json"
|
||||
"src/main/resources/assets/easysurvival/models/item/portable_crafting_table.json",
|
||||
"src/main/java/ch/netquick/easysurvival/item/PortableCraftingTableItem.java"
|
||||
]
|
||||
},
|
||||
"path": "~/Portable_CraftingTable"
|
||||
|
|
@ -2253,11 +2252,11 @@
|
|||
"registry_name": "easy_smelter",
|
||||
"metadata": {
|
||||
"files": [
|
||||
"src/main/resources/assets/easysurvival/models/block/easy_smelter.json",
|
||||
"src/main/resources/assets/easysurvival/blockstates/easy_smelter.json",
|
||||
"src/main/java/ch/netquick/easysurvival/block/EasySmelterBlock.java",
|
||||
"src/main/resources/assets/easysurvival/models/block/easy_smelter.json",
|
||||
"src/main/resources/assets/easysurvival/models/item/easy_smelter.json",
|
||||
"src/main/java/ch/netquick/easysurvival/block/entity/EasySmelterBlockEntity.java",
|
||||
"src/main/resources/assets/easysurvival/models/item/easy_smelter.json"
|
||||
"src/main/java/ch/netquick/easysurvival/block/EasySmelterBlock.java"
|
||||
]
|
||||
},
|
||||
"path": "~/Easy_Smelter"
|
||||
|
|
@ -2554,7 +2553,7 @@
|
|||
"type": "procedure",
|
||||
"sortid": 142,
|
||||
"compiles": true,
|
||||
"locked_code": true,
|
||||
"locked_code": false,
|
||||
"registry_name": "open_crafting_gui",
|
||||
"metadata": {
|
||||
"files": [
|
||||
|
|
|
|||
File diff suppressed because one or more lines are too long
|
|
@ -2,6 +2,6 @@
|
|||
"_fv": 60,
|
||||
"_type": "procedure",
|
||||
"definition": {
|
||||
"procedurexml": "<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?><xml xmlns=\"https://developers.google.com/blockly/xml\"><block deletable=\"false\" type=\"event_trigger\" x=\"40\" y=\"40\"><field name=\"trigger\">no_ext_trigger</field><next><block type=\"entity_open_gui\"><field name=\"guiname\">CropGUI</field><value name=\"entity\"><block type=\"entity_from_deps\"/></value><value name=\"x\"><block type=\"coord_x\"/></value><value name=\"y\"><block type=\"coord_y\"/></value><value name=\"z\"><block type=\"coord_z\"/></value></block></next></block></xml>"
|
||||
"procedurexml": "<xml xmlns=\"https://developers.google.com/blockly/xml\"><block type=\"event_trigger\" deletable=\"false\" x=\"40\" y=\"40\"><field name=\"trigger\">no_ext_trigger</field><next><block type=\"entity_open_gui\"><field name=\"guiname\">EasyIntakeGUI</field><value name=\"entity\"><block type=\"entity_from_deps\"></block></value><value name=\"x\"><block type=\"coord_x\"></block></value><value name=\"y\"><block type=\"coord_y\"></block></value><value name=\"z\"><block type=\"coord_z\"></block></value></block></next></block></xml>"
|
||||
}
|
||||
}
|
||||
|
|
@ -32,7 +32,7 @@
|
|||
"glowCondition": {
|
||||
"fixedValue": false
|
||||
},
|
||||
"guiBoundTo": "CraftingStickGUI",
|
||||
"guiBoundTo": "<NONE>",
|
||||
"inventorySize": 10,
|
||||
"inventoryStackSize": 64,
|
||||
"onRightClickedInAir": {
|
||||
|
|
|
|||
|
|
@ -1,38 +1,20 @@
|
|||
|
||||
package ch.netquick.easysurvival.item;
|
||||
|
||||
import net.minecraftforge.network.NetworkHooks;
|
||||
import net.minecraftforge.items.ItemStackHandler;
|
||||
import net.minecraftforge.common.capabilities.ICapabilityProvider;
|
||||
import net.minecraftforge.common.capabilities.ForgeCapabilities;
|
||||
|
||||
import net.minecraft.world.level.Level;
|
||||
import net.minecraft.world.item.UseAnim;
|
||||
import net.minecraft.world.item.Rarity;
|
||||
import net.minecraft.world.item.ItemStack;
|
||||
import net.minecraft.world.item.Item;
|
||||
import net.minecraft.world.inventory.AbstractContainerMenu;
|
||||
import net.minecraft.world.entity.player.Player;
|
||||
import net.minecraft.world.entity.player.Inventory;
|
||||
import net.minecraft.world.MenuProvider;
|
||||
import net.minecraft.world.InteractionResultHolder;
|
||||
import net.minecraft.world.InteractionHand;
|
||||
import net.minecraft.server.level.ServerPlayer;
|
||||
import net.minecraft.network.chat.Component;
|
||||
import net.minecraft.network.FriendlyByteBuf;
|
||||
import net.minecraft.nbt.CompoundTag;
|
||||
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import ch.netquick.easysurvival.world.inventory.CraftingStickGUIMenu;
|
||||
import ch.netquick.easysurvival.procedures.OpenCraftingGUIProcedure;
|
||||
import ch.netquick.easysurvival.item.inventory.PortableCraftingTableInventoryCapability;
|
||||
|
||||
public class PortableCraftingTableItem extends Item {
|
||||
public PortableCraftingTableItem() {
|
||||
super(new Item.Properties().stacksTo(1).rarity(Rarity.COMMON));
|
||||
super(new Item.Properties().stacksTo(64).rarity(Rarity.COMMON));
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
@ -43,45 +25,7 @@ public class PortableCraftingTableItem extends Item {
|
|||
@Override
|
||||
public InteractionResultHolder<ItemStack> use(Level world, Player entity, InteractionHand hand) {
|
||||
InteractionResultHolder<ItemStack> ar = super.use(world, entity, hand);
|
||||
if (entity instanceof ServerPlayer serverPlayer) {
|
||||
NetworkHooks.openScreen(serverPlayer, new MenuProvider() {
|
||||
@Override
|
||||
public Component getDisplayName() {
|
||||
return Component.literal("Portable Crafting Table");
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) {
|
||||
FriendlyByteBuf packetBuffer = new FriendlyByteBuf(Unpooled.buffer());
|
||||
packetBuffer.writeBlockPos(entity.blockPosition());
|
||||
packetBuffer.writeByte(hand == InteractionHand.MAIN_HAND ? 0 : 1);
|
||||
return new CraftingStickGUIMenu(id, inventory, packetBuffer);
|
||||
}
|
||||
}, buf -> {
|
||||
buf.writeBlockPos(entity.blockPosition());
|
||||
buf.writeByte(hand == InteractionHand.MAIN_HAND ? 0 : 1);
|
||||
});
|
||||
}
|
||||
OpenCraftingGUIProcedure.execute(world, entity.getX(), entity.getY(), entity.getZ(), entity);
|
||||
return ar;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ICapabilityProvider initCapabilities(ItemStack stack, @Nullable CompoundTag compound) {
|
||||
return new PortableCraftingTableInventoryCapability();
|
||||
}
|
||||
|
||||
@Override
|
||||
public CompoundTag getShareTag(ItemStack stack) {
|
||||
CompoundTag nbt = stack.getOrCreateTag();
|
||||
stack.getCapability(ForgeCapabilities.ITEM_HANDLER, null).ifPresent(capability -> nbt.put("Inventory", ((ItemStackHandler) capability).serializeNBT()));
|
||||
return nbt;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void readShareTag(ItemStack stack, @Nullable CompoundTag nbt) {
|
||||
super.readShareTag(stack, nbt);
|
||||
if (nbt != null)
|
||||
stack.getCapability(ForgeCapabilities.ITEM_HANDLER, null).ifPresent(capability -> ((ItemStackHandler) capability).deserializeNBT((CompoundTag) nbt.get("Inventory")));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -755,6 +755,56 @@ public class EasyEnchantmentTableUpdateTickProcedure {
|
|||
}.getItemStack(world, BlockPos.containing(x, y, z), 0));
|
||||
}
|
||||
}
|
||||
if (tool.getItem() == Items.ELYTRA) {
|
||||
if (tool.getEnchantmentLevel(Enchantments.UNBREAKING) == 0) {
|
||||
tool.enchant(Enchantments.UNBREAKING, 3);
|
||||
{
|
||||
BlockEntity _ent = world.getBlockEntity(BlockPos.containing(x, y, z));
|
||||
if (_ent != null) {
|
||||
final int _slotid = 1;
|
||||
final ItemStack _setstack = tool.copy();
|
||||
_setstack.setCount(1);
|
||||
_ent.getCapability(ForgeCapabilities.ITEM_HANDLER, null).ifPresent(capability -> {
|
||||
if (capability instanceof IItemHandlerModifiable)
|
||||
((IItemHandlerModifiable) capability).setStackInSlot(_slotid, _setstack);
|
||||
});
|
||||
}
|
||||
}
|
||||
tool = (new Object() {
|
||||
public ItemStack getItemStack(LevelAccessor world, BlockPos pos, int slotid) {
|
||||
AtomicReference<ItemStack> _retval = new AtomicReference<>(ItemStack.EMPTY);
|
||||
BlockEntity _ent = world.getBlockEntity(pos);
|
||||
if (_ent != null)
|
||||
_ent.getCapability(ForgeCapabilities.ITEM_HANDLER, null).ifPresent(capability -> _retval.set(capability.getStackInSlot(slotid).copy()));
|
||||
return _retval.get();
|
||||
}
|
||||
}.getItemStack(world, BlockPos.containing(x, y, z), 0));
|
||||
}
|
||||
if (tool.getEnchantmentLevel(Enchantments.MENDING) == 0) {
|
||||
tool.enchant(Enchantments.MENDING, 1);
|
||||
{
|
||||
BlockEntity _ent = world.getBlockEntity(BlockPos.containing(x, y, z));
|
||||
if (_ent != null) {
|
||||
final int _slotid = 2;
|
||||
final ItemStack _setstack = tool.copy();
|
||||
_setstack.setCount(1);
|
||||
_ent.getCapability(ForgeCapabilities.ITEM_HANDLER, null).ifPresent(capability -> {
|
||||
if (capability instanceof IItemHandlerModifiable)
|
||||
((IItemHandlerModifiable) capability).setStackInSlot(_slotid, _setstack);
|
||||
});
|
||||
}
|
||||
}
|
||||
tool = (new Object() {
|
||||
public ItemStack getItemStack(LevelAccessor world, BlockPos pos, int slotid) {
|
||||
AtomicReference<ItemStack> _retval = new AtomicReference<>(ItemStack.EMPTY);
|
||||
BlockEntity _ent = world.getBlockEntity(pos);
|
||||
if (_ent != null)
|
||||
_ent.getCapability(ForgeCapabilities.ITEM_HANDLER, null).ifPresent(capability -> _retval.set(capability.getStackInSlot(slotid).copy()));
|
||||
return _retval.get();
|
||||
}
|
||||
}.getItemStack(world, BlockPos.containing(x, y, z), 0));
|
||||
}
|
||||
}
|
||||
if (tool.getItem() == Items.TRIDENT) {
|
||||
if (tool.getEnchantmentLevel(Enchantments.UNBREAKING) == 0) {
|
||||
tool.enchant(Enchantments.UNBREAKING, 3);
|
||||
|
|
|
|||
|
|
@ -15,27 +15,25 @@ import net.minecraft.core.BlockPos;
|
|||
|
||||
import io.netty.buffer.Unpooled;
|
||||
|
||||
import ch.netquick.easysurvival.world.inventory.CropGUIMenu;
|
||||
import ch.netquick.easysurvival.world.inventory.EasyIntakeGUIMenu;
|
||||
|
||||
public class OpenCraftingGUIProcedure {
|
||||
public static void execute(LevelAccessor world, double x, double y, double z, Entity entity) {
|
||||
if (!(entity instanceof Player))
|
||||
return;
|
||||
public static void execute(LevelAccessor world, double x, double y, double z, Entity entity) {
|
||||
if (entity == null)
|
||||
return;
|
||||
if (entity instanceof ServerPlayer _ent) {
|
||||
BlockPos _bpos = BlockPos.containing(x, y, z);
|
||||
NetworkHooks.openScreen((ServerPlayer) _ent, new MenuProvider() {
|
||||
@Override
|
||||
public Component getDisplayName() {
|
||||
return Component.literal("EasyIntakeGUI");
|
||||
}
|
||||
|
||||
Player player = (Player) entity;
|
||||
BlockPos pos = new BlockPos((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z)); // Convert doubles to integers
|
||||
|
||||
player.openMenu(new MenuProvider() {
|
||||
@Override
|
||||
public Component getDisplayName() {
|
||||
return null; // You can return a custom display name if needed
|
||||
}
|
||||
|
||||
@Override
|
||||
public AbstractContainerMenu createMenu(int windowId, Inventory playerInventory, Player player) {
|
||||
// Instantiate CropGUIMenu with proper constructor arguments
|
||||
return new CropGUIMenu(windowId, playerInventory, new FriendlyByteBuf(Unpooled.buffer()));
|
||||
}
|
||||
});
|
||||
}
|
||||
@Override
|
||||
public AbstractContainerMenu createMenu(int id, Inventory inventory, Player player) {
|
||||
return new EasyIntakeGUIMenu(id, inventory, new FriendlyByteBuf(Unpooled.buffer()).writeBlockPos(_bpos));
|
||||
}
|
||||
}, _bpos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user