|
本帖最后由 aftersans53228 于 2024-5-3 20:17 编辑
1 q* e, r% v& d" i* a9 y. l, e* }. f/ H' D {& Q0 I' j1 r
我嘞个 MinecraftServer server =player.getServer();BlockPos boxPos =buf.readBlockPos(); int[] timeData= buf.readIntArray();Boolean enabled = buf.readBoolean();if (server != null) {server.execute(()-> {if (player.getEntityWorld().getBlockEntity(boxPos) != null && player.getEntityWorld().getBlockEntity(boxPos).getType() == AFRoadsBlockRegistry.TRAFFIC_LIGHTS_CONTROL_ENTITY) {TrafficLightsControlEntity blockEntity = (TrafficLightsControlEntity) player.getEntityWorld().getBlockEntity(boxPos);World world =player.getEntityWorld();world.setBlockState(boxPos,world.getBlockState(boxPos).with(BooleanProperty.of("is_enable"),enabled));blockEntity.setCachedState(blockEntity.getCachedState().with(BooleanProperty.of("is_enable"),enabled));ArrayList<Integer> timeForward = new ArrayList<>();ArrayList<Integer> timeTurn = new ArrayList<>(); timeForward.add(timeData[0]);timeForward.add(timeData[1]);timeTurn.add(timeData[2]); timeTurn.add(timeData[3]);blockEntity.setTimeData(timeForward,timeTurn); AFRoads.LOGGER.info("Set Traffic lights Control Box {"+ Arrays.toString(timeData) + "} ,"+enabled );} else if (player.getEntityWorld().getBlockEntity(boxPos) == null) {AFRoads.LOGGER.info("Invalid Block Entity.");}});} |
|