Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

假人背包假人末影箱 功能完成 #45

Merged
merged 6 commits into from
Apr 4, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 13 additions & 1 deletion src/main/java/dev/dubhe/curtain/CurtainRules.java
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ public boolean validate(CommandSourceStack source, CurtainRule<String> rule, Str

@Rule(
categories = {CREATIVE, CLIENT},
suggestions = {"true", "flase"}
suggestions = {"true", "false"}
)
public static boolean creativeNoClip = false;

Expand Down Expand Up @@ -329,4 +329,16 @@ public boolean validate(CommandSourceStack source, CurtainRule<Double> rule, Str
)
public static boolean ctrlQCraftingFix = false;


@Rule(
categories = {CREATIVE,SURVIVAL},
suggestions = {"true","false"}
)
public static boolean openFakePlayerInventory = false;

@Rule(
categories = {CREATIVE,SURVIVAL},
suggestions = {"true","false"}
)
public static boolean openFakePlayerEnderChest = false;
}
7 changes: 7 additions & 0 deletions src/main/java/dev/dubhe/curtain/events/MyEventHandlers.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package dev.dubhe.curtain.events;

import dev.dubhe.curtain.events.rules.open_fake_player_inventory.PlayerLoggedEventHandler;
import dev.dubhe.curtain.events.rules.open_fake_player_inventory.PlayerTickEventHandler;
import dev.dubhe.curtain.events.rules.open_fake_player_inventory.entityInteractHandler;
import dev.dubhe.curtain.events.utils.LevelEventHandler;
import dev.dubhe.curtain.events.utils.ServerEventHandler;
import dev.dubhe.curtain.events.utils.ServerLifecycleEventHandler;
Expand All @@ -10,5 +13,9 @@ public static void register() {
MinecraftForge.EVENT_BUS.register(new ServerLifecycleEventHandler());
MinecraftForge.EVENT_BUS.register(new LevelEventHandler());
MinecraftForge.EVENT_BUS.register(new ServerEventHandler());

MinecraftForge.EVENT_BUS.register(new entityInteractHandler());
MinecraftForge.EVENT_BUS.register(new PlayerLoggedEventHandler());
MinecraftForge.EVENT_BUS.register(new PlayerTickEventHandler());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package dev.dubhe.curtain.events.rules.open_fake_player_inventory;

import dev.dubhe.curtain.features.player.menu.FakePlayerInventoryMenu;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

import static dev.dubhe.curtain.features.player.menu.MenuHashMap.FAKE_PLAYER_INVENTORY_MENU_MAP;

public class PlayerLoggedEventHandler {
@SubscribeEvent
public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event){
FAKE_PLAYER_INVENTORY_MENU_MAP.put(event.getEntity(),new FakePlayerInventoryMenu(event.getEntity()));
}
@SubscribeEvent
public void onPlayerLeave(PlayerEvent.PlayerLoggedOutEvent event){
FAKE_PLAYER_INVENTORY_MENU_MAP.remove(event.getEntity());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.dubhe.curtain.events.rules.open_fake_player_inventory;

import dev.dubhe.curtain.CurtainRules;
import dev.dubhe.curtain.features.player.patches.EntityPlayerMPFake;
import net.minecraft.server.level.ServerPlayer;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

import static dev.dubhe.curtain.features.player.menu.MenuHashMap.FAKE_PLAYER_INVENTORY_MENU_MAP;

public class PlayerTickEventHandler {
@SubscribeEvent
public void onTick(TickEvent.PlayerTickEvent playerTickEvent){
if(CurtainRules.openFakePlayerInventory &&
playerTickEvent.player instanceof ServerPlayer serverPlayer &&
serverPlayer instanceof EntityPlayerMPFake &&
serverPlayer.isAlive()
){
FAKE_PLAYER_INVENTORY_MENU_MAP.get(serverPlayer).tick();
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package dev.dubhe.curtain.events.rules.open_fake_player_inventory;

import dev.dubhe.curtain.CurtainRules;
import dev.dubhe.curtain.features.player.patches.EntityPlayerMPFake;
import net.minecraft.world.SimpleMenuProvider;
import net.minecraft.world.inventory.ChestMenu;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;

import static dev.dubhe.curtain.features.player.menu.MenuHashMap.FAKE_PLAYER_INVENTORY_MENU_MAP;

public class entityInteractHandler {
@SubscribeEvent
public void onInteractWithFakePlayer(PlayerInteractEvent.EntityInteract entityInteract){
if(entityInteract.getTarget() instanceof EntityPlayerMPFake fakeplayer){
SimpleMenuProvider provider = null;
if (CurtainRules.openFakePlayerEnderChest && entityInteract.getEntity().isShiftKeyDown()) {
provider = new SimpleMenuProvider(
(i,inventory,p)->
ChestMenu.threeRows(
i,
inventory,
fakeplayer.getEnderChestInventory()
),
fakeplayer.getDisplayName()
);
}
else if(CurtainRules.openFakePlayerInventory){
provider = new SimpleMenuProvider(
(i,inventory,p)->
ChestMenu.sixRows(
i,
inventory,
FAKE_PLAYER_INVENTORY_MENU_MAP.get(fakeplayer)
),
fakeplayer.getDisplayName()
);
}
if(provider != null)
entityInteract.getEntity().openMenu(provider);
}

}
}
Loading