From 551edceb8207835488379e3b030d15189cd049ff Mon Sep 17 00:00:00 2001 From: Max Date: Wed, 8 Jun 2022 13:40:10 +0200 Subject: [PATCH] Clean up BlockEntityHooks Signed-off-by: Max --- .../hooks/block/BlockEntityHooks.java | 50 +++++++----------- .../block/fabric/BlockEntityHooksImpl.java | 51 ------------------ .../block/forge/BlockEntityHooksImpl.java | 52 ------------------- 3 files changed, 20 insertions(+), 133 deletions(-) delete mode 100644 fabric/src/main/java/dev/architectury/hooks/block/fabric/BlockEntityHooksImpl.java delete mode 100644 forge/src/main/java/dev/architectury/hooks/block/forge/BlockEntityHooksImpl.java diff --git a/common/src/main/java/dev/architectury/hooks/block/BlockEntityHooks.java b/common/src/main/java/dev/architectury/hooks/block/BlockEntityHooks.java index a35434da..f8ffe001 100644 --- a/common/src/main/java/dev/architectury/hooks/block/BlockEntityHooks.java +++ b/common/src/main/java/dev/architectury/hooks/block/BlockEntityHooks.java @@ -19,45 +19,35 @@ package dev.architectury.hooks.block; -import com.mojang.datafixers.types.Type; -import dev.architectury.injectables.annotations.ExpectPlatform; -import net.minecraft.core.BlockPos; -import net.minecraft.world.level.block.Block; +import net.minecraft.server.level.ServerLevel; import net.minecraft.world.level.block.entity.BlockEntity; -import net.minecraft.world.level.block.entity.BlockEntityType; -import net.minecraft.world.level.block.state.BlockState; -import org.jetbrains.annotations.Nullable; -import java.util.Set; +import java.util.Objects; public class BlockEntityHooks { private BlockEntityHooks() { } - public static class TypeBuilder { - private final Constructor constructor; - private final Set validBlocks; - - private TypeBuilder(Constructor constructor, Set validBlocks) { - this.constructor = constructor; - this.validBlocks = validBlocks; - } - - public BlockEntityType build(@Nullable Type type) { - return new BlockEntityType<>(this.constructor::create, this.validBlocks, type); - } - } - /** - * Sync data to the clients. + * Utility method to sync block entity data to the clients. + * Original implementation by FabricMC, see copyright notice below. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. */ - @ExpectPlatform public static void syncData(BlockEntity entity) { - throw new AssertionError(); - } - - @FunctionalInterface - public interface Constructor { - T create(BlockPos pos, BlockState state); + if (!(Objects.requireNonNull(entity.getLevel()) instanceof ServerLevel level)) { + throw new IllegalStateException("Cannot call syncData() on the logical client! Did you check level.isClientSide first?"); + } + level.getChunkSource().blockChanged(entity.getBlockPos()); } } diff --git a/fabric/src/main/java/dev/architectury/hooks/block/fabric/BlockEntityHooksImpl.java b/fabric/src/main/java/dev/architectury/hooks/block/fabric/BlockEntityHooksImpl.java deleted file mode 100644 index c87aebad..00000000 --- a/fabric/src/main/java/dev/architectury/hooks/block/fabric/BlockEntityHooksImpl.java +++ /dev/null @@ -1,51 +0,0 @@ -/* - * This file is part of architectury. - * Copyright (C) 2020, 2021, 2022 architectury - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package dev.architectury.hooks.block.fabric; - -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.block.entity.BlockEntity; - -import java.util.Objects; - -public class BlockEntityHooksImpl { - /* - * Copyright (c) 2016, 2017, 2018, 2019 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - public static void syncData(BlockEntity entity) { - var world = Objects.requireNonNull(entity.getLevel()); - if (!(world instanceof ServerLevel)) { - throw new IllegalStateException("Cannot call sync() on the logical client! Did you check world.isClient first?"); - } else { - ((ServerLevel) world).getChunkSource().blockChanged(entity.getBlockPos()); - } - } -} diff --git a/forge/src/main/java/dev/architectury/hooks/block/forge/BlockEntityHooksImpl.java b/forge/src/main/java/dev/architectury/hooks/block/forge/BlockEntityHooksImpl.java deleted file mode 100644 index ef877259..00000000 --- a/forge/src/main/java/dev/architectury/hooks/block/forge/BlockEntityHooksImpl.java +++ /dev/null @@ -1,52 +0,0 @@ -/* - * This file is part of architectury. - * Copyright (C) 2020, 2021, 2022 architectury - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 3 of the License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public License - * along with this program; if not, write to the Free Software Foundation, - * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. - */ - -package dev.architectury.hooks.block.forge; - -import net.minecraft.server.level.ServerLevel; -import net.minecraft.world.level.Level; -import net.minecraft.world.level.block.entity.BlockEntity; - -import java.util.Objects; - -public class BlockEntityHooksImpl { - /* - * Copyright (c) 2016, 2017, 2018, 2019 FabricMC - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - public static void syncData(BlockEntity entity) { - Level world = Objects.requireNonNull(entity.getLevel()); - if (!(world instanceof ServerLevel)) { - throw new IllegalStateException("Cannot call sync() on the logical client! Did you check world.isClient first?"); - } else { - ((ServerLevel) world).getChunkSource().blockChanged(entity.getBlockPos()); - } - } -}