From bd89ca4529eb04fe698be6072b05465b5d4f7307 Mon Sep 17 00:00:00 2001 From: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> Date: Mon, 13 May 2024 21:00:02 -0300 Subject: [PATCH] chore: Island protection Signed-off-by: Awakened-Redstone <40528665+Awakened-Redstone@users.noreply.github.com> --- build.gradle | 32 ++- gradle.properties | 36 +-- ...anager.java => IslandSettingsManager.java} | 29 +-- .../neoskies/command/SkylandsCommands.java | 32 ++- .../neoskies/command/island/HubCommands.java | 58 +++-- .../neoskies/command/island/LevelCommand.java | 2 +- .../neoskies/command/island/MenuCommand.java | 11 +- .../command/island/SettingCommands.java | 2 +- .../neoskies/config/MainConfig.java | 3 + .../neoskies/data/PlayerComponent.java | 7 +- .../neoskies/data/SkylandComponents.java | 8 +- .../neoskies/data/WorldComponent.java | 7 +- .../datagen/NeoSkiesBlockTagProvider.java | 102 ++++++-- .../datagen/NeoSkiesEntityTagProvider.java | 37 ++- .../datagen/NeoSkiesItemTagProvider.java | 48 ++-- .../event/GenericEntityDamageEvent.java | 36 +++ .../neoskies/gui/CommonGuiElements.java | 8 +- .../neoskies/gui/IslandSettingsGui.java | 24 +- .../neoskies/gui/PagedGui.java | 8 +- .../gui/polymer/CBGuiElementBuilder.java | 232 ++++++++++-------- .../neoskies/logic/Island.java | 46 ++-- .../logic/SkylandsEventListeners.java | 85 +++++-- .../SkylandsProtectionProvider.java | 12 +- .../registry/NeoSkiesIslandSettings.java | 123 +++++++--- .../logic/settings/IslandSettings.java | 4 +- .../logic/tags/NeoSkiesBlockTags.java | 34 ++- .../logic/tags/NeoSkiesEntityTags.java | 11 +- .../neoskies/logic/tags/NeoSkiesItemTags.java | 8 +- .../mixin/entity/DataTrackerAccessor.java | 10 + .../mixin/entity/PlayerManagerMixin.java | 6 +- .../mixin/item/ArmorStandItemMixin.java | 30 --- .../neoskies/mixin/item/BlockItemMixin.java | 44 ---- .../neoskies/mixin/item/BoatItemMixin.java | 31 --- .../BoneMealItemMixin.java | 16 +- .../neoskies/mixin/item/ItemStackMixin.java | 33 ++- .../mixin/item/MinecartItemMixin.java | 30 --- .../mixin/world/ServerWorldMixin.java | 11 +- .../protection/AbstractBlockStateMixin.java | 29 --- .../world/protection/AnvilBlockMixin.java | 30 --- .../world/protection/ArmorStandMixin.java | 58 ----- .../mixin/world/protection/AxeItemMixin.java | 29 --- .../world/protection/BeaconBlockMixin.java | 30 --- .../world/protection/BigDripLeafMixin.java | 41 ---- .../mixin/world/protection/BoatMixin.java | 42 ---- .../protection/BrewingStandBlockMixin.java | 30 --- .../world/protection/BucketableMixin.java | 53 ++++ .../mixin/world/protection/ButtonMixin.java | 35 --- .../world/protection/CandleBlockMixin.java | 37 --- .../protection/CandleCakeBlockMixin.java | 37 --- .../world/protection/CauldronBlockMixin.java | 30 --- .../world/protection/ChestBlockMixin.java | 30 --- .../world/protection/ChestBoatMixin.java | 33 --- .../world/protection/ComparatorMixin.java | 35 --- .../world/protection/CompassItemMixin.java | 35 --- .../world/protection/ComposterBlockMixin.java | 30 --- .../DaylightDetectorBlockMixin.java | 30 --- .../protection/DecorationEntityMixin.java | 37 --- .../world/protection/DecorationItemMixin.java | 34 --- .../world/protection/DispenserBlockMixin.java | 48 ---- .../world/protection/DoorBlockMixin.java | 30 --- .../world/protection/DropperBlockMixin.java | 24 -- .../mixin/world/protection/EntityMixin.java | 34 +++ .../protection/ExplosionBehaviorMixin.java | 49 ++++ .../world/protection/FarmlandBlockMixin.java | 28 --- .../world/protection/FenceBlockMixin.java | 30 --- .../world/protection/FenceGateBlockMixin.java | 30 --- .../world/protection/FilledMapItemMixin.java | 29 --- .../world/protection/FireChargeItemMixin.java | 31 --- .../world/protection/FlowerPotBlockMixin.java | 30 --- .../world/protection/FurnaceBlockMixin.java | 30 --- .../mixin/world/protection/HoeItemMixin.java | 29 --- .../world/protection/HoneycombItemMixin.java | 31 --- .../protection/HopperBlockEntityMixin.java | 32 --- .../world/protection/HopperBlockMixin.java | 60 ----- .../protection/HopperMinecartEntityMixin.java | 26 -- .../protection/ItemFrameEntityMixin.java | 44 ---- .../mixin/world/protection/LeadItemMixin.java | 30 --- .../protection/LeashKnotEntityMixin.java | 33 --- .../world/protection/LecternBlockMixin.java | 37 --- .../mixin/world/protection/LeverMixin.java | 35 --- .../world/protection/LivingEntityMixin.java | 43 ---- .../mixin/world/protection/MinecartMixin.java | 32 --- .../world/protection/NoteBlockMixin.java | 30 --- .../world/protection/PistonBlockMixin.java | 31 --- .../world/protection/PlayerEntityMixin.java | 42 ---- .../world/protection/PotionEntityMixin.java | 10 +- .../world/protection/PumpkinBlockMixin.java | 33 --- .../world/protection/RedstoneWireMixin.java | 67 ----- .../mixin/world/protection/RepeaterMixin.java | 35 --- .../protection/RespawnAnchorBlockMixin.java | 31 --- .../protection/SculkSpreadCursorMixin.java | 25 -- .../ServerPlayerInteractionManagerMixin.java | 84 +++++++ .../protection/ShulkerBoxBlockMixin.java | 30 --- .../protection/StorageMinecartMixin.java | 27 -- .../protection/SweetBerryBushBlockMixin.java | 30 --- .../mixin/world/protection/TntBlockMixin.java | 93 ------- .../world/protection/TrapdoorBlockMixin.java | 30 --- .../protection/VibrationListenerMixin.java | 38 ++- .../world/protection/VillagerEntityMixin.java | 27 -- .../mixin/world/protection/WorldMixin.java | 22 -- .../protection/WritableBookItemMixin.java | 30 --- .../protection/WrittenBookItemMixin.java | 30 --- .../{ => block}/AbstractCandleBlockMixin.java | 12 +- .../protection/block/BigDripLeafMixin.java | 59 +++++ .../protection/block/ButtonBlockMixin.java | 38 +++ .../{ => block}/CampfireBlockMixin.java | 24 +- .../protection/block/CauldronBlockMixin.java | 37 +++ .../block/LightningRodBlockMixin.java | 38 +++ .../{ => block}/PressurePlateBlockMixin.java | 25 +- .../SculkSensorBlockEntityMixin.java | 20 +- .../SculkShriekerBlockEntityMixin.java | 21 +- .../{ => block}/SculkShriekerBlockMixin.java | 17 +- .../{ => block}/TargetBlockMixin.java | 14 +- .../world/protection/block/TntBlockMixin.java | 92 +++++++ .../protection/block/TripwireBlockMixin.java | 40 +++ .../world/protection/item/AxeItemMixin.java | 40 +++ .../{ => item}/FlintAndSteelMixin.java | 20 +- .../{ => item}/ShovelItemMixin.java | 16 +- .../protection/item/SpawnEggItemMixin.java | 50 ++++ .../neoskies/util/ServerUtils.java | 13 +- .../neoskies/util/WorldProtection.java | 33 ++- .../resources/data/neoskies/lang/en_us.json | 225 +++++++++-------- src/main/resources/fabric.mod.json | 4 +- src/main/resources/neoskies.mixins.json | 34 ++- .../neoskies/test/SkylandsTestMain.java | 116 +++++++++ .../neoskies/test/TestBlock.java | 68 +++++ src/testmod/resources/fabric.mod.json | 15 ++ 127 files changed, 1891 insertions(+), 2751 deletions(-) rename src/main/java/com/awakenedredstone/neoskies/api/island/{SettingsManager.java => IslandSettingsManager.java} (75%) create mode 100644 src/main/java/com/awakenedredstone/neoskies/event/GenericEntityDamageEvent.java create mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/entity/DataTrackerAccessor.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/item/ArmorStandItemMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/item/BlockItemMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/item/BoatItemMixin.java rename src/main/java/com/awakenedredstone/neoskies/mixin/{world/protection => item}/BoneMealItemMixin.java (55%) delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/item/MinecartItemMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/AbstractBlockStateMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/AnvilBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ArmorStandMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/AxeItemMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BeaconBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BigDripLeafMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BoatMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BrewingStandBlockMixin.java create mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BucketableMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ButtonMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CandleBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CandleCakeBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CauldronBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ChestBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ChestBoatMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ComparatorMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CompassItemMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ComposterBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DaylightDetectorBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DecorationEntityMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DecorationItemMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DispenserBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DoorBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DropperBlockMixin.java create mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/EntityMixin.java create mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ExplosionBehaviorMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FarmlandBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FenceBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FenceGateBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FilledMapItemMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FireChargeItemMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FlowerPotBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FurnaceBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HoeItemMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HoneycombItemMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HopperBlockEntityMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HopperBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HopperMinecartEntityMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ItemFrameEntityMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LeadItemMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LeashKnotEntityMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LecternBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LeverMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LivingEntityMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/MinecartMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/NoteBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PistonBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PlayerEntityMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PumpkinBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/RedstoneWireMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/RepeaterMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/RespawnAnchorBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SculkSpreadCursorMixin.java create mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ServerPlayerInteractionManagerMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ShulkerBoxBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/StorageMinecartMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SweetBerryBushBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/TntBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/TrapdoorBlockMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/VillagerEntityMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/WorldMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/WritableBookItemMixin.java delete mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/WrittenBookItemMixin.java rename src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/{ => block}/AbstractCandleBlockMixin.java (66%) create mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/BigDripLeafMixin.java create mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/ButtonBlockMixin.java rename src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/{ => block}/CampfireBlockMixin.java (68%) create mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/CauldronBlockMixin.java create mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/LightningRodBlockMixin.java rename src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/{ => block}/PressurePlateBlockMixin.java (58%) rename src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/{ => block}/SculkSensorBlockEntityMixin.java (50%) rename src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/{ => block}/SculkShriekerBlockEntityMixin.java (51%) rename src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/{ => block}/SculkShriekerBlockMixin.java (61%) rename src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/{ => block}/TargetBlockMixin.java (77%) create mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/TntBlockMixin.java create mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/TripwireBlockMixin.java create mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/item/AxeItemMixin.java rename src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/{ => item}/FlintAndSteelMixin.java (58%) rename src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/{ => item}/ShovelItemMixin.java (54%) create mode 100644 src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/item/SpawnEggItemMixin.java create mode 100644 src/testmod/java/com/awakenedredstone/neoskies/test/SkylandsTestMain.java create mode 100644 src/testmod/java/com/awakenedredstone/neoskies/test/TestBlock.java create mode 100644 src/testmod/resources/fabric.mod.json diff --git a/build.gradle b/build.gradle index 7d9082d..e004bd5 100644 --- a/build.gradle +++ b/build.gradle @@ -5,11 +5,14 @@ plugins { sourceSets { main { resources { - srcDirs += [ - 'src/main/generated' - ] + srcDirs += ['src/main/generated'] } } + + testmod { + compileClasspath += main.compileClasspath + runtimeClasspath += main.runtimeClasspath + } } loom { @@ -26,6 +29,12 @@ loom { ideConfigGenerated = true runDir "build/datagen" } + + testmodServer { + server() + name = "Testmod Server" + source sourceSets.testmod + } } } @@ -34,6 +43,7 @@ version = project.mod_version group = project.maven_group repositories { + mavenLocal() maven { url "https://maven.nucleoid.xyz" } maven { url "https://maven.awakenedredstone.com" } maven { url "https://oss.sonatype.org/content/repositories/snapshots" } @@ -50,9 +60,9 @@ dependencies { modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fabric_api}" //endregion // region Cardinal Components - modImplementation "dev.onyxstudios.cardinal-components-api:cardinal-components-api:${project.cardinal_components_api}" - include "dev.onyxstudios.cardinal-components-api:cardinal-components-base:${project.cardinal_components_api}" - include "dev.onyxstudios.cardinal-components-api:cardinal-components-world:${project.cardinal_components_api}" + modImplementation "org.ladysnake.cardinal-components-api:cardinal-components-api:${project.cardinal_components_api}" + include "org.ladysnake.cardinal-components-api:cardinal-components-base:${project.cardinal_components_api}" + include "org.ladysnake.cardinal-components-api:cardinal-components-world:${project.cardinal_components_api}" // endregion // region Nucleoid modImplementation include("xyz.nucleoid:fantasy:${project.fantasy}") @@ -76,6 +86,10 @@ dependencies { // region Non mod dependencies include api("blue.endless:jankson:${project.jankson_version}") //endregion + + // region Tests + testmodImplementation sourceSets.main.output + //endregion } processResources { @@ -88,12 +102,12 @@ processResources { tasks.withType(JavaCompile).configureEach { it.options.encoding = "UTF-8" //noinspection GroovyAssignabilityCheck - it.options.release = 17 + it.options.release = 21 } java { - sourceCompatibility = JavaVersion.VERSION_17 - targetCompatibility = JavaVersion.VERSION_17 + sourceCompatibility = JavaVersion.VERSION_21 + targetCompatibility = JavaVersion.VERSION_21 withSourcesJar() } diff --git a/gradle.properties b/gradle.properties index 9547c59..5a3459c 100644 --- a/gradle.properties +++ b/gradle.properties @@ -1,30 +1,30 @@ # Done to increase the memory available to gradle. -org.gradle.jvmargs = -Xmx2G +org.gradle.jvmargs=-Xmx2G # Mod Properties -maven_group = com.awakenedredstone -archives_base_name = neoskies -mod_version = 1.0.0-alpha.1 +maven_group=com.awakenedredstone +archives_base_name=neoskies +mod_version=1.0.0-alpha.1 # Dependencies | Check these on https://fabricmc.net/develop -minecraft_version = 1.20.4 -yarn_mappings = 1.20.4+build.3 -fabric_loader = 0.15.7 +minecraft_version=1.20.6 +yarn_mappings=1.20.6+build.1 +fabric_loader=0.15.10 -fabric_api = 0.96.11+1.20.4 +fabric_api=0.98.0+1.20.6 -cardinal_components_api = 5.4.0 +cardinal_components_api=6.0.0-beta.3 -server_gui = 1.4.2+1.20.4 -placeholder_api = 2.3.0+1.20.3 -common_protection_api = 1.0.0 -common_economy_api = 1.1.1 -polymer = 0.7.7+1.20.4 +server_gui=1.5.0+1.20.5 +placeholder_api=2.4.0-pre.1+1.20.5 +common_protection_api=1.0.0 +common_economy_api=1.1.1 +polymer=0.8.0-beta.3+1.20.5-rc2 -fantasy = 0.5.0+1.20.4 -server_translations_api = 2.2.0+1.20.3-rc1 -stimuli = 0.4.10+1.20.4 +fantasy=0.6.0+1.20.6 +server_translations_api=2.3.0+1.20.5-rc2 +stimuli=0.4.10+1.20.6-local.1 -fabric_permission_api = 0.2-SNAPSHOT +fabric_permission_api=0.2-SNAPSHOT jankson_version=1.2.2 diff --git a/src/main/java/com/awakenedredstone/neoskies/api/island/SettingsManager.java b/src/main/java/com/awakenedredstone/neoskies/api/island/IslandSettingsManager.java similarity index 75% rename from src/main/java/com/awakenedredstone/neoskies/api/island/SettingsManager.java rename to src/main/java/com/awakenedredstone/neoskies/api/island/IslandSettingsManager.java index a01c118..2c6342e 100644 --- a/src/main/java/com/awakenedredstone/neoskies/api/island/SettingsManager.java +++ b/src/main/java/com/awakenedredstone/neoskies/api/island/IslandSettingsManager.java @@ -3,12 +3,12 @@ import com.awakenedredstone.neoskies.gui.polymer.CBGuiElement; import com.awakenedredstone.neoskies.gui.polymer.CBGuiElementBuilder; import com.awakenedredstone.neoskies.util.MapBuilder; -import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.registry.RegistryKey; import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; +import net.minecraft.text.Style; import net.minecraft.text.Text; import net.minecraft.util.Identifier; import com.awakenedredstone.neoskies.logic.Island; @@ -18,8 +18,8 @@ import java.util.*; @Deprecated //TODO: Replace with just registry -public class SettingsManager { - private static final Map defaultSettings = new HashMap<>(); +public class IslandSettingsManager { + private static final SortedMap defaultSettings = new TreeMap<>(); private static final Map icons = new HashMap<>(); public static boolean registerIcon(Identifier identifier, CBGuiElement icon) { @@ -55,23 +55,17 @@ public static Map getIcons() { public static CBGuiElement getIcon(Identifier identifier, Island island) { CBGuiElementBuilder builder = icons.getOrDefault(identifier, new CBGuiElementBuilder(Items.PAPER).build()).getBuilder(); - builder.hideFlag(ItemStack.TooltipSection.ADDITIONAL) - .hideFlag(ItemStack.TooltipSection.DYE) - .hideFlag(ItemStack.TooltipSection.CAN_DESTROY) - .hideFlag(ItemStack.TooltipSection.CAN_PLACE) - .hideFlag(ItemStack.TooltipSection.ENCHANTMENTS) - .hideFlag(ItemStack.TooltipSection.MODIFIERS) - .hideFlag(ItemStack.TooltipSection.UNBREAKABLE) + builder.hideDefaultTooltip() .setLore(buildLore(island, identifier)) - .setName(Texts.of(identifier.getNamespace() + ".island_settings." + identifier.getPath())) + .setName(Texts.of("island_settings." + identifier.toTranslationKey())) .setCallback((index, type, action, gui) -> { switch (type) { case MOUSE_LEFT -> { - gui.getPlayer().playSound(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1); + gui.getPlayer().playSoundToPlayer(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1); offsetPermission(island.getSettings().get(identifier), 1); } case MOUSE_RIGHT -> { - gui.getPlayer().playSound(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1); + gui.getPlayer().playSoundToPlayer(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1); offsetPermission(island.getSettings().get(identifier), -1); } } @@ -81,7 +75,7 @@ public static CBGuiElement getIcon(Identifier identifier, Island island) { private static List buildLore(Island island, Identifier identifier) { List lore = new ArrayList<>(); - lore.add(Texts.of(identifier.getNamespace() + ".island_settings." + identifier.getPath() + ".description")); + lore.add(Text.empty().setStyle(Style.EMPTY.withItalic(false)).append(Texts.of("island_settings." + identifier.toTranslationKey() + ".description"))); lore.add(Text.empty()); int value = island.getSettings().get(identifier).permissionLevel.getLevel(); List levels = new ArrayList<>(); @@ -93,16 +87,15 @@ private static List buildLore(Island island, Identifier identifier) { Collections.reverse(levels); for (Integer level : levels) { - - Text levelText = Texts.of("text.neoskies.island_settings.level." + level); + Text levelText = Texts.of("island_settings/level." + level); Map placeholders = new MapBuilder() .put("level", levelText) .build(); if (value == level) { - lore.add(Texts.of(Text.translatable("text.neoskies.island_settings.selected"), placeholders)); + lore.add(Text.empty().setStyle(Style.EMPTY.withItalic(false)).append(Texts.of(Text.translatable("island_settings/selected"), placeholders))); } else { - lore.add(Texts.of(Text.translatable("text.neoskies.island_settings.unselected"), placeholders)); + lore.add(Text.empty().setStyle(Style.EMPTY.withItalic(false)).append(Texts.of(Text.translatable("island_settings/unselected"), placeholders))); } } diff --git a/src/main/java/com/awakenedredstone/neoskies/command/SkylandsCommands.java b/src/main/java/com/awakenedredstone/neoskies/command/SkylandsCommands.java index 5e52d34..043690b 100644 --- a/src/main/java/com/awakenedredstone/neoskies/command/SkylandsCommands.java +++ b/src/main/java/com/awakenedredstone/neoskies/command/SkylandsCommands.java @@ -2,15 +2,20 @@ import com.awakenedredstone.neoskies.config.MainConfig; import com.awakenedredstone.neoskies.logic.Skylands; +import com.awakenedredstone.neoskies.util.Texts; import com.mojang.brigadier.CommandDispatcher; import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.ServerCommandSource; import com.awakenedredstone.neoskies.SkylandsMain; import com.awakenedredstone.neoskies.command.admin.*; import com.awakenedredstone.neoskies.command.island.*; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.text.Text; +import java.util.Set; + import static com.awakenedredstone.neoskies.command.utils.CommandUtils.adminNode; import static com.awakenedredstone.neoskies.command.utils.CommandUtils.registerAdmin; @@ -53,11 +58,36 @@ private static void registerAdminCommands(CommandDispatcher registerAdmin(dispatcher, adminNode() .then(CommandManager.literal("reload") .executes(context -> { - context.getSource().sendFeedback(() -> Text.translatable("message.neoskies.reload"), true); + context.getSource().sendFeedback(() -> Texts.prefixed(Text.translatable("commands.neoskies.reload")), true); Skylands.getConfig().load(); return 1; }) ) ); + + registerAdmin(dispatcher, adminNode() + .then(CommandManager.literal("bypass") + .executes(context -> { + ServerCommandSource source = context.getSource(); + if (!source.isExecutedByPlayer()) { + source.sendError(Texts.prefixed(Text.translatable("commands.neoskies.error.player_only"))); + return 0; + } + + ServerPlayerEntity player = source.getPlayer(); + + Set protectionBypass = SkylandsMain.PROTECTION_BYPASS; + boolean overrideMode = protectionBypass.contains(player); + if (overrideMode) { + protectionBypass.remove(player); + source.sendFeedback(() -> Texts.prefixed(Text.translatable("commands.neoskies.admin.bypass.disable")), true); + } else { + protectionBypass.add(player); + source.sendFeedback(() -> Texts.prefixed(Text.translatable("commands.neoskies.admin.bypass.enable")), true); + } + return 1; + }) + ) + ); } } diff --git a/src/main/java/com/awakenedredstone/neoskies/command/island/HubCommands.java b/src/main/java/com/awakenedredstone/neoskies/command/island/HubCommands.java index 1cabf5f..8073717 100644 --- a/src/main/java/com/awakenedredstone/neoskies/command/island/HubCommands.java +++ b/src/main/java/com/awakenedredstone/neoskies/command/island/HubCommands.java @@ -20,36 +20,40 @@ public class HubCommands { public static void init(CommandDispatcher dispatcher) { register(dispatcher, node() - .then(literal("hub") - .requires(Permissions.require("neoskies.teleport.hub", true)) - .executes(context -> { - var source = context.getSource(); - var player = source.getPlayer(); - MinecraftServer server = source.getServer(); - if (player != null) { - HubCommands.visit(player, server); - } - return 1; - }) - ) + .then(literal("hub") + .requires(Permissions.require("neoskies.teleport.hub", true)) + .executes(context -> { + var source = context.getSource(); + var player = source.getPlayer(); + MinecraftServer server = source.getServer(); + if (player != null) { + HubCommands.visit(player, server); + } + return 1; + }) + ) ); registerAdmin(dispatcher, adminNode() - .then(literal("hub").requires(Permissions.require("neoskies.admin.hub", 4)) - .then(literal("pos").requires(Permissions.require("neoskies.admin.hub.pos", 4)) - .then(argument("position", blockPos()).executes(context -> { - var pos = BlockPosArgumentType.getBlockPos(context, "position"); - var source = context.getSource(); - HubCommands.setPos(pos, source); - return 1; - }))) - .then(literal("protection").requires(Permissions.require("neoskies.admin.hub.protection", 4)) - .executes(context -> { - HubCommands.toggleProtection(context.getSource()); - return 1; - }) - ) - ) + .then(literal("hub").requires(Permissions.require("neoskies.admin.hub", 4)) + .then(literal("pos").requires(Permissions.require("neoskies.admin.hub.pos", 4)) + .then(argument("position", blockPos()).executes(context -> { + var pos = BlockPosArgumentType.getBlockPos(context, "position"); + var source = context.getSource(); + HubCommands.setPos(pos, source); + return 1; + })) + ).then(literal("protection").requires(Permissions.require("neoskies.admin.hub.protection", 4)) + .executes(context -> { + HubCommands.toggleProtection(context.getSource()); + return 1; + }) + )/*.then(literal("settings").requires(Permissions.require("neoskies.admin.hub.settings", 4)) + .executes(context -> { + + }) + )*/ + ) ); } diff --git a/src/main/java/com/awakenedredstone/neoskies/command/island/LevelCommand.java b/src/main/java/com/awakenedredstone/neoskies/command/island/LevelCommand.java index 04ced68..97479ec 100644 --- a/src/main/java/com/awakenedredstone/neoskies/command/island/LevelCommand.java +++ b/src/main/java/com/awakenedredstone/neoskies/command/island/LevelCommand.java @@ -98,7 +98,7 @@ private static int view(ServerCommandSource source) { Block block1 = Registries.BLOCK.get(block); ItemStack stack = block1.asItem().getDefaultStack(); GuiElementBuilder builder = GuiElementBuilder.from(stack.isEmpty() ? new ItemStack(Items.BARRIER) : stack) - .hideFlags() + .hideDefaultTooltip() .addLoreLine(Texts.of("x%d blocks".formatted(count))) .addLoreLine(Texts.of("%d points".formatted(points * count))); diff --git a/src/main/java/com/awakenedredstone/neoskies/command/island/MenuCommand.java b/src/main/java/com/awakenedredstone/neoskies/command/island/MenuCommand.java index cce4f59..acad819 100644 --- a/src/main/java/com/awakenedredstone/neoskies/command/island/MenuCommand.java +++ b/src/main/java/com/awakenedredstone/neoskies/command/island/MenuCommand.java @@ -51,7 +51,6 @@ private static int execute(ServerCommandSource source) { } ServerPlayerEntity player = source.getPlayer(); - assert player != null; int permissionLevel = player.getPermissionLevel(); @@ -63,7 +62,7 @@ private static int execute(ServerCommandSource source) { }; final Consumer consumer = slotHolder -> { Optional islandOptional = SkylandsAPI.getIslandByPlayer(player); - UIUtils.fillGui(slotHolder, new CBGuiElementBuilder(Items.BLACK_STAINED_GLASS_PANE).setName(Text.empty()).build()); + UIUtils.fillGui(slotHolder, new CBGuiElementBuilder(Items.BLACK_STAINED_GLASS_PANE).setName(Text.empty()).hideTooltip().build()); if (Permissions.check(player, "neoskies.teleport.hub", true)) { slotHolder.setSlot(10, new CBGuiElementBuilder(Items.BEACON).setName(Texts.of("item_name.neoskies.hub")) .setCallback((index, type, action, gui) -> { @@ -86,7 +85,7 @@ private static int execute(ServerCommandSource source) { if (Permissions.check(player, "neoskies.island.settings", true)) { slotHolder.setSlot(12, new CBGuiElementBuilder(Items.REDSTONE).setName(Texts.of("item_name.neoskies.island_settings")) .setCallback((index, type, action, gui) -> { - gui.getPlayer().playSound(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1); + gui.getPlayer().playSoundToPlayer(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1); new IslandSettingsGui(islandOptional.get(), gui).openGui(player); }) .build()); @@ -94,7 +93,7 @@ private static int execute(ServerCommandSource source) { } else if (Permissions.check(player, "neoskies.island.create", true)) { slotHolder.setSlot(11, new CBGuiElementBuilder(Items.OAK_SAPLING).setName(Texts.of("item_name.neoskies.create")) .setCallback((index, type, action, gui) -> { - gui.getPlayer().playSound(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1); + gui.getPlayer().playSoundToPlayer(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1); CreateCommand.run(player); ref.dirty = true; }) @@ -107,7 +106,7 @@ private static int execute(ServerCommandSource source) { slotHolder.setSlot(slotHolder.getSize() - 2, new CBGuiElementBuilder(item).setName(Texts.of("item_name.neoskies.protection_bypass")) .addLoreLine(Texts.of("text.neoskies.protection_bypass", map -> map.put("value", String.valueOf(overrideMode)))) .setCallback((index, type, action, gui) -> { - gui.getPlayer().playSound(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1); + gui.getPlayer().playSoundToPlayer(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1); if (overrideMode) protectionBypass.remove(player); else protectionBypass.add(player); ref.dirty = true; @@ -135,7 +134,7 @@ private static int execute(ServerCommandSource source) { }); guiBuilder.build(player).open(); - player.playSound(SoundEvents.ENTITY_HORSE_SADDLE, SoundCategory.MASTER, 0.4f, 1.2f); + player.playSoundToPlayer(SoundEvents.ENTITY_HORSE_SADDLE, SoundCategory.MASTER, 0.4f, 1.2f); return 1; } } diff --git a/src/main/java/com/awakenedredstone/neoskies/command/island/SettingCommands.java b/src/main/java/com/awakenedredstone/neoskies/command/island/SettingCommands.java index 6b14fad..a681bb1 100644 --- a/src/main/java/com/awakenedredstone/neoskies/command/island/SettingCommands.java +++ b/src/main/java/com/awakenedredstone/neoskies/command/island/SettingCommands.java @@ -111,7 +111,7 @@ private static int settingsGui(ServerCommandSource source) { Optional optionalIsland = SkylandsAPI.getIslandByPlayer(player); optionalIsland.ifPresentOrElse(island -> { //noinspection DataFlowIssue - player.playSound(SoundEvents.ENTITY_HORSE_SADDLE, SoundCategory.MASTER, 0.4f, 1); + player.playSoundToPlayer(SoundEvents.ENTITY_HORSE_SADDLE, SoundCategory.MASTER, 0.4f, 1); new IslandSettingsGui(island, null).openGui(player); }, () -> source.sendError(Texts.prefixed("message.neoskies.error.missing_island"))); diff --git a/src/main/java/com/awakenedredstone/neoskies/config/MainConfig.java b/src/main/java/com/awakenedredstone/neoskies/config/MainConfig.java index 37fe721..548b68e 100644 --- a/src/main/java/com/awakenedredstone/neoskies/config/MainConfig.java +++ b/src/main/java/com/awakenedredstone/neoskies/config/MainConfig.java @@ -28,6 +28,9 @@ public MainConfig() { @Comment("The mod admin command aliases") public List adminCommandAliases = new ArrayList<>(List.of("skyblockadmin")); + @Comment("Disables spawning lightning and horse traps in the hub") + public boolean disableLightningOnHub = true; + @Comment("Allow the player to visit their own island") public boolean allowVisitCurrentIsland = false; diff --git a/src/main/java/com/awakenedredstone/neoskies/data/PlayerComponent.java b/src/main/java/com/awakenedredstone/neoskies/data/PlayerComponent.java index fb27727..4aa0f0d 100644 --- a/src/main/java/com/awakenedredstone/neoskies/data/PlayerComponent.java +++ b/src/main/java/com/awakenedredstone/neoskies/data/PlayerComponent.java @@ -1,6 +1,7 @@ package com.awakenedredstone.neoskies.data; -import dev.onyxstudios.cca.api.v3.component.ComponentV3; +import net.minecraft.registry.RegistryWrapper; +import org.ladysnake.cca.api.v3.component.ComponentV3; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.nbt.NbtCompound; @@ -33,7 +34,7 @@ public void removeIsland(String owner) { } @Override - public void readFromNbt(NbtCompound tag) { + public void readFromNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { NbtCompound islandsNbt = tag.getCompound("islands"); int size = islandsNbt.getInt("size"); for (int i = 0; i < size; i++) { @@ -43,7 +44,7 @@ public void readFromNbt(NbtCompound tag) { } @Override - public void writeToNbt(NbtCompound tag) { + public void writeToNbt(NbtCompound tag, RegistryWrapper.WrapperLookup registryLookup) { NbtCompound islandsNbt = new NbtCompound(); islandsNbt.putInt("size", this.islands.size()); for (int i = 0; i < this.islands.size(); i++) { diff --git a/src/main/java/com/awakenedredstone/neoskies/data/SkylandComponents.java b/src/main/java/com/awakenedredstone/neoskies/data/SkylandComponents.java index d1c326b..9b2e57e 100644 --- a/src/main/java/com/awakenedredstone/neoskies/data/SkylandComponents.java +++ b/src/main/java/com/awakenedredstone/neoskies/data/SkylandComponents.java @@ -1,9 +1,9 @@ package com.awakenedredstone.neoskies.data; -import dev.onyxstudios.cca.api.v3.component.ComponentKey; -import dev.onyxstudios.cca.api.v3.component.ComponentRegistryV3; -import dev.onyxstudios.cca.api.v3.world.WorldComponentFactoryRegistry; -import dev.onyxstudios.cca.api.v3.world.WorldComponentInitializer; +import org.ladysnake.cca.api.v3.component.ComponentKey; +import org.ladysnake.cca.api.v3.component.ComponentRegistryV3; +import org.ladysnake.cca.api.v3.world.WorldComponentFactoryRegistry; +import org.ladysnake.cca.api.v3.world.WorldComponentInitializer; import com.awakenedredstone.neoskies.SkylandsMain; public class SkylandComponents implements WorldComponentInitializer/*, EntityComponentInitializer*/ { diff --git a/src/main/java/com/awakenedredstone/neoskies/data/WorldComponent.java b/src/main/java/com/awakenedredstone/neoskies/data/WorldComponent.java index c5a3068..aba8403 100644 --- a/src/main/java/com/awakenedredstone/neoskies/data/WorldComponent.java +++ b/src/main/java/com/awakenedredstone/neoskies/data/WorldComponent.java @@ -1,6 +1,7 @@ package com.awakenedredstone.neoskies.data; -import dev.onyxstudios.cca.api.v3.component.ComponentV3; +import net.minecraft.registry.RegistryWrapper; +import org.ladysnake.cca.api.v3.component.ComponentV3; import net.minecraft.nbt.NbtCompound; import net.minecraft.world.World; import org.jetbrains.annotations.NotNull; @@ -9,14 +10,14 @@ public record WorldComponent(World world) implements ComponentV3 { @Override - public void readFromNbt(@NotNull NbtCompound nbt) { + public void readFromNbt(@NotNull NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { if (world.getRegistryKey().equals(World.OVERWORLD)) { Skylands.getInstance().readFromNbt(nbt); } } @Override - public void writeToNbt(@NotNull NbtCompound nbt) { + public void writeToNbt(@NotNull NbtCompound nbt, RegistryWrapper.WrapperLookup registryLookup) { if (world.getRegistryKey().equals(World.OVERWORLD)) { Skylands.getInstance().writeToNbt(nbt); } diff --git a/src/main/java/com/awakenedredstone/neoskies/datagen/NeoSkiesBlockTagProvider.java b/src/main/java/com/awakenedredstone/neoskies/datagen/NeoSkiesBlockTagProvider.java index 2a30851..768319a 100644 --- a/src/main/java/com/awakenedredstone/neoskies/datagen/NeoSkiesBlockTagProvider.java +++ b/src/main/java/com/awakenedredstone/neoskies/datagen/NeoSkiesBlockTagProvider.java @@ -1,15 +1,23 @@ package com.awakenedredstone.neoskies.datagen; -import com.awakenedredstone.neoskies.logic.tags.NeoSkiesBlockTags; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; -import net.fabricmc.fabric.api.tag.convention.v1.ConventionalBlockTags; +import net.fabricmc.fabric.api.tag.convention.v2.ConventionalBlockTags; +import net.minecraft.block.Block; import net.minecraft.block.Blocks; +import net.minecraft.block.Oxidizable; +import net.minecraft.data.DataProvider; +import net.minecraft.item.Item; +import net.minecraft.item.MinecartItem; +import net.minecraft.registry.Registries; import net.minecraft.registry.RegistryWrapper; import net.minecraft.registry.tag.BlockTags; +import net.minecraft.util.Identifier; import java.util.concurrent.CompletableFuture; +import static com.awakenedredstone.neoskies.logic.tags.NeoSkiesBlockTags.*; + public class NeoSkiesBlockTagProvider extends FabricTagProvider.BlockTagProvider { public NeoSkiesBlockTagProvider(FabricDataOutput output, CompletableFuture registriesFuture) { super(output, registriesFuture); @@ -17,23 +25,32 @@ public NeoSkiesBlockTagProvider(FabricDataOutput output, CompletableFuture.FabricTagBuilder unwaxedCopper = getOrCreateTagBuilder(UNWAXED_COPPER_BLOCKS); + FabricTagProvider.FabricTagBuilder waxedCopper = getOrCreateTagBuilder(WAXED_COPPER_BLOCKS); + for (Block block : Registries.BLOCK) { + Identifier id = Registries.BLOCK.getId(block); + boolean waxed = id.getPath().startsWith("waxed_"); + if (block instanceof Oxidizable) { + unwaxedCopper.add(block); + } else if (waxed) { + waxedCopper.add(block); + } + } + + getOrCreateTagBuilder(COPPER_BLOCKS) + .addTag(UNWAXED_COPPER_BLOCKS) + .addTag(WAXED_COPPER_BLOCKS); + + getOrCreateTagBuilder(EXTINGUISHABLE) + .forceAddTag(BlockTags.FIRE) + .forceAddTag(BlockTags.CAMPFIRES) + .forceAddTag(BlockTags.CANDLES) + .forceAddTag(BlockTags.CANDLE_CAKES); + + getOrCreateTagBuilder(OTHERS) + .forceAddTag(BlockTags.CANDLE_CAKES) + .forceAddTag(BlockTags.CANDLES) + .forceAddTag(BlockTags.BANNERS) + .forceAddTag(BlockTags.BEDS) + .add( + Blocks.CAKE, + Blocks.BELL + ); + + getOrCreateTagBuilder(HARVEST) + .forceAddTag(BlockTags.CAVE_VINES) + .add( + Blocks.SWEET_BERRY_BUSH, + Blocks.PUMPKIN + ); + + getOrCreateTagBuilder(SIGNS) + .forceAddTag(BlockTags.SIGNS); } } diff --git a/src/main/java/com/awakenedredstone/neoskies/datagen/NeoSkiesEntityTagProvider.java b/src/main/java/com/awakenedredstone/neoskies/datagen/NeoSkiesEntityTagProvider.java index 9b07524..c8ce0d7 100644 --- a/src/main/java/com/awakenedredstone/neoskies/datagen/NeoSkiesEntityTagProvider.java +++ b/src/main/java/com/awakenedredstone/neoskies/datagen/NeoSkiesEntityTagProvider.java @@ -1,13 +1,15 @@ package com.awakenedredstone.neoskies.datagen; -import com.awakenedredstone.neoskies.logic.tags.NeoSkiesEntityTags; import net.fabricmc.fabric.api.datagen.v1.FabricDataOutput; import net.fabricmc.fabric.api.datagen.v1.provider.FabricTagProvider; +import net.fabricmc.fabric.api.tag.convention.v2.ConventionalEntityTypeTags; import net.minecraft.entity.EntityType; import net.minecraft.registry.RegistryWrapper; import java.util.concurrent.CompletableFuture; +import static com.awakenedredstone.neoskies.logic.tags.NeoSkiesEntityTags.*; + public class NeoSkiesEntityTagProvider extends FabricTagProvider.EntityTypeTagProvider { public NeoSkiesEntityTagProvider(FabricDataOutput output, CompletableFuture registriesFuture) { super(output, registriesFuture); @@ -15,10 +17,39 @@ public NeoSkiesEntityTagProvider(FabricDataOutput output, CompletableFuture registriesFuture) { super(output, registriesFuture); @@ -17,55 +18,48 @@ public NeoSkiesItemTagProvider(FabricDataOutput output, CompletableFuture.FabricTagBuilder blockInteraction = getOrCreateTagBuilder(NeoSkiesItemTags.BLOCK_INTERACTION) + getOrCreateTagBuilder(PLACE) .forceAddTag(ItemTags.AXES) .forceAddTag(ItemTags.HOES) .forceAddTag(ItemTags.SHOVELS) - .forceAddTag(ItemTags.MUSIC_DISCS) .add( Items.ARMOR_STAND, Items.BONE_MEAL, - Items.BRUSH, - Items.COMPASS, Items.DEBUG_STICK, - Items.END_CRYSTAL, Items.ENDER_EYE, - Items.FILLED_MAP, Items.FIRE_CHARGE, - Items.FIREWORK_ROCKET, - Items.FLINT_AND_STEEL, Items.HONEYCOMB, - Items.LEAD, - Items.POWDER_SNOW_BUCKET, - Items.SHEARS + Items.SHEARS, + Items.END_CRYSTAL, + Items.FLINT_AND_STEEL, + Items.POWDER_SNOW_BUCKET ); + var spawner = getOrCreateTagBuilder(SPAWNER); + for (Item item : Registries.ITEM) { - if (item instanceof DecorationItem || - item instanceof MinecartItem || - item instanceof PlaceableOnWaterItem || - item instanceof SpawnEggItem || - item instanceof PotionItem - ) { - blockInteraction.add(item); + if (item instanceof SpawnEggItem) { + spawner.add(item); } } - FabricTagProvider.FabricTagBuilder generalInteraction = getOrCreateTagBuilder(NeoSkiesItemTags.BLOCK_INTERACTION) - .forceAddTag(ItemTags.BOATS) + getOrCreateTagBuilder(CONTAINERS) .add( - Items.ENDER_EYE, + Items.FILLED_MAP, Items.GLASS_BOTTLE ); + getOrCreateTagBuilder(LODESTONE) + .add(Items.COMPASS); + + FabricTagProvider.FabricTagBuilder minecarts = getOrCreateTagBuilder(MINECART); for (Item item : Registries.ITEM) { - if (item instanceof BucketItem || - item instanceof SpawnEggItem - ) { - generalInteraction.add(item); + if (item instanceof MinecartItem) { + minecarts.add(item); } } - + getOrCreateTagBuilder(LEAD) + .add(Items.LEAD); } } diff --git a/src/main/java/com/awakenedredstone/neoskies/event/GenericEntityDamageEvent.java b/src/main/java/com/awakenedredstone/neoskies/event/GenericEntityDamageEvent.java new file mode 100644 index 0000000..58c8613 --- /dev/null +++ b/src/main/java/com/awakenedredstone/neoskies/event/GenericEntityDamageEvent.java @@ -0,0 +1,36 @@ +package com.awakenedredstone.neoskies.event; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.util.ActionResult; +import xyz.nucleoid.stimuli.event.StimulusEvent; + +/** + * Called when a {@link LivingEntity} is damaged. + * + *

Upon return: + *

    + *
  • {@link ActionResult#SUCCESS} cancels further processing and damages the entity. + *
  • {@link ActionResult#FAIL} cancels further processing and does not damage the entity. + *
  • {@link ActionResult#PASS} moves on to the next listener.
+ *

+ * If all listeners return {@link ActionResult#PASS}, the entity is damaged as per normal behavior. + */ +public interface GenericEntityDamageEvent { + StimulusEvent EVENT = StimulusEvent.create(GenericEntityDamageEvent.class, ctx -> (entity, source, amount) -> { + try { + for (var listener : ctx.getListeners()) { + var result = listener.onDamage(entity, source, amount); + if (result != ActionResult.PASS) { + return result; + } + } + } catch (Throwable t) { + ctx.handleException(t); + } + return ActionResult.PASS; + }); + + ActionResult onDamage(Entity entity, DamageSource source, float amount); +} diff --git a/src/main/java/com/awakenedredstone/neoskies/gui/CommonGuiElements.java b/src/main/java/com/awakenedredstone/neoskies/gui/CommonGuiElements.java index 90f288c..a4a611b 100644 --- a/src/main/java/com/awakenedredstone/neoskies/gui/CommonGuiElements.java +++ b/src/main/java/com/awakenedredstone/neoskies/gui/CommonGuiElements.java @@ -8,19 +8,19 @@ import net.minecraft.util.Formatting; public class CommonGuiElements { - private static final GuiElement PURPLE_PLATE = new GuiElementBuilder(Items.PURPLE_STAINED_GLASS_PANE).setName(Text.empty()).build(); - private static final GuiElement WHITE_PLATE = new GuiElementBuilder(Items.WHITE_STAINED_GLASS_PANE).setName(Text.empty()).build(); + private static final GuiElement PURPLE_PLATE = new GuiElementBuilder(Items.PURPLE_STAINED_GLASS_PANE).hideTooltip().setName(Text.empty()).build(); + private static final GuiElement WHITE_PLATE = new GuiElementBuilder(Items.WHITE_STAINED_GLASS_PANE).hideTooltip().setName(Text.empty()).build(); public static GuiElementBuilder nextPage() { return new GuiElementBuilder(Items.PLAYER_HEAD) .setName(Text.translatable("spectatorMenu.next_page").formatted(Formatting.WHITE)) - .hideFlags() + .hideDefaultTooltip() .setSkullOwner("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvYzg2MTg1YjFkNTE5YWRlNTg1ZjE4NGMzNGYzZjNlMjBiYjY0MWRlYjg3OWU4MTM3OGU0ZWFmMjA5Mjg3In19fQ"); } public static GuiElementBuilder previousPage() { return new GuiElementBuilder(Items.PLAYER_HEAD) .setName(Text.translatable("spectatorMenu.previous_page").formatted(Formatting.WHITE)) - .hideFlags() + .hideDefaultTooltip() .setSkullOwner("eyJ0ZXh0dXJlcyI6eyJTS0lOIjp7InVybCI6Imh0dHA6Ly90ZXh0dXJlcy5taW5lY3JhZnQubmV0L3RleHR1cmUvMzEwODI5OGZmMmIyNjk1MWQ2ODNlNWFkZTQ2YTQyZTkwYzJmN2M3ZGQ0MWJhYTkwOGJjNTg1MmY4YzMyZTU4MyJ9fX0"); } diff --git a/src/main/java/com/awakenedredstone/neoskies/gui/IslandSettingsGui.java b/src/main/java/com/awakenedredstone/neoskies/gui/IslandSettingsGui.java index 48642f7..130077e 100644 --- a/src/main/java/com/awakenedredstone/neoskies/gui/IslandSettingsGui.java +++ b/src/main/java/com/awakenedredstone/neoskies/gui/IslandSettingsGui.java @@ -1,5 +1,6 @@ package com.awakenedredstone.neoskies.gui; +import com.awakenedredstone.neoskies.api.island.IslandSettingsManager; import com.awakenedredstone.neoskies.gui.polymer.CBGuiElement; import com.awakenedredstone.neoskies.gui.polymer.CBGuiElementBuilder; import com.awakenedredstone.neoskies.gui.polymer.CBSimpleGuiBuilder; @@ -17,7 +18,6 @@ import net.minecraft.util.math.MathHelper; import org.jetbrains.annotations.Nullable; import com.awakenedredstone.neoskies.api.island.IslandSettings; -import com.awakenedredstone.neoskies.api.island.SettingsManager; import com.awakenedredstone.neoskies.logic.Island; import com.awakenedredstone.neoskies.util.Texts; @@ -33,7 +33,7 @@ public class IslandSettingsGui { private final Consumer simpleUpdateGui; private int page = 0; - private final CBGuiElement filler = new CBGuiElementBuilder(Items.BLACK_STAINED_GLASS_PANE).setName(Text.empty()).build(); + private final CBGuiElement filler = new CBGuiElementBuilder(Items.BLACK_STAINED_GLASS_PANE).setName(Text.empty()).hideTooltip().build(); private final CBGuiElement nextPage = new CBGuiElementBuilder(Items.LIME_STAINED_GLASS_PANE).setName(Texts.of("neoskies.page.next")).setCallback((index, type, action, gui) -> offsetPage(1, gui)).build(); private final CBGuiElement prevPage = new CBGuiElementBuilder(Items.RED_STAINED_GLASS_PANE).setName(Texts.of("neoskies.page.previous")).setCallback((index, type, action, gui) -> offsetPage(-1, gui)).build(); @@ -49,11 +49,11 @@ public IslandSettingsGui(Island island, @Nullable GuiInterface parent) { gui.setTitle(Texts.of("gui.neoskies.island_settings")); int slot = 10; - int offset = page * 24; - for (int i = offset; i < Math.min(offset + 24, island.getSettings().size()); i++) { + int offset = page * 28; + for (int i = offset; i < Math.min(offset + 28, island.getSettings().size()); i++) { if ((slot + 1) % 9 == 0 && slot > 10) slot += 2; Map.Entry pageEntry = entries.get(i); - gui.setSlot(slot++, SettingsManager.getIcon(pageEntry.getKey(), island)); + gui.setSlot(slot++, IslandSettingsManager.getIcon(pageEntry.getKey(), island)); } if (page < getPageMax()) gui.setSlot(gui.getSize() - 8, nextPage); @@ -62,7 +62,7 @@ public IslandSettingsGui(Island island, @Nullable GuiInterface parent) { CBGuiElementBuilder close = new CBGuiElementBuilder(Items.BARRIER) .setName(Texts.of("gui.neoskies.close")) .setCallback((index, type, action, gui1) -> { - gui.getPlayer().playSound(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1); + gui.getPlayer().playSoundToPlayer(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1); if (parent != null) { parent.close(); parent.open(); @@ -73,11 +73,11 @@ public IslandSettingsGui(Island island, @Nullable GuiInterface parent) { simpleUpdateGui = gui -> { int slot = 10; - int offset = page * 24; - for (int i = offset; i < Math.min(offset + 24, island.getSettings().size()); i++) { + int offset = page * 28; + for (int i = offset; i < Math.min(offset + 28, island.getSettings().size()); i++) { if ((slot + 1) % 9 == 0 && slot > 10) slot += 2; Map.Entry pageEntry = entries.get(i); - gui.setSlot(slot++, SettingsManager.getIcon(pageEntry.getKey(), island)); + gui.setSlot(slot++, IslandSettingsManager.getIcon(pageEntry.getKey(), island)); } }; } @@ -97,12 +97,12 @@ public void openGui(ServerPlayerEntity player) { } public void offsetPage(int offset, SlotGuiInterface gui) { - gui.getPlayer().playSound(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1); - this.page = (int) MathHelper.clamp(this.page + offset, 0, Math.floor(island.getSettings().size() / 24f)); + gui.getPlayer().playSoundToPlayer(SoundEvents.UI_BUTTON_CLICK.value(), SoundCategory.MASTER, 0.3f, 1); + this.page = (int) MathHelper.clamp(this.page + offset, 0, Math.floor(island.getSettings().size() / 28f)); updateGui.accept(gui); } private int getPageMax() { - return (int) Math.ceil(island.getSettings().size() / 24f) - 1; + return (int) Math.ceil(island.getSettings().size() / 28f) - 1; } } diff --git a/src/main/java/com/awakenedredstone/neoskies/gui/PagedGui.java b/src/main/java/com/awakenedredstone/neoskies/gui/PagedGui.java index c1eb568..2586fa5 100644 --- a/src/main/java/com/awakenedredstone/neoskies/gui/PagedGui.java +++ b/src/main/java/com/awakenedredstone/neoskies/gui/PagedGui.java @@ -117,7 +117,7 @@ public record DisplayElement(@Nullable GuiElementInterface element, @Nullable Sl private static final DisplayElement FILLER = DisplayElement.of( new GuiElementBuilder(Items.WHITE_STAINED_GLASS_PANE) .setName(Text.empty()) - .hideFlags() + .hideDefaultTooltip() ); public static DisplayElement of(GuiElementInterface element) { @@ -144,7 +144,7 @@ public static DisplayElement nextPage(PagedGui gui) { return DisplayElement.of( new GuiElementBuilder(Items.PLAYER_HEAD) .setName(Text.translatable("spectatorMenu.next_page").formatted(Formatting.DARK_GRAY)) - .hideFlags() + .hideDefaultTooltip() .setSkullOwner(SkinEncoder.encode("7e57720a4878c8bcab0e9c9c47d9e55128ccd77ba3445a54a91e3e1e1a27356e")) ); } @@ -163,7 +163,7 @@ public static DisplayElement previousPage(PagedGui gui) { return DisplayElement.of( new GuiElementBuilder(Items.PLAYER_HEAD) .setName(Text.translatable("spectatorMenu.previous_page").formatted(Formatting.DARK_GRAY)) - .hideFlags() + .hideDefaultTooltip() .setSkullOwner(SkinEncoder.encode("50820f76e3e041c75f76d0f301232bdf48321b534fe6a859ccb873d2981a9623")) ); } @@ -179,7 +179,7 @@ public static DisplayElement empty() { } public static void playSound(ServerPlayerEntity player, SoundEvent sound) { - player.playSound(sound, SoundCategory.MASTER, 1, 1); + player.playSoundToPlayer(sound, SoundCategory.MASTER, 1, 1); } public static void playClickSound(ServerPlayerEntity player) { diff --git a/src/main/java/com/awakenedredstone/neoskies/gui/polymer/CBGuiElementBuilder.java b/src/main/java/com/awakenedredstone/neoskies/gui/polymer/CBGuiElementBuilder.java index ff91b05..48dda94 100644 --- a/src/main/java/com/awakenedredstone/neoskies/gui/polymer/CBGuiElementBuilder.java +++ b/src/main/java/com/awakenedredstone/neoskies/gui/polymer/CBGuiElementBuilder.java @@ -2,96 +2,77 @@ import com.mojang.authlib.GameProfile; import com.mojang.authlib.minecraft.MinecraftProfileTextures; +import com.mojang.authlib.properties.Property; +import com.mojang.authlib.properties.PropertyMap; +import eu.pb4.sgui.api.elements.GuiElement; import eu.pb4.sgui.api.elements.GuiElementBuilder; import eu.pb4.sgui.api.elements.GuiElementInterface; +import net.minecraft.component.DataComponentType; +import net.minecraft.component.DataComponentTypes; +import net.minecraft.component.type.CustomModelDataComponent; +import net.minecraft.component.type.LoreComponent; +import net.minecraft.component.type.ProfileComponent; +import net.minecraft.component.type.UnbreakableComponent; import net.minecraft.enchantment.Enchantment; -import net.minecraft.enchantment.Enchantments; import net.minecraft.item.Item; import net.minecraft.item.ItemStack; -import net.minecraft.nbt.NbtCompound; -import net.minecraft.nbt.NbtElement; -import net.minecraft.nbt.NbtHelper; -import net.minecraft.nbt.NbtList; -import net.minecraft.registry.Registries; import net.minecraft.server.MinecraftServer; -import net.minecraft.text.MutableText; import net.minecraft.text.Text; -import net.minecraft.util.Identifier; -import net.minecraft.util.Util; +import net.minecraft.util.Rarity; +import net.minecraft.util.Unit; import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import java.util.List; +import java.util.Optional; import java.util.UUID; +import java.util.function.Consumer; -public class CBGuiElementBuilder extends eu.pb4.sgui.api.elements.GuiElementBuilder { +public class CBGuiElementBuilder extends GuiElementBuilder { /** - * Constructs a GuiElementBuilder with the default options + * Constructs a CBGuiElementBuilder with the default options */ - public CBGuiElementBuilder() {} + public CBGuiElementBuilder() { + } /** - * Constructs a GuiElementBuilder with the specified Item. + * Constructs a CBGuiElementBuilder with the specified Item. * * @param item the item to use */ public CBGuiElementBuilder(Item item) { - super(item); + this.itemStack = new ItemStack(item); } /** - * Constructs a GuiElementBuilder with the specified Item + * Constructs a CBGuiElementBuilder with the specified Item * and number of items. * * @param item the item to use * @param count the number of items */ public CBGuiElementBuilder(Item item, int count) { - super(item, count); + this.itemStack = new ItemStack(item, count); } /** - * Constructs a GuiElementBuilder based on the supplied stack. + * Constructs a CBGuiElementBuilder with the specified ItemStack + * + * @param stack the item stack to use + */ + public CBGuiElementBuilder(ItemStack stack) { + this.itemStack = stack.copy(); + } + + /** + * Constructs a CBGuiElementBuilder based on the supplied stack. * * @param stack the stack to base the builder of * @return the constructed builder */ - @NotNull - public static CBGuiElementBuilder from(@NotNull ItemStack stack) { - CBGuiElementBuilder builder = new CBGuiElementBuilder(stack.getItem(), stack.getCount()); - NbtCompound tag = stack.getOrCreateNbt().copy(); - - if (stack.hasCustomName()) { - builder.setName((MutableText) stack.getName()); - tag.getCompound("display").remove("Name"); - } - - if (tag.contains("display") && tag.getCompound("display").contains("Lore")) { - builder.setLore(CBGuiElementBuilder.getLore(stack)); - tag.getCompound("display").remove("Lore"); - } - - if (stack.isDamaged()) { - builder.setDamage(stack.getDamage()); - tag.remove("Damage"); - } - - if (stack.hasEnchantments()) { - for (NbtElement enc : stack.getEnchantments()) { - Registries.ENCHANTMENT.getOrEmpty(Identifier.tryParse(((NbtCompound) enc).getString("id"))).ifPresent(enchantment -> builder.enchant(enchantment, ((NbtCompound) enc).getInt("lvl"))); - } - tag.remove("Enchantments"); - } - - if (stack.getOrCreateNbt().contains("HideFlags")) { - builder.hideFlags(stack.getOrCreateNbt().getByte("HideFlags")); - tag.remove("HideFlags"); - } - - builder.tag = tag; - - return builder; + public static CBGuiElementBuilder from(ItemStack stack) { + return new CBGuiElementBuilder(stack); } @NotNull @@ -107,6 +88,15 @@ public static CBGuiElementBuilder fromSimple(@NotNull CBGuiElement element) { return from(element.getItemStack()); } + public ItemStack getItemStack() { + return itemStack; + } + + @Deprecated + public static List getLore(ItemStack stack) { + return stack.getOrDefault(DataComponentTypes.LORE, LoreComponent.DEFAULT).lines(); + } + /** * Sets the type of Item of the element. * @@ -114,7 +104,7 @@ public static CBGuiElementBuilder fromSimple(@NotNull CBGuiElement element) { * @return this element builder */ public CBGuiElementBuilder setItem(Item item) { - this.item = item; + this.itemStack = new ItemStack(item.getRegistryEntry(), this.itemStack.getCount(), this.itemStack.getComponentChanges()); return this; } @@ -124,8 +114,19 @@ public CBGuiElementBuilder setItem(Item item) { * @param name the name to use * @return this element builder */ - public CBGuiElementBuilder setName(@NotNull Text name) { - this.name = name.copy(); + public CBGuiElementBuilder setName(Text name) { + this.itemStack.set(DataComponentTypes.ITEM_NAME, name.copy()); + return this; + } + + /** + * Sets the rarity of the element. + * + * @param rarity to use + * @return this element builder + */ + public CBGuiElementBuilder setRarity(Rarity rarity) { + this.itemStack.set(DataComponentTypes.RARITY, rarity); return this; } @@ -136,7 +137,19 @@ public CBGuiElementBuilder setName(@NotNull Text name) { * @return this element builder */ public CBGuiElementBuilder setCount(int count) { - this.count = count; + this.itemStack.setCount(count); + return this; + } + + + /** + * Sets the max number of items in the element. + * + * @param count the number of items + * @return this element builder + */ + public CBGuiElementBuilder setMaxCount(int count) { + this.itemStack.set(DataComponentTypes.MAX_STACK_SIZE, count); return this; } @@ -147,7 +160,7 @@ public CBGuiElementBuilder setCount(int count) { * @return this element builder */ public CBGuiElementBuilder setLore(List lore) { - this.lore = lore; + this.itemStack.set(DataComponentTypes.LORE, new LoreComponent(lore)); return this; } @@ -158,7 +171,7 @@ public CBGuiElementBuilder setLore(List lore) { * @return this element builder */ public CBGuiElementBuilder addLoreLine(Text lore) { - this.lore.add(lore); + this.itemStack.apply(DataComponentTypes.LORE, LoreComponent.DEFAULT, lore, LoreComponent::with); return this; } @@ -170,42 +183,63 @@ public CBGuiElementBuilder addLoreLine(Text lore) { * @return this element builder */ public CBGuiElementBuilder setDamage(int damage) { - this.damage = damage; + this.itemStack.set(DataComponentTypes.DAMAGE, damage); return this; } /** - * Hides all {@link ItemStack.TooltipSection}s from the element display + * Set the max damage of the element. * + * @param damage the amount of durability the item is missing * @return this element builder */ - public CBGuiElementBuilder hideFlags() { - this.hideFlags = 127; + public CBGuiElementBuilder setMaxDamage(int damage) { + this.itemStack.set(DataComponentTypes.MAX_DAMAGE, damage); return this; } /** - * Hides a {@link ItemStack.TooltipSection} - * from the elements display. - * - * @param section the section to hide + * Disables all default components on an item. * @return this element builder */ - public CBGuiElementBuilder hideFlag(@NotNull ItemStack.TooltipSection section) { - this.hideFlags = (byte) (this.hideFlags | section.getFlag()); + public CBGuiElementBuilder noDefaults() { + for (var x : this.itemStack.getItem().getComponents()) { + if (this.itemStack.get(x.type()) == x.value()) { + this.itemStack.set(x.type(), null); + } + } + return this; + } + + public CBGuiElementBuilder setComponent(DataComponentType type, @Nullable T value) { + this.itemStack.set(type, value); return this; } /** - * Set the {@link ItemStack.TooltipSection}s to - * hide from the elements display, by the flags. + * Hides all component-item related tooltip added by item's or non name/lore components. * - * @param value the flags to hide * @return this element builder - * @see CBGuiElementBuilder#hideFlag(ItemStack.TooltipSection) */ - public CBGuiElementBuilder hideFlags(byte value) { - this.hideFlags = value; + public CBGuiElementBuilder hideDefaultTooltip() { + this.itemStack.apply(DataComponentTypes.TRIM, null, comp -> comp != null ? comp.withShowInTooltip(false) : null); + this.itemStack.apply(DataComponentTypes.UNBREAKABLE, null, comp -> comp != null ? comp.withShowInTooltip(false) : null); + this.itemStack.apply(DataComponentTypes.ENCHANTMENTS, null, comp -> comp != null ? comp.withShowInTooltip(false) : null); + this.itemStack.apply(DataComponentTypes.STORED_ENCHANTMENTS, null, comp -> comp != null ? comp.withShowInTooltip(false) : null); + this.itemStack.apply(DataComponentTypes.ATTRIBUTE_MODIFIERS, null, comp -> comp != null ? comp.withShowInTooltip(false) : null); + this.itemStack.apply(DataComponentTypes.DYED_COLOR, null, comp -> comp != null ? comp.withShowInTooltip(false) : null); + this.itemStack.apply(DataComponentTypes.CAN_BREAK, null, comp -> comp != null ? comp.withShowInTooltip(false) : null); + this.itemStack.apply(DataComponentTypes.CAN_PLACE_ON, null, comp -> comp != null ? comp.withShowInTooltip(false) : null); + this.itemStack.set(DataComponentTypes.HIDE_ADDITIONAL_TOOLTIP, Unit.INSTANCE); + return this; + } + + /** + * Hides tooltip completely, making it never show + * @return this element builder + */ + public CBGuiElementBuilder hideTooltip() { + this.itemStack.set(DataComponentTypes.HIDE_TOOLTIP, Unit.INSTANCE); return this; } @@ -217,7 +251,7 @@ public CBGuiElementBuilder hideFlags(byte value) { * @return this element builder */ public CBGuiElementBuilder enchant(Enchantment enchantment, int level) { - this.enchantments.put(enchantment, level); + this.itemStack.addEnchantment(enchantment, level); return this; } @@ -227,8 +261,18 @@ public CBGuiElementBuilder enchant(Enchantment enchantment, int level) { * @return this element builder */ public CBGuiElementBuilder glow() { - this.enchantments.put(Enchantments.LUCK_OF_THE_SEA, 1); - return hideFlag(ItemStack.TooltipSection.ENCHANTMENTS); + this.itemStack.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, true); + return this; + } + + /** + * Sets the element to have an enchantment glint. + * + * @return this element builder + */ + public CBGuiElementBuilder glow(boolean value) { + this.itemStack.set(DataComponentTypes.ENCHANTMENT_GLINT_OVERRIDE, value); + return this; } /** @@ -238,7 +282,7 @@ public CBGuiElementBuilder glow() { * @return this element builder */ public CBGuiElementBuilder setCustomModelData(int value) { - this.getOrCreateNbt().putInt("CustomModelData", value); + this.itemStack.set(DataComponentTypes.CUSTOM_MODEL_DATA, new CustomModelDataComponent(value)); return this; } @@ -248,8 +292,8 @@ public CBGuiElementBuilder setCustomModelData(int value) { * @return this element builder */ public CBGuiElementBuilder unbreakable() { - this.getOrCreateNbt().putBoolean("Unbreakable", true); - return hideFlag(ItemStack.TooltipSection.UNBREAKABLE); + this.itemStack.set(DataComponentTypes.UNBREAKABLE, new UnbreakableComponent(true)); + return this; } /** @@ -264,7 +308,7 @@ public CBGuiElementBuilder unbreakable() { * @param server the server instance, used to get the textures * @return this element builder */ - public GuiElementBuilder setSkullOwner(GameProfile profile, @Nullable MinecraftServer server) { + public CBGuiElementBuilder setSkullOwner(GameProfile profile, @Nullable MinecraftServer server) { if (profile.getId() != null && server != null) { if (server.getSessionService().getTextures(profile) == MinecraftProfileTextures.EMPTY) { var tmp = server.getSessionService().fetchProfile(profile.getId(), false); @@ -273,10 +317,8 @@ public GuiElementBuilder setSkullOwner(GameProfile profile, @Nullable MinecraftS } } - this.getOrCreateNbt().put("SkullOwner", NbtHelper.writeGameProfile(new NbtCompound(), profile)); - } else { - this.getOrCreateNbt().putString("SkullOwner", profile.getName()); } + this.itemStack.set(DataComponentTypes.PROFILE, new ProfileComponent(profile)); return this; } @@ -303,28 +345,14 @@ public CBGuiElementBuilder setSkullOwner(String value) { * @return this element builder */ public CBGuiElementBuilder setSkullOwner(String value, @Nullable String signature, @Nullable UUID uuid) { - NbtCompound skullOwner = new NbtCompound(); - NbtCompound properties = new NbtCompound(); - NbtCompound valueData = new NbtCompound(); - NbtList textures = new NbtList(); - - valueData.putString("Value", value); - if (signature != null) { - valueData.putString("Signature", signature); - } - - textures.add(valueData); - properties.put("textures", textures); - - skullOwner.put("Id", NbtHelper.fromUuid(uuid != null ? uuid : Util.NIL_UUID)); - skullOwner.put("Properties", properties); - this.getOrCreateNbt().put("SkullOwner", skullOwner); - + PropertyMap map = new PropertyMap(); + map.put("textures", new Property("textures", value, signature)); + this.itemStack.set(DataComponentTypes.PROFILE, new ProfileComponent(Optional.empty(), Optional.ofNullable(uuid), map)); return this; } @Override - public CBGuiElementBuilder setCallback(CBGuiElement.ClickCallback callback) { + public CBGuiElementBuilder setCallback(GuiElement.ClickCallback callback) { this.callback = callback; return this; } diff --git a/src/main/java/com/awakenedredstone/neoskies/logic/Island.java b/src/main/java/com/awakenedredstone/neoskies/logic/Island.java index d9a512d..b380615 100644 --- a/src/main/java/com/awakenedredstone/neoskies/logic/Island.java +++ b/src/main/java/com/awakenedredstone/neoskies/logic/Island.java @@ -1,5 +1,6 @@ package com.awakenedredstone.neoskies.logic; +import com.awakenedredstone.neoskies.api.island.IslandSettingsManager; import eu.pb4.common.economy.api.EconomyAccount; import net.minecraft.block.Block; import net.minecraft.entity.player.PlayerEntity; @@ -16,6 +17,7 @@ import net.minecraft.util.math.Vec3d; import net.minecraft.util.math.random.RandomSeed; import net.minecraft.world.Difficulty; +import net.minecraft.world.GameRules; import net.minecraft.world.biome.BiomeKeys; import net.minecraft.world.dimension.DimensionTypes; import net.minecraft.world.gen.chunk.FlatChunkGenerator; @@ -25,7 +27,6 @@ import com.awakenedredstone.neoskies.api.events.IslandEvents; import com.awakenedredstone.neoskies.api.island.IslandSettings; import com.awakenedredstone.neoskies.api.island.PermissionLevel; -import com.awakenedredstone.neoskies.api.island.SettingsManager; import com.awakenedredstone.neoskies.logic.economy.SkylandsEconomyAccount; import com.awakenedredstone.neoskies.util.Constants; import com.awakenedredstone.neoskies.util.Players; @@ -139,7 +140,7 @@ public static Island fromNbt(NbtCompound nbt) { island.blocks.put(new Identifier(key), amount); }); - SettingsManager.update(island.settings); + IslandSettingsManager.update(island.settings); //TODO: Load gamerules into island @@ -192,7 +193,7 @@ public NbtCompound toNbt() { } nbt.put("bans", bansNbt); - SettingsManager.update(this.settings); + IslandSettingsManager.update(this.settings); NbtCompound settingsNbt = new NbtCompound(); this.settings.forEach((identifier, settings) -> { NbtCompound settingsDataNbt = new NbtCompound(); @@ -206,7 +207,7 @@ public NbtCompound toNbt() { this.blocks.forEach((block, amount) -> blocksNbt.putInt(block.toString(), amount)); nbt.put("blocks", blocksNbt); - nbt.put("game_rules", getOverworld().getGameRules().toNbt()); + //nbt.put("game_rules", getOverworld().getGameRules().toNbt()); return nbt; } @@ -281,7 +282,7 @@ public Map getSettings() { } public IslandSettings getSettings(Identifier identifier) { - return settings.computeIfAbsent(identifier, id -> SettingsManager.getDefaultSettings().get(id)); + return settings.computeIfAbsent(identifier, id -> IslandSettingsManager.getDefaultSettings().get(id)); } public boolean isInteractionAllowed(Identifier identifier, PermissionLevel source) { @@ -301,11 +302,12 @@ private RuntimeWorldConfig createIslandConfig() { FlatChunkGenerator generator = new FlatChunkGenerator(flat); return new RuntimeWorldConfig() - .setDimensionType(DimensionTypes.OVERWORLD) - .setGenerator(generator) - .setDifficulty(Difficulty.NORMAL) - .setShouldTickTime(true) - .setSeed(0L); + .setDimensionType(DimensionTypes.OVERWORLD) + .setGenerator(generator) + .setMirrorOverworldDifficulty(true) + .setMirrorOverworldGameRules(true) + .setShouldTickTime(true) + .setSeed(0L); } public RuntimeWorldHandle getNetherHandler() { @@ -321,11 +323,11 @@ private RuntimeWorldConfig createNetherConfig() { FlatChunkGenerator generator = new FlatChunkGenerator(flat); return new RuntimeWorldConfig() - .setDimensionType(DimensionTypes.THE_NETHER) - .setGenerator(generator) - .setDifficulty(Difficulty.NORMAL) - .setShouldTickTime(false) - .setSeed(RandomSeed.getSeed()); + .setDimensionType(DimensionTypes.THE_NETHER) + .setGenerator(generator) + .setDifficulty(Difficulty.NORMAL) + .setShouldTickTime(false) + .setSeed(RandomSeed.getSeed()); } public RuntimeWorldHandle getEndHandler() { @@ -341,11 +343,11 @@ private RuntimeWorldConfig createEndConfig() { FlatChunkGenerator generator = new FlatChunkGenerator(flat); return new RuntimeWorldConfig() - .setDimensionType(DimensionTypes.THE_END) - .setGenerator(generator) - .setDifficulty(Difficulty.NORMAL) - .setShouldTickTime(false) - .setSeed(RandomSeed.getSeed()); + .setDimensionType(DimensionTypes.THE_END) + .setGenerator(generator) + .setDifficulty(Difficulty.NORMAL) + .setShouldTickTime(false) + .setSeed(RandomSeed.getSeed()); } public ServerWorld getOverworld() { @@ -383,9 +385,9 @@ public void visit(PlayerEntity player, Vec3d pos) { ServerWorld world = this.getOverworld(); player.teleport(world, pos.getX(), pos.getY(), pos.getZ(), Set.of(), 0, 0); - if(!isMember(player)) { + if (!isMember(player)) { Players.get(this.owner.name).ifPresent(owner -> { - if(!player.getUuid().equals(owner.getUuid())) { + if (!player.getUuid().equals(owner.getUuid())) { owner.sendMessage(Texts.prefixed("message.neoskies.island_visit.visit", map -> map.put("visitor", player.getName().getString()))); } }); diff --git a/src/main/java/com/awakenedredstone/neoskies/logic/SkylandsEventListeners.java b/src/main/java/com/awakenedredstone/neoskies/logic/SkylandsEventListeners.java index 7c48e8c..29878cc 100644 --- a/src/main/java/com/awakenedredstone/neoskies/logic/SkylandsEventListeners.java +++ b/src/main/java/com/awakenedredstone/neoskies/logic/SkylandsEventListeners.java @@ -1,11 +1,10 @@ package com.awakenedredstone.neoskies.logic; import com.awakenedredstone.neoskies.api.SkylandsAPI; -import com.awakenedredstone.neoskies.event.PlayerConnectEvent; -import com.awakenedredstone.neoskies.event.PlayerEvents; -import com.awakenedredstone.neoskies.event.ServerEventListener; +import com.awakenedredstone.neoskies.event.*; import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; import com.awakenedredstone.neoskies.logic.settings.IslandSettings; +import com.awakenedredstone.neoskies.logic.tags.NeoSkiesItemTags; import com.awakenedredstone.neoskies.util.ServerUtils; import com.awakenedredstone.neoskies.util.WorldProtection; import com.awakenedredstone.neoskies.util.Worlds; @@ -14,7 +13,11 @@ import net.fabricmc.fabric.api.networking.v1.ServerPlayConnectionEvents; import net.minecraft.block.Block; import net.minecraft.block.BlockState; +import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.Ownable; +import net.minecraft.entity.damage.DamageSource; import net.minecraft.entity.mob.Monster; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.ItemStack; @@ -24,12 +27,11 @@ import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.Vec3d; import net.minecraft.world.World; import xyz.nucleoid.stimuli.Stimuli; -import xyz.nucleoid.stimuli.event.block.BlockBreakEvent; -import xyz.nucleoid.stimuli.event.block.BlockPlaceEvent; -import xyz.nucleoid.stimuli.event.block.BlockTrampleEvent; -import xyz.nucleoid.stimuli.event.block.BlockUseEvent; +import xyz.nucleoid.stimuli.event.block.*; +import xyz.nucleoid.stimuli.event.entity.EntityDamageEvent; import xyz.nucleoid.stimuli.event.entity.EntityShearEvent; import xyz.nucleoid.stimuli.event.entity.EntityUseEvent; import xyz.nucleoid.stimuli.event.player.PlayerAttackEntityEvent; @@ -52,10 +54,16 @@ public static void registerEvents() { } }); - Stimuli.global().listen(BlockUseEvent.EVENT, (player, hand, hitResult) -> { + /*Stimuli.global().listen(BlockUseEvent.EVENT, (player, hand, hitResult) -> { World world = player.getWorld(); + ItemStack stack = player.getStackInHand(hand); + if (!stack.isEmpty() && player.isSneaking()) { + return ActionResult.PASS; + } + BlockPos pos = hitResult.getBlockPos(); BlockState state = world.getBlockState(pos); + IslandSettings settings = null; for (Map.Entry, IslandSettings> entry : NeoSkiesIslandSettings.getRuleBlockTags().entrySet()) { @@ -71,16 +79,18 @@ public static void registerEvents() { if (!WorldProtection.canModify(world, pos, player, settings)) { ServerUtils.protectionWarning(player, settings.getTranslationKey()); + int slot = hand == Hand.MAIN_HAND ? player.getInventory().selectedSlot : 40; + player.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(ScreenHandlerSlotUpdateS2CPacket.UPDATE_PLAYER_INVENTORY_SYNC_ID, 0, slot, stack)); return ActionResult.FAIL; } return ActionResult.PASS; - }); + });*/ Stimuli.global().listen(BlockPlaceEvent.BEFORE, (player, world, pos, state, context) -> { BlockPos blockPos = context.getBlockPos().offset(context.getSide()); if (!WorldProtection.canModify(world, blockPos, player, NeoSkiesIslandSettings.PLACE_BLOCKS)) { - ServerUtils.protectionWarning(player, "neoskies.place_blocks"); + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.PLACE_BLOCKS); int slot = context.getHand() == Hand.MAIN_HAND ? player.getInventory().selectedSlot : 40; var stack = context.getStack(); player.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(ScreenHandlerSlotUpdateS2CPacket.UPDATE_PLAYER_INVENTORY_SYNC_ID, 0, slot, stack)); @@ -91,7 +101,7 @@ public static void registerEvents() { Stimuli.global().listen(BlockBreakEvent.EVENT, (player, world, pos) -> { if (!WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.BREAK_BLOCKS)) { - ServerUtils.protectionWarning(player, "neoskies.break_blocks"); + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.BREAK_BLOCKS); return ActionResult.FAIL; } return ActionResult.PASS; @@ -99,25 +109,17 @@ public static void registerEvents() { Stimuli.global().listen(BlockTrampleEvent.EVENT, (entity, world, pos, from, to) -> { if (entity instanceof PlayerEntity player && !WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.BREAK_BLOCKS)) { - ServerUtils.protectionWarning(player, "neoskies.break_blocks"); + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.BREAK_BLOCKS); return ActionResult.FAIL; } return ActionResult.PASS; }); - Stimuli.global().listen(PlayerAttackEntityEvent.EVENT, (attacker, hand, attacked, hitResult) -> { - boolean monster = attacked instanceof Monster; - IslandSettings rule = monster ? NeoSkiesIslandSettings.HURT_HOSTILE : NeoSkiesIslandSettings.HURT_PASSIVE; - if (!WorldProtection.canModify(attacker.getWorld(), attacked.getBlockPos(), attacker, rule)) { - ServerUtils.protectionWarning(attacker, monster ? "neoskies.hurt_hostile" : "neoskies.hurt_passive"); - return ActionResult.FAIL; - } - return ActionResult.PASS; - }); + Stimuli.global().listen(GenericEntityDamageEvent.EVENT, SkylandsEventListeners::onEntityDamage); Stimuli.global().listen(EntityShearEvent.EVENT, (entity, player, hand, pos) -> { if (!WorldProtection.canModify(player.getWorld(), pos, player, NeoSkiesIslandSettings.SHEAR_ENTITY)) { - ServerUtils.protectionWarning(player, "entity_shear"); + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.SHEAR_ENTITY); return ActionResult.FAIL; } return ActionResult.PASS; @@ -127,19 +129,52 @@ public static void registerEvents() { for (Map.Entry>, IslandSettings> entry : NeoSkiesIslandSettings.getRuleEntityTags().entrySet()) { if (entity.getType().isIn(entry.getKey())) { if (!WorldProtection.canModify(player.getWorld(), entity.getBlockPos(), player, entry.getValue())) { - ServerUtils.protectionWarning(player, entry.getValue().getTranslationKey()); + ServerUtils.protectionWarning(player, entry.getValue()); return ActionResult.FAIL; } } } ItemStack stack = player.getStackInHand(hand); - if (stack.isOf(Items.LEAD) && !WorldProtection.canModify(player.getWorld(), entity.getBlockPos(), player, NeoSkiesIslandSettings.LEASH_ENTITY)) { - ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.LEASH_ENTITY.getTranslationKey()); + if (stack.isIn(NeoSkiesItemTags.LEAD) && !WorldProtection.canModify(player.getWorld(), entity.getBlockPos(), player, NeoSkiesIslandSettings.LEASH_ENTITY)) { + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.LEASH_ENTITY); + return ActionResult.FAIL; + } + + return ActionResult.PASS; + }); + + Stimuli.global().listen(FlowerPotModifyEvent.EVENT, (player, hand, hitResult) -> { + if (!WorldProtection.canModify(player.getWorld(), hitResult.getBlockPos(), player, NeoSkiesIslandSettings.PLACE_BLOCKS)) { + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.PLACE_BLOCKS); return ActionResult.FAIL; } return ActionResult.PASS; }); } + + private static ActionResult onEntityDamage(Entity entity, DamageSource source, float amount) { + PlayerEntity player = null; + Entity attacker = source.getAttacker(); + + if (attacker instanceof PlayerEntity) { + player = (PlayerEntity) attacker; + } else if (attacker instanceof Ownable ownable && ownable.getOwner() instanceof PlayerEntity owner) { + player = owner; + } + + if (player == null) { + return ActionResult.PASS; + } + + boolean monster = entity instanceof Monster; + IslandSettings rule = monster ? NeoSkiesIslandSettings.HURT_HOSTILE : NeoSkiesIslandSettings.HURT_PASSIVE; + if (!WorldProtection.canModify(attacker.getWorld(), entity.getBlockPos(), player, rule)) { + ServerUtils.protectionWarning(player, rule); + return ActionResult.FAIL; + } + + return ActionResult.PASS; + } } diff --git a/src/main/java/com/awakenedredstone/neoskies/logic/protection/SkylandsProtectionProvider.java b/src/main/java/com/awakenedredstone/neoskies/logic/protection/SkylandsProtectionProvider.java index bc9c24d..02fa434 100644 --- a/src/main/java/com/awakenedredstone/neoskies/logic/protection/SkylandsProtectionProvider.java +++ b/src/main/java/com/awakenedredstone/neoskies/logic/protection/SkylandsProtectionProvider.java @@ -2,6 +2,7 @@ import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; import com.awakenedredstone.neoskies.logic.settings.IslandSettings; +import com.awakenedredstone.neoskies.util.ServerUtils; import com.mojang.authlib.GameProfile; import eu.pb4.common.protection.api.ProtectionProvider; import net.minecraft.block.*; @@ -9,7 +10,10 @@ import net.minecraft.entity.EntityType; import net.minecraft.entity.mob.Monster; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; import net.minecraft.registry.tag.TagKey; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Box; import net.minecraft.world.World; @@ -44,8 +48,10 @@ public boolean canPlaceBlock(World world, BlockPos pos, GameProfile profile, Pla @Override public boolean canInteractBlock(World world, BlockPos pos, GameProfile profile, PlayerEntity player) { if (player == null) return true; + BlockState state = world.getBlockState(pos); - IslandSettings settings = NeoSkiesIslandSettings.INTERACT_OTHER_BLOCKS; + + IslandSettings settings = null; for (Map.Entry, IslandSettings> entry : NeoSkiesIslandSettings.getRuleBlockTags().entrySet()) { if (state.isIn(entry.getKey())) { @@ -54,6 +60,10 @@ public boolean canInteractBlock(World world, BlockPos pos, GameProfile profile, } } + if (settings == null) { + return true; + } + return WorldProtection.canModify(world, pos, player, settings); } diff --git a/src/main/java/com/awakenedredstone/neoskies/logic/registry/NeoSkiesIslandSettings.java b/src/main/java/com/awakenedredstone/neoskies/logic/registry/NeoSkiesIslandSettings.java index 8cf1e18..7217a74 100644 --- a/src/main/java/com/awakenedredstone/neoskies/logic/registry/NeoSkiesIslandSettings.java +++ b/src/main/java/com/awakenedredstone/neoskies/logic/registry/NeoSkiesIslandSettings.java @@ -4,8 +4,10 @@ import com.awakenedredstone.neoskies.logic.tags.NeoSkiesBlockTags; import com.awakenedredstone.neoskies.logic.settings.DefaultNeoSkiesIslandSettings; import com.awakenedredstone.neoskies.logic.tags.NeoSkiesEntityTags; +import com.awakenedredstone.neoskies.logic.tags.NeoSkiesItemTags; import net.minecraft.block.Block; import net.minecraft.entity.EntityType; +import net.minecraft.item.Item; import net.minecraft.item.Items; import net.minecraft.registry.Registry; import com.awakenedredstone.neoskies.logic.SkylandsRegistries; @@ -18,64 +20,113 @@ import java.util.Map; public class NeoSkiesIslandSettings { - protected static final Map, IslandSettings> RULE_BLOCK_TAG = new HashMap<>(); + protected static final Map, IslandSettings> RULE_BLOCK_USE_TAG = new HashMap<>(); + protected static final Map, IslandSettings> RULE_BLOCK_USE_WITH_ITEM_TAG = new HashMap<>(); protected static final Map>, IslandSettings> RULE_ENTITY_TAG = new HashMap<>(); + protected static final Map, IslandSettings> RULE_ITEM_TAG = new HashMap<>(); - public static final IslandSettings PLACE_BLOCKS = new DefaultNeoSkiesIslandSettings("place_blocks", Items.STONE); - public static final IslandSettings BREAK_BLOCKS = new DefaultNeoSkiesIslandSettings("break_blocks", Items.WOODEN_PICKAXE); - - public static final IslandSettings USE_ANVIL = new DefaultNeoSkiesIslandSettings("use_anvil", Items.ANVIL); - public static final IslandSettings USE_BEACON = new DefaultNeoSkiesIslandSettings("use_beacon", Items.BEACON); - public static final IslandSettings USE_BREWING_STAND = new DefaultNeoSkiesIslandSettings("use_brewing_stand", Items.BREWING_STAND); - public static final IslandSettings USE_COMPOSTER = new DefaultNeoSkiesIslandSettings("use_composter", Items.COMPOSTER); - public static final IslandSettings USE_CONTAINERS = new DefaultNeoSkiesIslandSettings("use_containers", Items.CHEST); - public static final IslandSettings USE_DOORS = new DefaultNeoSkiesIslandSettings("use_doors", Items.OAK_DOOR); - public static final IslandSettings USE_LECTERN = new DefaultNeoSkiesIslandSettings("use_lectern", Items.LECTERN); - public static final IslandSettings USE_LODESTONE = new DefaultNeoSkiesIslandSettings("use_lodestone", Items.LODESTONE); - public static final IslandSettings USE_REDSTONE = new DefaultNeoSkiesIslandSettings("use_redstone", Items.REDSTONE); - public static final IslandSettings USE_RESPAWN_ANCHOR = new DefaultNeoSkiesIslandSettings("use_respawn_anchor", Items.RESPAWN_ANCHOR); - public static final IslandSettings INTERACT_DRIPLEAF = new DefaultNeoSkiesIslandSettings("interact_dripleaf", Items.BIG_DRIPLEAF); - public static final IslandSettings INTERACT_SCULK = new DefaultNeoSkiesIslandSettings("interact_sculk", Items.SCULK); - public static final IslandSettings INTERACT_OTHER_BLOCKS = new DefaultNeoSkiesIslandSettings("interact_other_blocks", Items.BELL, true); - - public static final IslandSettings USE_ARMOR_STAND = new DefaultNeoSkiesIslandSettings("use_armor_stand", Items.ARMOR_STAND); - public static final IslandSettings LEASH_ENTITY = new DefaultNeoSkiesIslandSettings("leash_entity", Items.LEAD); - public static final IslandSettings SHEAR_ENTITY = new DefaultNeoSkiesIslandSettings("shear_entity", Items.SHEARS); - public static final IslandSettings HURT_HOSTILE = new DefaultNeoSkiesIslandSettings("hurt_hostile", Items.DIAMOND_SWORD); - public static final IslandSettings HURT_PASSIVE = new DefaultNeoSkiesIslandSettings("hurt_passive", Items.WOODEN_SWORD); + public static final IslandSettings PLACE_BLOCKS = new DefaultNeoSkiesIslandSettings("place/blocks", Items.STONE); + public static final IslandSettings PLACE_MINECARTS = new DefaultNeoSkiesIslandSettings("place/minecarts", Items.MINECART); + public static final IslandSettings BREAK_BLOCKS = new DefaultNeoSkiesIslandSettings("break/blocks", Items.WOODEN_PICKAXE); + + public static final IslandSettings USE_ANVIL = new DefaultNeoSkiesIslandSettings("use/anvil", Items.ANVIL); + public static final IslandSettings USE_ARMOR_STAND = new DefaultNeoSkiesIslandSettings("use/armor_stand", Items.ARMOR_STAND); + public static final IslandSettings USE_BEACON = new DefaultNeoSkiesIslandSettings("use/beacon", Items.BEACON); + public static final IslandSettings USE_BREWING_STAND = new DefaultNeoSkiesIslandSettings("use/brewing_stand", Items.BREWING_STAND); + public static final IslandSettings USE_COMPOSTER = new DefaultNeoSkiesIslandSettings("use/composter", Items.COMPOSTER); + public static final IslandSettings USE_CONTAINERS = new DefaultNeoSkiesIslandSettings("use/containers", Items.CHEST); + public static final IslandSettings USE_DOORS = new DefaultNeoSkiesIslandSettings("use/doors", Items.OAK_DOOR); + public static final IslandSettings USE_ITEM_FRAME = new DefaultNeoSkiesIslandSettings("use/item_frame", Items.ITEM_FRAME); + public static final IslandSettings USE_LECTERN = new DefaultNeoSkiesIslandSettings("use/lectern", Items.LECTERN); + public static final IslandSettings USE_LODESTONE = new DefaultNeoSkiesIslandSettings("use/lodestone", Items.LODESTONE); + public static final IslandSettings USE_REDSTONE = new DefaultNeoSkiesIslandSettings("use/redstone", Items.REDSTONE); + public static final IslandSettings USE_RESPAWN_ANCHOR = new DefaultNeoSkiesIslandSettings("use/respawn_anchor", Items.RESPAWN_ANCHOR); + public static final IslandSettings USE_SIGNS = new DefaultNeoSkiesIslandSettings("use/signs", Items.SPAWNER); + public static final IslandSettings USE_SPAWNER = new DefaultNeoSkiesIslandSettings("use/spawner", Items.SPAWNER); + public static final IslandSettings USE_TNT = new DefaultNeoSkiesIslandSettings("use/tnt", Items.TNT); + + public static final IslandSettings INTERACT_DRIPLEAF = new DefaultNeoSkiesIslandSettings("interact/dripleaf", Items.BIG_DRIPLEAF); + public static final IslandSettings INTERACT_DRAGON_EGG = new DefaultNeoSkiesIslandSettings("interact/dragon_egg", Items.DRAGON_EGG); + public static final IslandSettings INTERACT_SCULK = new DefaultNeoSkiesIslandSettings("interact/sculk", Items.SCULK); + public static final IslandSettings INTERACT_OTHER_BLOCKS = new DefaultNeoSkiesIslandSettings("interact/other_blocks", Items.BELL, true); + + public static final IslandSettings HARVEST = new DefaultNeoSkiesIslandSettings("harvest", Items.SWEET_BERRIES); + + public static final IslandSettings RIDE_MINECARTS = new DefaultNeoSkiesIslandSettings("ride/minecarts", Items.MINECART); + public static final IslandSettings RIDE_BOATS = new DefaultNeoSkiesIslandSettings("ride/boats", Items.MINECART); + public static final IslandSettings RIDE_OTHERS = new DefaultNeoSkiesIslandSettings("ride/others", Items.SADDLE); + public static final IslandSettings LEASH_ENTITY = new DefaultNeoSkiesIslandSettings("leash/entity", Items.LEAD); + public static final IslandSettings SHEAR_ENTITY = new DefaultNeoSkiesIslandSettings("shear/entity", Items.SHEARS); + + public static final IslandSettings HURT_HOSTILE = new DefaultNeoSkiesIslandSettings("hurt/hostile", Items.DIAMOND_SWORD); + public static final IslandSettings HURT_PASSIVE = new DefaultNeoSkiesIslandSettings("hurt/passive", Items.WOODEN_SWORD); + public static final IslandSettings BUCKET_PASSIVE = new DefaultNeoSkiesIslandSettings("bucket/passive", Items.AXOLOTL_BUCKET); static { - addBlockTag(NeoSkiesBlockTags.ANVIL, USE_ANVIL); - addBlockTag(NeoSkiesBlockTags.BEACON, USE_BEACON); - addBlockTag(NeoSkiesBlockTags.BREWING_STAND, USE_BREWING_STAND); - addBlockTag(NeoSkiesBlockTags.COMPOSTER, USE_COMPOSTER); - addBlockTag(NeoSkiesBlockTags.CONTAINERS, USE_CONTAINERS); - addBlockTag(NeoSkiesBlockTags.DOORS, USE_DOORS); - addBlockTag(NeoSkiesBlockTags.LECTERN, USE_LECTERN); - addBlockTag(NeoSkiesBlockTags.LODESTONE, USE_LODESTONE); - addBlockTag(NeoSkiesBlockTags.REDSTONE, USE_REDSTONE); - addBlockTag(NeoSkiesBlockTags.RESPAWN_ANCHOR, USE_RESPAWN_ANCHOR); + addBlockUseTag(NeoSkiesBlockTags.ANVIL, USE_ANVIL); + addBlockUseTag(NeoSkiesBlockTags.BEACON, USE_BEACON); + addBlockUseTag(NeoSkiesBlockTags.BREWING_STAND, USE_BREWING_STAND); + addBlockUseTag(NeoSkiesBlockTags.COMPOSTER, USE_COMPOSTER); + addBlockUseTag(NeoSkiesBlockTags.CONTAINERS, USE_CONTAINERS); + addBlockUseWithItemTag(NeoSkiesBlockTags.CONTAINERS_WITH_ITEM, USE_CONTAINERS); + addBlockUseTag(NeoSkiesBlockTags.DOORS, USE_DOORS); + addBlockUseTag(NeoSkiesBlockTags.LECTERN, USE_LECTERN); + addBlockUseTag(NeoSkiesBlockTags.LODESTONE, USE_LODESTONE); + addBlockUseTag(NeoSkiesBlockTags.OTHERS, INTERACT_OTHER_BLOCKS); + addBlockUseTag(NeoSkiesBlockTags.REDSTONE, USE_REDSTONE); + addBlockUseTag(NeoSkiesBlockTags.RESPAWN_ANCHOR, USE_RESPAWN_ANCHOR); + addBlockUseTag(NeoSkiesBlockTags.SPAWNER, USE_SPAWNER); + addBlockUseTag(NeoSkiesBlockTags.SIGNS, USE_SIGNS); + addBlockUseTag(NeoSkiesBlockTags.DRAGON_EGG, INTERACT_DRAGON_EGG); + addBlockUseTag(NeoSkiesBlockTags.HARVEST, HARVEST); + + addItemTag(NeoSkiesItemTags.PLACE, PLACE_BLOCKS); + addItemTag(NeoSkiesItemTags.MINECART, PLACE_MINECARTS); + addItemTag(NeoSkiesItemTags.CONTAINERS, USE_CONTAINERS); + addItemTag(NeoSkiesItemTags.LODESTONE, USE_LODESTONE); + addItemTag(NeoSkiesItemTags.SPAWNER, USE_SPAWNER); + addEntityTag(NeoSkiesEntityTags.BREAK, BREAK_BLOCKS); + addEntityTag(NeoSkiesEntityTags.MINECARTS, RIDE_MINECARTS); + addEntityTag(NeoSkiesEntityTags.BOATS, RIDE_BOATS); + addEntityTag(NeoSkiesEntityTags.RIDEABLE, RIDE_OTHERS); addEntityTag(NeoSkiesEntityTags.ARMOR_STAND, USE_ARMOR_STAND); + addEntityTag(NeoSkiesEntityTags.ITEM_FRAME, USE_ITEM_FRAME); addEntityTag(NeoSkiesEntityTags.LEASH_KNOT, LEASH_ENTITY); } - public static void addBlockTag(TagKey tagKey, IslandSettings settings) { - RULE_BLOCK_TAG.put(tagKey, settings); + public static void addBlockUseTag(TagKey tagKey, IslandSettings settings) { + RULE_BLOCK_USE_TAG.put(tagKey, settings); + } + + public static void addBlockUseWithItemTag(TagKey tagKey, IslandSettings settings) { + RULE_BLOCK_USE_WITH_ITEM_TAG.put(tagKey, settings); } public static void addEntityTag(TagKey> tagKey, IslandSettings settings) { RULE_ENTITY_TAG.put(tagKey, settings); } + public static void addItemTag(TagKey tagKey, IslandSettings settings) { + RULE_ITEM_TAG.put(tagKey, settings); + } + public static Map, IslandSettings> getRuleBlockTags() { - return RULE_BLOCK_TAG; + return RULE_BLOCK_USE_TAG; + } + + public static Map, IslandSettings> getRuleBlockUseTag() { + return RULE_BLOCK_USE_TAG; } public static Map>, IslandSettings> getRuleEntityTags() { return RULE_ENTITY_TAG; } + public static Map, IslandSettings> getRuleItemTags() { + return RULE_ITEM_TAG; + } + public static void init() { Class clazz = NeoSkiesIslandSettings.class; IslandSettings settings; diff --git a/src/main/java/com/awakenedredstone/neoskies/logic/settings/IslandSettings.java b/src/main/java/com/awakenedredstone/neoskies/logic/settings/IslandSettings.java index 7a40db0..07e1bff 100644 --- a/src/main/java/com/awakenedredstone/neoskies/logic/settings/IslandSettings.java +++ b/src/main/java/com/awakenedredstone/neoskies/logic/settings/IslandSettings.java @@ -4,7 +4,7 @@ import com.awakenedredstone.neoskies.gui.polymer.CBGuiElementBuilder; import net.minecraft.item.Item; import net.minecraft.util.Identifier; -import com.awakenedredstone.neoskies.api.island.SettingsManager; +import com.awakenedredstone.neoskies.api.island.IslandSettingsManager; import com.awakenedredstone.neoskies.logic.registry.SkylandsPermissionLevels; public abstract class IslandSettings { @@ -48,6 +48,6 @@ public String getTranslationKey() { } protected void register() { - SettingsManager.register(identifier, new com.awakenedredstone.neoskies.api.island.IslandSettings(SkylandsPermissionLevels.MEMBER), icon); + IslandSettingsManager.register(identifier, new com.awakenedredstone.neoskies.api.island.IslandSettings(SkylandsPermissionLevels.MEMBER), icon); } } diff --git a/src/main/java/com/awakenedredstone/neoskies/logic/tags/NeoSkiesBlockTags.java b/src/main/java/com/awakenedredstone/neoskies/logic/tags/NeoSkiesBlockTags.java index 78cfa8e..3530cf7 100644 --- a/src/main/java/com/awakenedredstone/neoskies/logic/tags/NeoSkiesBlockTags.java +++ b/src/main/java/com/awakenedredstone/neoskies/logic/tags/NeoSkiesBlockTags.java @@ -4,18 +4,28 @@ import net.minecraft.block.Block; import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.tag.TagKey; +import net.minecraft.util.Identifier; public class NeoSkiesBlockTags { - public static final TagKey ANVIL = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("islands/anvil")); - public static final TagKey BEACON = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("islands/beacon")); - public static final TagKey BREWING_STAND = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("islands/brewing_stand")); - public static final TagKey COMPOSTER = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("islands/composter")); - public static final TagKey CONTAINERS = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("islands/containers")); - public static final TagKey DOORS = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("islands/doors")); - public static final TagKey LECTERN = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("islands/lectern")); - public static final TagKey LODESTONE = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("islands/lodestone")); - public static final TagKey REDSTONE = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("islands/redstone")); - public static final TagKey RESPAWN_ANCHOR = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("islands/respawn_anchor")); - //public static final TagKey DRIPLEAF = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("islands/dripleaf")); - //public static final TagKey SCULK = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("islands/sculk")); + public static final TagKey ANVIL = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/use/anvil")); + public static final TagKey BEACON = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/use/beacon")); + public static final TagKey BREWING_STAND = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/use/brewing_stand")); + public static final TagKey COMPOSTER = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/use/composter")); + public static final TagKey CONTAINERS = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/use/containers")); + public static final TagKey CONTAINERS_WITH_ITEM = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/use/containers_with_item")); + public static final TagKey DOORS = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/use/doors")); + public static final TagKey DRAGON_EGG = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/interact/dragon_egg")); + public static final TagKey EXTINGUISHABLE = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/extinguishable")); + public static final TagKey HARVEST = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/harvest")); + public static final TagKey LECTERN = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/use/lectern")); + public static final TagKey LODESTONE = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/use/lodestone")); + public static final TagKey OTHERS = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/interact/others")); + public static final TagKey REDSTONE = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/use/redstone")); + public static final TagKey RESPAWN_ANCHOR = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/use/respawn_anchor")); + public static final TagKey SPAWNER = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/use/spawner")); + public static final TagKey SIGNS = TagKey.of(RegistryKeys.BLOCK, SkylandsMain.id("protection/use/signs")); + + public static final TagKey UNWAXED_COPPER_BLOCKS = TagKey.of(RegistryKeys.BLOCK, new Identifier("c", "copper_blocks/unwaxed")); + public static final TagKey WAXED_COPPER_BLOCKS = TagKey.of(RegistryKeys.BLOCK, new Identifier("c", "copper_blocks/waxed")); + public static final TagKey COPPER_BLOCKS = TagKey.of(RegistryKeys.BLOCK, new Identifier("c", "copper_blocks")); } diff --git a/src/main/java/com/awakenedredstone/neoskies/logic/tags/NeoSkiesEntityTags.java b/src/main/java/com/awakenedredstone/neoskies/logic/tags/NeoSkiesEntityTags.java index b14d600..eeaeaf1 100644 --- a/src/main/java/com/awakenedredstone/neoskies/logic/tags/NeoSkiesEntityTags.java +++ b/src/main/java/com/awakenedredstone/neoskies/logic/tags/NeoSkiesEntityTags.java @@ -1,13 +1,16 @@ package com.awakenedredstone.neoskies.logic.tags; import com.awakenedredstone.neoskies.SkylandsMain; -import net.minecraft.block.Block; -import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.registry.RegistryKeys; import net.minecraft.registry.tag.TagKey; public class NeoSkiesEntityTags { - public static final TagKey> ARMOR_STAND = TagKey.of(RegistryKeys.ENTITY_TYPE, SkylandsMain.id("islands/armor_stand")); - public static final TagKey> LEASH_KNOT = TagKey.of(RegistryKeys.ENTITY_TYPE, SkylandsMain.id("islands/leash_knot")); + public static final TagKey> ARMOR_STAND = TagKey.of(RegistryKeys.ENTITY_TYPE, SkylandsMain.id("protection/interact/armor_stand")); + public static final TagKey> LEASH_KNOT = TagKey.of(RegistryKeys.ENTITY_TYPE, SkylandsMain.id("protection/use/leash_knot")); + public static final TagKey> ITEM_FRAME = TagKey.of(RegistryKeys.ENTITY_TYPE, SkylandsMain.id("protection/use/item_frame")); + public static final TagKey> MINECARTS = TagKey.of(RegistryKeys.ENTITY_TYPE, SkylandsMain.id("protection/ride/minecarts")); + public static final TagKey> BOATS = TagKey.of(RegistryKeys.ENTITY_TYPE, SkylandsMain.id("protection/ride/item_frame")); + public static final TagKey> RIDEABLE = TagKey.of(RegistryKeys.ENTITY_TYPE, SkylandsMain.id("protection/ride/rideable")); + public static final TagKey> BREAK = TagKey.of(RegistryKeys.ENTITY_TYPE, SkylandsMain.id("protection/break/block")); } diff --git a/src/main/java/com/awakenedredstone/neoskies/logic/tags/NeoSkiesItemTags.java b/src/main/java/com/awakenedredstone/neoskies/logic/tags/NeoSkiesItemTags.java index f83610d..6d582d9 100644 --- a/src/main/java/com/awakenedredstone/neoskies/logic/tags/NeoSkiesItemTags.java +++ b/src/main/java/com/awakenedredstone/neoskies/logic/tags/NeoSkiesItemTags.java @@ -6,6 +6,10 @@ import net.minecraft.registry.tag.TagKey; public class NeoSkiesItemTags { - public static final TagKey BLOCK_INTERACTION = TagKey.of(RegistryKeys.ITEM, SkylandsMain.id("islands/block_interaction")); - public static final TagKey GENERAL_INTERACTION = TagKey.of(RegistryKeys.ITEM, SkylandsMain.id("islands/general_interaction")); + public static final TagKey MINECART = TagKey.of(RegistryKeys.ITEM, SkylandsMain.id("protection/use/minecart")); + public static final TagKey LEAD = TagKey.of(RegistryKeys.ITEM, SkylandsMain.id("protection/lead")); + public static final TagKey PLACE = TagKey.of(RegistryKeys.ITEM, SkylandsMain.id("protection/place")); + public static final TagKey CONTAINERS = TagKey.of(RegistryKeys.ITEM, SkylandsMain.id("protection/containers")); + public static final TagKey LODESTONE = TagKey.of(RegistryKeys.ITEM, SkylandsMain.id("protection/locestone")); + public static final TagKey SPAWNER = TagKey.of(RegistryKeys.ITEM, SkylandsMain.id("protection/spawner")); } diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/entity/DataTrackerAccessor.java b/src/main/java/com/awakenedredstone/neoskies/mixin/entity/DataTrackerAccessor.java new file mode 100644 index 0000000..96c368d --- /dev/null +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/entity/DataTrackerAccessor.java @@ -0,0 +1,10 @@ +package com.awakenedredstone.neoskies.mixin.entity; + +import net.minecraft.entity.data.DataTracker; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.gen.Accessor; + +@Mixin(DataTracker.class) +public interface DataTrackerAccessor { + @Accessor DataTracker.Entry[] getEntries(); +} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/entity/PlayerManagerMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/entity/PlayerManagerMixin.java index ff6f472..10c35b5 100644 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/entity/PlayerManagerMixin.java +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/entity/PlayerManagerMixin.java @@ -69,13 +69,13 @@ private void loadIsland(ClientConnection connection, ServerPlayerEntity player, //Load the proper island dimension if (SkylandsAPI.isOverworld(registryKey)) { - LOGGER.info("Loading overworld for " + registryKey.getValue()); + LOGGER.debug("Loading overworld for {}", registryKey.getValue()); island.getOverworld(); } else if (SkylandsAPI.isNether(registryKey)) { - LOGGER.info("Loading nether for " + registryKey.getValue()); + LOGGER.debug("Loading nether for {}", registryKey.getValue()); island.getNether(); } else if (SkylandsAPI.isEnd(registryKey)) { - LOGGER.info("Loading end for " + registryKey.getValue()); + LOGGER.debug("Loading end for {}", registryKey.getValue()); island.getEnd(); } } else { diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/item/ArmorStandItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/item/ArmorStandItemMixin.java deleted file mode 100644 index c5c84d9..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/item/ArmorStandItemMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.item; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ArmorStandItem; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.util.ActionResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; -@Mixin(ArmorStandItem.class) -public class ArmorStandItemMixin { - - @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) - void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { - World world = context.getWorld(); - PlayerEntity player = context.getPlayer(); - BlockPos blockPos = context.getBlockPos().offset(context.getSide()); - if (!world.isClient() && player != null) { - if (!WorldProtection.canModify(world, blockPos, player)) { - ServerUtils.protectionWarning(player, "item_use"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/item/BlockItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/item/BlockItemMixin.java deleted file mode 100644 index 882459f..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/item/BlockItemMixin.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.item; - -/*import net.minecraft.entity.player.PlayerEntity;*/ - -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; -/*import net.minecraft.item.ItemUsageContext; -import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World;*/ -import org.spongepowered.asm.mixin.Mixin; -/*import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import skylands.logic.registry.SkylandsIslandSettings; -import skylands.util.WorldProtection; - -import static skylands.util.ServerUtils.ServerUtils.protectionWarning;*/ -@Mixin(BlockItem.class) -public class BlockItemMixin extends Item { - - public BlockItemMixin(Settings settings) { - super(settings); - } - - /*@Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) - void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { - World world = context.getWorld(); - PlayerEntity player = context.getPlayer(); - if (player instanceof ServerPlayerEntity serverPlayer) { - BlockPos blockPos = context.getBlockPos().offset(context.getSide()); - if (!WorldProtection.canModify(world, blockPos, player, SkylandsIslandSettings.PLACE)) { - ServerUtils.protectionWarning(player, "block_place"); - int slot = context.getHand() == Hand.MAIN_HAND ? player.getInventory().selectedSlot : 40; - var stack = context.getStack(); - serverPlayer.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(ScreenHandlerSlotUpdateS2CPacket.UPDATE_PLAYER_INVENTORY_SYNC_ID, 0, slot, stack)); - cir.setReturnValue(ActionResult.FAIL); - } - } - }*/ -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/item/BoatItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/item/BoatItemMixin.java deleted file mode 100644 index 1b2fd99..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/item/BoatItemMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.item; - -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.BoatItem; -import net.minecraft.item.ItemStack; -import net.minecraft.util.Hand; -import net.minecraft.util.TypedActionResult; -import net.minecraft.util.hit.HitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import org.spongepowered.asm.mixin.injection.callback.LocalCapture; -import com.awakenedredstone.neoskies.util.WorldProtection; -@Mixin(BoatItem.class) -public class BoatItemMixin { - - @SuppressWarnings("InvalidInjectorMethodSignature") - @Inject(method = "use", at = @At(value = "INVOKE_ASSIGN", target = "Lnet/minecraft/item/BoatItem;raycast(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/world/RaycastContext$FluidHandling;)Lnet/minecraft/util/hit/BlockHitResult;", shift = At.Shift.AFTER), cancellable = true, locals = LocalCapture.CAPTURE_FAILSOFT) - void useOnBlock(World world, PlayerEntity user, Hand hand, CallbackInfoReturnable> cir, ItemStack itemStack, HitResult hitResult) { - if (hitResult.getType() == HitResult.Type.MISS) return; - if (!world.isClient()) { - BlockPos blockPos = BlockPos.ofFloored(hitResult.getPos()); - if (!WorldProtection.isWithinIsland(world, blockPos)) { - cir.setReturnValue(TypedActionResult.fail(itemStack)); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BoneMealItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/item/BoneMealItemMixin.java similarity index 55% rename from src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BoneMealItemMixin.java rename to src/main/java/com/awakenedredstone/neoskies/mixin/item/BoneMealItemMixin.java index 539af62..e07d5ea 100644 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BoneMealItemMixin.java +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/item/BoneMealItemMixin.java @@ -1,10 +1,15 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; +package com.awakenedredstone.neoskies.mixin.item; +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; import com.awakenedredstone.neoskies.util.ServerUtils; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.BoneMealItem; +import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUsageContext; +import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -14,14 +19,17 @@ @Mixin(BoneMealItem.class) public class BoneMealItemMixin { - @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { World world = context.getWorld(); PlayerEntity player = context.getPlayer(); if (!world.isClient() && player != null) { - if (!WorldProtection.canModify(world, context.getBlockPos(), player)) { - ServerUtils.protectionWarning(player, "bone_meal_use"); + if (!WorldProtection.canModify(world, context.getBlockPos(), player, NeoSkiesIslandSettings.PLACE_BLOCKS)) { + Hand hand = context.getHand(); + ItemStack stack = context.getStack(); + int slot = hand == Hand.MAIN_HAND ? player.getInventory().selectedSlot : 40; + ((ServerPlayerEntity) player).networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(ScreenHandlerSlotUpdateS2CPacket.UPDATE_PLAYER_INVENTORY_SYNC_ID, 0, slot, stack)); + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.PLACE_BLOCKS); cir.setReturnValue(ActionResult.FAIL); } } diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/item/ItemStackMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/item/ItemStackMixin.java index 840f9fb..2be4931 100644 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/item/ItemStackMixin.java +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/item/ItemStackMixin.java @@ -1,8 +1,16 @@ package com.awakenedredstone.neoskies.mixin.item; +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; +import com.awakenedredstone.neoskies.logic.settings.IslandSettings; +import com.awakenedredstone.neoskies.util.ServerUtils; +import net.minecraft.block.Block; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.*; +import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; +import net.minecraft.registry.tag.TagKey; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; @@ -12,6 +20,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.awakenedredstone.neoskies.util.WorldProtection; +import java.util.Map; + @Mixin(ItemStack.class) public abstract class ItemStackMixin { @@ -23,14 +33,31 @@ public abstract class ItemStackMixin { @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) private void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { - if (getItem() instanceof BlockItem) return; + ItemStack stack = context.getStack(); + if (stack.getItem() instanceof BlockItem) return; World world = context.getWorld(); PlayerEntity player = context.getPlayer(); if (!world.isClient() && player != null) { + IslandSettings settings = null; + + for (Map.Entry, IslandSettings> entry : NeoSkiesIslandSettings.getRuleItemTags().entrySet()) { + if (stack.isIn(entry.getKey())) { + settings = entry.getValue(); + break; + } + } + + if (settings == null) { + return; + } + BlockPos blockPos = context.getBlockPos().offset(context.getSide()); - if (!WorldProtection.canModify(world, blockPos, player)) { - //ServerUtils.protectionWarning(player, "item_use"); + if (!WorldProtection.canModify(world, blockPos, player, settings)) { + Hand hand = context.getHand(); + int slot = hand == Hand.MAIN_HAND ? player.getInventory().selectedSlot : 40; + ((ServerPlayerEntity) player).networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(ScreenHandlerSlotUpdateS2CPacket.UPDATE_PLAYER_INVENTORY_SYNC_ID, 0, slot, stack)); + ServerUtils.protectionWarning(player, settings); cir.setReturnValue(ActionResult.FAIL); } } diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/item/MinecartItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/item/MinecartItemMixin.java deleted file mode 100644 index 575311c..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/item/MinecartItemMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.item; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.item.MinecartItem; -import net.minecraft.util.ActionResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; -@Mixin(MinecartItem.class) -public class MinecartItemMixin { - - @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) - void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { - World world = context.getWorld(); - PlayerEntity player = context.getPlayer(); - if (!world.isClient() && player != null) { - BlockPos blockPos = context.getBlockPos().offset(context.getSide()); - if (!WorldProtection.canModify(world, blockPos, player)) { - ServerUtils.protectionWarning(player, "item_use"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/ServerWorldMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/ServerWorldMixin.java index 5efe72f..367763c 100644 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/ServerWorldMixin.java +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/ServerWorldMixin.java @@ -1,8 +1,8 @@ package com.awakenedredstone.neoskies.mixin.world; -import com.awakenedredstone.neoskies.config.MainConfig; import com.awakenedredstone.neoskies.logic.Skylands; import com.google.common.collect.ImmutableList; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; import net.minecraft.entity.Entity; import net.minecraft.entity.ItemEntity; import net.minecraft.entity.projectile.ProjectileEntity; @@ -36,7 +36,6 @@ import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.SkylandsMain; import com.awakenedredstone.neoskies.api.SkylandsAPI; import com.awakenedredstone.neoskies.util.WorldProtection; @@ -53,6 +52,14 @@ protected ServerWorldMixin(MutableWorldProperties properties, RegistryKey super(properties, registryRef, registryManager, dimensionEntry, profiler, isClient, debugWorld, biomeAccess, maxChainedNeighborUpdates); } + @ModifyExpressionValue(method = "tickChunk", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/math/random/Random;nextInt(I)I", ordinal = 0)) + private int disableLightningOnHub(int original) { + if (SkylandsAPI.isHub(this) && Skylands.getConfig().disableLightningOnHub) { + return 1; + } + return original; + } + @Inject(method = "spawnEntity", at = @At("HEAD"), cancellable = true) private void spawnEntity(Entity entity, CallbackInfoReturnable cir) { if (!Skylands.getConfig().disableEntitiesOutsideIslands) return; diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/AbstractBlockStateMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/AbstractBlockStateMixin.java deleted file mode 100644 index 198c18a..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/AbstractBlockStateMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import net.minecraft.block.AbstractBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.awakenedredstone.neoskies.api.SkylandsAPI; - -@Mixin(AbstractBlock.AbstractBlockState.class) -public class AbstractBlockStateMixin { - - @Inject(method = "randomTick", at = @At("HEAD"), cancellable = true) - private void disableRandomTickingOutsideIsland(ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (SkylandsAPI.isIsland(world) && !SkylandsAPI.getIsland(world).get().isWithinBorder(pos)) { - ci.cancel(); - } - } - - @Inject(method = "scheduledTick", at = @At("HEAD"), cancellable = true) - private void disableTickingOutsideIsland(ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) { - if (SkylandsAPI.isIsland(world) && !SkylandsAPI.getIsland(world).get().isWithinBorder(pos)) { - ci.cancel(); - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/AnvilBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/AnvilBlockMixin.java deleted file mode 100644 index 1d62a5f..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/AnvilBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.AnvilBlock; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(AnvilBlock.class) -public class AnvilBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "anvil"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ArmorStandMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ArmorStandMixin.java deleted file mode 100644 index ada4fc0..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ArmorStandMixin.java +++ /dev/null @@ -1,58 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.EquipmentSlot; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.decoration.ArmorStandEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Vec3d; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(ArmorStandEntity.class) -public abstract class ArmorStandMixin extends LivingEntity { - - protected ArmorStandMixin(EntityType entityType, World world) { - super(entityType, world); - } - - @Inject(method = "damage", at = @At("HEAD"), cancellable = true) - void damage(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (!getWorld().isClient() && source.getAttacker() instanceof PlayerEntity attacker) { - if (!WorldProtection.canModify(getWorld(), this.getBlockPos(), attacker)) { - ServerUtils.protectionWarning(attacker, "entity_hurt"); - cir.setReturnValue(false); - } - } - } - - @Inject(method = "interactAt", at = @At("HEAD"), cancellable = true) - void interactAt(PlayerEntity player, Vec3d hitPos, Hand hand, CallbackInfoReturnable cir) { - if (!player.getWorld().isClient()) { - if (!WorldProtection.canModify(player.getWorld(), BlockPos.ofFloored(hitPos), player)) { - ServerUtils.protectionWarning(player, "armor_stand_use"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } - - @Inject(method = "equip", at = @At("HEAD"), cancellable = true) - void equip(PlayerEntity player, EquipmentSlot slot, ItemStack stack, Hand hand, CallbackInfoReturnable cir) { - if (!player.getWorld().isClient()) { - if (!WorldProtection.canModify(player.getWorld(), this.getBlockPos(), player)) { - ServerUtils.protectionWarning(player, "armor_stand_use"); - cir.setReturnValue(false); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/AxeItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/AxeItemMixin.java deleted file mode 100644 index b8a213b..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/AxeItemMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.AxeItem; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.util.ActionResult; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(AxeItem.class) -public class AxeItemMixin { - - @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) - void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { - World world = context.getWorld(); - PlayerEntity player = context.getPlayer(); - if (!world.isClient() && player != null) { - if (!WorldProtection.canModify(world, context.getBlockPos(), player)) { - ServerUtils.protectionWarning(player, "axe_use"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BeaconBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BeaconBlockMixin.java deleted file mode 100644 index d218936..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BeaconBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BeaconBlock; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(BeaconBlock.class) -public class BeaconBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "interact"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BigDripLeafMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BigDripLeafMixin.java deleted file mode 100644 index 1168814..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BigDripLeafMixin.java +++ /dev/null @@ -1,41 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BigDripleafBlock; -import net.minecraft.block.BlockState; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.projectile.ProjectileEntity; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(BigDripleafBlock.class) -public class BigDripLeafMixin { - - @Inject(method = "onProjectileHit", at = @At("HEAD"), cancellable = true) - void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile, CallbackInfo ci) { - if (!world.isClient()) { - if (!WorldProtection.isWithinIsland(world, hit.getBlockPos())) { - ci.cancel(); - } - } - } - - @Inject(method = "onEntityCollision", at = @At("HEAD"), cancellable = true) - void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity, CallbackInfo ci) { - if (!world.isClient()) { - if ((entity instanceof PlayerEntity player && !WorldProtection.canModify(world, pos, player))) { - ServerUtils.protectionWarning(player, "dripleaf"); - ci.cancel(); - } else if (!WorldProtection.isWithinIsland(world, pos)) { - ci.cancel(); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BoatMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BoatMixin.java deleted file mode 100644 index 2572f30..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BoatMixin.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.vehicle.BoatEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(BoatEntity.class) -public abstract class BoatMixin extends Entity { - - public BoatMixin(EntityType type, World world) { - super(type, world); - } - - /*@Inject(method = "damage", at = @At("HEAD"), cancellable = true) - void preventDamage(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (!getWorld().isClient() && source.getAttacker() instanceof PlayerEntity attacker) { - if (!WorldProtection.canModify(getWorld(), getBlockPos(), attacker)) { - ServerUtils.protectionWarning(attacker, "entity_hurt"); - cir.setReturnValue(false); - } - } - }*/ - - @Inject(method = "interact", at = @At("HEAD"), cancellable = true) - void preventInteraction(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - if (!WorldProtection.canModify(getWorld(), getBlockPos(), player)) { - ServerUtils.protectionWarning(player, "interact"); - cir.setReturnValue(ActionResult.PASS); - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BrewingStandBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BrewingStandBlockMixin.java deleted file mode 100644 index 93466b2..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BrewingStandBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.BrewingStandBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(BrewingStandBlock.class) -public class BrewingStandBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "brewing_stand"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BucketableMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BucketableMixin.java new file mode 100644 index 0000000..79c4be1 --- /dev/null +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/BucketableMixin.java @@ -0,0 +1,53 @@ +package com.awakenedredstone.neoskies.mixin.world.protection; + +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; +import com.awakenedredstone.neoskies.mixin.entity.DataTrackerAccessor; +import com.awakenedredstone.neoskies.util.ServerUtils; +import com.awakenedredstone.neoskies.util.WorldProtection; +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.entity.Bucketable; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.data.DataTracker; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket; +import net.minecraft.network.packet.s2c.play.EntityTrackerUpdateS2CPacket; +import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.ArrayList; +import java.util.Optional; + +@Mixin(Bucketable.class) +public interface BucketableMixin { + @Inject(method = "tryBucket", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/Bucketable;getBucketItem()Lnet/minecraft/item/ItemStack;", shift = At.Shift.BEFORE), cancellable = true) + private static void preventBucket(PlayerEntity player, Hand hand, LivingEntity entity, CallbackInfoReturnable> cir , @Local ItemStack stack) { + if (player == null) return; + World world = player.getWorld(); + if (!world.isClient()) { + BlockPos pos = entity.getBlockPos(); + + if (!WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.BUCKET_PASSIVE)) { + ServerPlayerEntity serverPlayer = (ServerPlayerEntity) player; + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.BUCKET_PASSIVE); + int slot = hand == Hand.MAIN_HAND ? player.getInventory().selectedSlot : 40; + serverPlayer.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(ScreenHandlerSlotUpdateS2CPacket.UPDATE_PLAYER_INVENTORY_SYNC_ID, 0, slot, stack)); + serverPlayer.networkHandler.sendPacket(new EntitySpawnS2CPacket(entity)); + ArrayList> entries = new ArrayList<>(); + for (DataTracker.Entry entry : ((DataTrackerAccessor) entity.getDataTracker()).getEntries()) { + entries.add(entry.toSerialized()); + } + serverPlayer.networkHandler.sendPacket(new EntityTrackerUpdateS2CPacket(entity.getId(), entries)); + cir.setReturnValue(Optional.empty()); + } + } + } +} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ButtonMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ButtonMixin.java deleted file mode 100644 index ad0b452..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ButtonMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.ButtonBlock; -import net.minecraft.block.WallMountedBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(ButtonBlock.class) -public abstract class ButtonMixin extends WallMountedBlock { - - public ButtonMixin(Settings settings) { - super(settings); - } - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "redstone"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CandleBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CandleBlockMixin.java deleted file mode 100644 index 7ad1788..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CandleBlockMixin.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.CandleBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(CandleBlock.class) -public class CandleBlockMixin { - - @Shadow - @Final - public static BooleanProperty LIT; - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - if (state.get(LIT)) ServerUtils.protectionWarning(player, "extinguish"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CandleCakeBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CandleCakeBlockMixin.java deleted file mode 100644 index f3812c6..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CandleCakeBlockMixin.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.CandleCakeBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(CandleCakeBlock.class) -public class CandleCakeBlockMixin { - - @Shadow - @Final - public static BooleanProperty LIT; - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - if (state.get(LIT)) ServerUtils.protectionWarning(player, "extinguish"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CauldronBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CauldronBlockMixin.java deleted file mode 100644 index ede1575..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CauldronBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.AbstractCauldronBlock; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(AbstractCauldronBlock.class) -public class CauldronBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "cauldron"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ChestBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ChestBlockMixin.java deleted file mode 100644 index eaf7fa8..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ChestBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.ChestBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(ChestBlock.class) -public class ChestBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "chest_open"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ChestBoatMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ChestBoatMixin.java deleted file mode 100644 index 81df5e0..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ChestBoatMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.vehicle.BoatEntity; -import net.minecraft.entity.vehicle.ChestBoatEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(ChestBoatEntity.class) -public class ChestBoatMixin extends BoatEntity { - - public ChestBoatMixin(EntityType entityType, World world) { - super(entityType, world); - } - - @Inject(method = "interact", at = @At("HEAD"), cancellable = true) - void interact(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - if (!player.getWorld().isClient()) { - if (!WorldProtection.canModify(player.getWorld(), player)) { - ServerUtils.protectionWarning(player, "boat_open"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ComparatorMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ComparatorMixin.java deleted file mode 100644 index b313f9e..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ComparatorMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.AbstractRedstoneGateBlock; -import net.minecraft.block.BlockState; -import net.minecraft.block.ComparatorBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(ComparatorBlock.class) -public abstract class ComparatorMixin extends AbstractRedstoneGateBlock { - - protected ComparatorMixin(Settings settings) { - super(settings); - } - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "redstone"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CompassItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CompassItemMixin.java deleted file mode 100644 index e145465..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CompassItemMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.Blocks; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.CompassItem; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.server.network.ServerPlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(CompassItem.class) -public class CompassItemMixin { - - @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) - void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { - World world = context.getWorld(); - PlayerEntity player = context.getPlayer(); - BlockPos blockPos = context.getBlockPos(); - if (!world.isClient() && player instanceof ServerPlayerEntity serverPlayer) { - if (!WorldProtection.canModify(world, blockPos, serverPlayer)) { - if (world.getBlockState(blockPos).isOf(Blocks.LODESTONE)) { - ServerUtils.protectionWarning(player, "lodestone"); - } - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ComposterBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ComposterBlockMixin.java deleted file mode 100644 index 0890fdd..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ComposterBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.ComposterBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(ComposterBlock.class) -public class ComposterBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "composter"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DaylightDetectorBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DaylightDetectorBlockMixin.java deleted file mode 100644 index cf0caeb..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DaylightDetectorBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.DaylightDetectorBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(DaylightDetectorBlock.class) -public class DaylightDetectorBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - private void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "redstone"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DecorationEntityMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DecorationEntityMixin.java deleted file mode 100644 index ebf08df..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DecorationEntityMixin.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.decoration.AbstractDecorationEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(AbstractDecorationEntity.class) -public abstract class DecorationEntityMixin extends Entity { - - @Shadow - protected BlockPos attachmentPos; - - public DecorationEntityMixin(EntityType type, World world) { - super(type, world); - } - - @Inject(method = "damage", at = @At("HEAD"), cancellable = true) - void damage(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (!getWorld().isClient() && source.getAttacker() instanceof PlayerEntity attacker) { - if (!WorldProtection.canModify(getWorld(), this.getBlockPos(), attacker)) { - ServerUtils.protectionWarning(attacker, "entity_hurt"); - cir.setReturnValue(false); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DecorationItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DecorationItemMixin.java deleted file mode 100644 index ca1f0d3..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DecorationItemMixin.java +++ /dev/null @@ -1,34 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.DecorationItem; -import net.minecraft.item.Item; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.util.ActionResult; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(DecorationItem.class) -public class DecorationItemMixin extends Item { - - public DecorationItemMixin(Settings settings) { - super(settings); - } - - @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) - void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { - World world = context.getWorld(); - PlayerEntity player = context.getPlayer(); - if (!world.isClient() && player != null) { - if (!WorldProtection.canModify(world, context.getBlockPos().offset(context.getSide()), player)) { - ServerUtils.protectionWarning(player, "item_place"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DispenserBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DispenserBlockMixin.java deleted file mode 100644 index 115b00e..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DispenserBlockMixin.java +++ /dev/null @@ -1,48 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.DispenserBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.state.property.DirectionProperty; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(DispenserBlock.class) -public class DispenserBlockMixin { - - @Shadow - @Final - public static DirectionProperty FACING; - - @Inject(method = "dispense", at = @At("HEAD"), cancellable = true) - private void dispense(ServerWorld world, BlockState state, BlockPos pos, CallbackInfo ci) { - if (!world.isClient()) { - if (!WorldProtection.isWithinIsland(world, pos) || !WorldProtection.isWithinIsland(world, pos.offset((world.getBlockState(pos).get(FACING))))) { - ci.cancel(); - } - } - } - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - private void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "dispenser_open"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DoorBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DoorBlockMixin.java deleted file mode 100644 index 05a582d..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DoorBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.DoorBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(DoorBlock.class) -public class DoorBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "door_open"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DropperBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DropperBlockMixin.java deleted file mode 100644 index 9849356..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/DropperBlockMixin.java +++ /dev/null @@ -1,24 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import net.minecraft.block.BlockState; -import net.minecraft.block.DropperBlock; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(DropperBlock.class) -public class DropperBlockMixin extends DispenserBlockMixin { - - @Inject(method = "dispense", at = @At("HEAD"), cancellable = true) - private void dispense(ServerWorld world, BlockState state, BlockPos pos, CallbackInfo ci) { - if (!world.isClient()) { - if (!WorldProtection.isWithinIsland(world, pos) || !WorldProtection.isWithinIsland(world, pos.offset((world.getBlockState(pos).get(FACING))))) { - ci.cancel(); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/EntityMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/EntityMixin.java new file mode 100644 index 0000000..6aeb71a --- /dev/null +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/EntityMixin.java @@ -0,0 +1,34 @@ +package com.awakenedredstone.neoskies.mixin.world.protection; + +import com.awakenedredstone.neoskies.event.GenericEntityDamageEvent; +import net.minecraft.entity.Entity; +import net.minecraft.entity.damage.DamageSource; +import net.minecraft.util.ActionResult; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import xyz.nucleoid.stimuli.Stimuli; + +@Mixin(Entity.class) +public abstract class EntityMixin { + @Shadow public abstract World getWorld(); + + @Inject(method = "isInvulnerableTo", at = @At("HEAD"), cancellable = true) + private void onDamage(DamageSource source, CallbackInfoReturnable cir) { + if (this.getWorld().isClient) { + return; + } + + var entity = (Entity) (Object) this; + + try (var invokers = Stimuli.select().forEntity(entity)) { + var result = invokers.get(GenericEntityDamageEvent.EVENT).onDamage(entity, source, -1); + if (result == ActionResult.FAIL) { + cir.setReturnValue(true); + } + } + } +} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ExplosionBehaviorMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ExplosionBehaviorMixin.java new file mode 100644 index 0000000..2a1446a --- /dev/null +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ExplosionBehaviorMixin.java @@ -0,0 +1,49 @@ +package com.awakenedredstone.neoskies.mixin.world.protection; + +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; +import com.awakenedredstone.neoskies.logic.settings.IslandSettings; +import com.awakenedredstone.neoskies.util.WorldProtection; +import net.minecraft.block.BlockState; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.Ownable; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.BlockView; +import net.minecraft.world.World; +import net.minecraft.world.explosion.EntityExplosionBehavior; +import net.minecraft.world.explosion.Explosion; +import net.minecraft.world.explosion.ExplosionBehavior; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin({ExplosionBehavior.class, EntityExplosionBehavior.class}) +public class ExplosionBehaviorMixin { + @Inject(method = "canDestroyBlock", at = @At("HEAD"), cancellable = true) + private void protectIslands(Explosion explosion, BlockView view, BlockPos pos, BlockState state, float power, CallbackInfoReturnable cir) { + if (!(view instanceof World world)) { + return; + } + + PlayerEntity player = null; + LivingEntity entity = explosion.getCausingEntity(); + + if (entity instanceof PlayerEntity) { + player = (PlayerEntity) entity; + } else if (entity instanceof Ownable ownable && ownable.getOwner() instanceof PlayerEntity owner) { + player = owner; + } + + if (player == null) { + return; + } + + boolean isBlockTrigger = explosion.getDestructionType() == Explosion.DestructionType.TRIGGER_BLOCK; + IslandSettings settings = isBlockTrigger ? NeoSkiesIslandSettings.USE_REDSTONE : NeoSkiesIslandSettings.BREAK_BLOCKS; + + if (!WorldProtection.canModify(world, pos, player, settings)) { + cir.setReturnValue(false); + } + } +} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FarmlandBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FarmlandBlockMixin.java deleted file mode 100644 index 6548e51..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FarmlandBlockMixin.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.FarmlandBlock; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(FarmlandBlock.class) -public class FarmlandBlockMixin { - - @Inject(method = "onLandedUpon", at = @At("HEAD"), cancellable = true) - void onLandedUpon(World world, BlockState state, BlockPos pos, Entity entity, float fallDistance, CallbackInfo ci) { - if (!world.isClient() && entity instanceof PlayerEntity player) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "farmland_spoil"); - ci.cancel(); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FenceBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FenceBlockMixin.java deleted file mode 100644 index 4998540..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FenceBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.FenceBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(FenceBlock.class) -public class FenceBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "fence"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FenceGateBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FenceGateBlockMixin.java deleted file mode 100644 index 3131287..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FenceGateBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.FenceGateBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(FenceGateBlock.class) -public class FenceGateBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "fence_gate_open"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FilledMapItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FilledMapItemMixin.java deleted file mode 100644 index aa60f07..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FilledMapItemMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.FilledMapItem; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.util.ActionResult; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(FilledMapItem.class) -public class FilledMapItemMixin { - - @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) - void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { - World world = context.getWorld(); - PlayerEntity player = context.getPlayer(); - if (!world.isClient() && player != null) { - if (!WorldProtection.canModify(world, context.getBlockPos(), player)) { - ServerUtils.protectionWarning(player, "interact"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FireChargeItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FireChargeItemMixin.java deleted file mode 100644 index d98d272..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FireChargeItemMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.FireChargeItem; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.util.ActionResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(FireChargeItem.class) -public class FireChargeItemMixin { - - @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) - void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { - World world = context.getWorld(); - PlayerEntity player = context.getPlayer(); - BlockPos blockPos = context.getBlockPos(); - if (!world.isClient() && player != null) { - if (!WorldProtection.canModify(world, blockPos.offset(context.getSide()), player)) { - ServerUtils.protectionWarning(player, "flint_and_steel_use"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FlowerPotBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FlowerPotBlockMixin.java deleted file mode 100644 index d491e8e..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FlowerPotBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.FlowerPotBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(FlowerPotBlock.class) -public class FlowerPotBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "flower_pot_use"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FurnaceBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FurnaceBlockMixin.java deleted file mode 100644 index 9bcd3cf..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FurnaceBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.AbstractFurnaceBlock; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(AbstractFurnaceBlock.class) -public class FurnaceBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "furnace_open"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HoeItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HoeItemMixin.java deleted file mode 100644 index 2e8f271..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HoeItemMixin.java +++ /dev/null @@ -1,29 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.HoeItem; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.util.ActionResult; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(HoeItem.class) -public class HoeItemMixin { - - @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) - void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { - World world = context.getWorld(); - PlayerEntity player = context.getPlayer(); - if (!world.isClient() && player != null) { - if (!WorldProtection.canModify(world, context.getBlockPos(), player)) { - ServerUtils.protectionWarning(player, "hoe_use"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HoneycombItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HoneycombItemMixin.java deleted file mode 100644 index e030c05..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HoneycombItemMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.HoneycombItem; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.util.ActionResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(HoneycombItem.class) -public class HoneycombItemMixin { - - @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) - void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { - World world = context.getWorld(); - PlayerEntity player = context.getPlayer(); - if (!world.isClient() && player != null) { - BlockPos blockPos = context.getBlockPos(); - if (!WorldProtection.canModify(world, blockPos, player)) { - ServerUtils.protectionWarning(player, "item_use"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HopperBlockEntityMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HopperBlockEntityMixin.java deleted file mode 100644 index ec44a08..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HopperBlockEntityMixin.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import net.minecraft.block.BlockState; -import net.minecraft.block.HopperBlock; -import net.minecraft.block.entity.BlockEntityType; -import net.minecraft.block.entity.HopperBlockEntity; -import net.minecraft.block.entity.LootableContainerBlockEntity; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(HopperBlockEntity.class) -public abstract class HopperBlockEntityMixin extends LootableContainerBlockEntity { - - protected HopperBlockEntityMixin(BlockEntityType blockEntityType, BlockPos blockPos, BlockState blockState) { - super(blockEntityType, blockPos, blockState); - } - - @Inject(method = "serverTick", at = @At("HEAD"), cancellable = true) - private static void lockHopper(World world, BlockPos pos, BlockState state, HopperBlockEntity blockEntity, CallbackInfo ci) { - if (world instanceof ServerWorld) { - if (!WorldProtection.isWithinIsland(world, pos.offset(state.get(HopperBlock.FACING)))) { - ci.cancel(); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HopperBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HopperBlockMixin.java deleted file mode 100644 index 6b06515..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HopperBlockMixin.java +++ /dev/null @@ -1,60 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import com.llamalad7.mixinextras.injector.ModifyReturnValue; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.BlockWithEntity; -import net.minecraft.block.HopperBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemPlacementContext; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.state.property.DirectionProperty; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(HopperBlock.class) -public abstract class HopperBlockMixin extends BlockWithEntity { - @Shadow @Final public static BooleanProperty ENABLED; - @Shadow @Final public static DirectionProperty FACING; - - protected HopperBlockMixin(Settings settings) { - super(settings); - } - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - public void blockOpening(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "hopper_open"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } - - @ModifyReturnValue(method = "getPlacementState", at = @At("RETURN")) - private BlockState lockHopper(BlockState original, ItemPlacementContext ctx) { - return original.with(ENABLED, WorldProtection.isWithinIsland(ctx.getWorld(), ctx.getBlockPos())); - } - - @Inject(method = "updateEnabled", at = @At("HEAD"), cancellable = true) - void lockHopper(World world, BlockPos pos, BlockState state, CallbackInfo ci) { - if (!world.isClient()) { - if (!WorldProtection.isWithinIsland(world, pos)) { - world.setBlockState(pos, state.with(ENABLED, false), 0); - ci.cancel(); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HopperMinecartEntityMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HopperMinecartEntityMixin.java deleted file mode 100644 index 6a249ac..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/HopperMinecartEntityMixin.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import net.minecraft.entity.EntityType; -import net.minecraft.entity.vehicle.HopperMinecartEntity; -import net.minecraft.entity.vehicle.StorageMinecartEntity; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(HopperMinecartEntity.class) -public abstract class HopperMinecartEntityMixin extends StorageMinecartEntity { - - protected HopperMinecartEntityMixin(EntityType entityType, World world) { - super(entityType, world); - } - - @Inject(method = "isEnabled", at = @At("TAIL"), cancellable = true) - private void lockMinecartHopper(CallbackInfoReturnable cir) { - if (!WorldProtection.isWithinIsland(getWorld(), getBlockPos())) { - cir.setReturnValue(false); - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ItemFrameEntityMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ItemFrameEntityMixin.java deleted file mode 100644 index 2e046cf..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ItemFrameEntityMixin.java +++ /dev/null @@ -1,44 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.decoration.AbstractDecorationEntity; -import net.minecraft.entity.decoration.ItemFrameEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(ItemFrameEntity.class) -public abstract class ItemFrameEntityMixin extends AbstractDecorationEntity { - - protected ItemFrameEntityMixin(EntityType entityType, World world) { - super(entityType, world); - } - - @Inject(method = "damage", at = @At("HEAD"), cancellable = true) - void damage(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (!getWorld().isClient() && source.getAttacker() instanceof PlayerEntity attacker) { - if (!WorldProtection.canModify(getWorld(), attacker)) { - ServerUtils.protectionWarning(attacker, "entity_hurt"); - cir.setReturnValue(false); - } - } - } - - @Inject(method = "interact", at = @At("HEAD"), cancellable = true) - void interact(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - if (!player.getWorld().isClient()) { - if (!WorldProtection.canModify(getWorld(), this.getBlockPos(), player)) { - ServerUtils.protectionWarning(player, "item_frame_use"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LeadItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LeadItemMixin.java deleted file mode 100644 index 8e6e1a8..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LeadItemMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.item.LeadItem; -import net.minecraft.util.ActionResult; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(LeadItem.class) -public class LeadItemMixin { - - @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) - void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { - World world = context.getWorld(); - PlayerEntity player = context.getPlayer(); - if (!world.isClient() && player != null) { - if (!WorldProtection.canModify(world, context.getBlockPos(), player)) { - ServerUtils.protectionWarning(player, "fence"); - player.getInventory().updateItems(); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LeashKnotEntityMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LeashKnotEntityMixin.java deleted file mode 100644 index 73aa2db..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LeashKnotEntityMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.decoration.LeashKnotEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(LeashKnotEntity.class) -public abstract class LeashKnotEntityMixin extends DecorationEntityMixin { - - public LeashKnotEntityMixin(EntityType type, World world) { - super(type, world); - } - - @Inject(method = "interact", at = @At("HEAD"), cancellable = true) - void interact(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - if (!getWorld().isClient() && player != null) { - if (!WorldProtection.canModify(getWorld(), attachmentPos, player)) { - ServerUtils.protectionWarning(player, "leash"); - player.getInventory().updateItems(); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LecternBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LecternBlockMixin.java deleted file mode 100644 index ebae5b0..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LecternBlockMixin.java +++ /dev/null @@ -1,37 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.LecternBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.state.property.BooleanProperty; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Final; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.Shadow; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(LecternBlock.class) -public class LecternBlockMixin { - - @Shadow - @Final - public static BooleanProperty HAS_BOOK; - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player) && !state.get(HAS_BOOK)) { - ServerUtils.protectionWarning(player, "lectern"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LeverMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LeverMixin.java deleted file mode 100644 index 7d59848..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LeverMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.LeverBlock; -import net.minecraft.block.WallMountedBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(LeverBlock.class) -public abstract class LeverMixin extends WallMountedBlock { - - public LeverMixin(Settings settings) { - super(settings); - } - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "redstone"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LivingEntityMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LivingEntityMixin.java deleted file mode 100644 index cf28f20..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/LivingEntityMixin.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.api.SkylandsAPI; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(LivingEntity.class) -public abstract class LivingEntityMixin extends Entity { - - public LivingEntityMixin(EntityType type, World world) { - super(type, world); - } - - @Inject(method = "damage", at = @At("HEAD"), cancellable = true) - void damage(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (!getWorld().isClient()) { - if ((LivingEntity) (Object) this instanceof PlayerEntity player) { - if (!WorldProtection.canModify(getWorld(), this.getBlockPos(), player) && !source.equals(getWorld().getDamageSources().outOfWorld()) && !SkylandsAPI.isHub(getWorld())) { - cir.setReturnValue(false); - } - } - if (source.getAttacker() instanceof PlayerEntity attacker) { - System.out.println(attacker.getDisplayName()); - System.out.println(this.getBlockPos()); - System.out.println(WorldProtection.canModify(getWorld(), this.getBlockPos(), attacker)); - if (!WorldProtection.canModify(getWorld(), this.getBlockPos(), attacker)) { - ServerUtils.protectionWarning(attacker, "entity_hurt"); - cir.setReturnValue(false); - } - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/MinecartMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/MinecartMixin.java deleted file mode 100644 index c850e4a..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/MinecartMixin.java +++ /dev/null @@ -1,32 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.damage.DamageSource; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.vehicle.AbstractMinecartEntity; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(AbstractMinecartEntity.class) -public abstract class MinecartMixin extends Entity { - - public MinecartMixin(EntityType type, World world) { - super(type, world); - } - - /*@Inject(method = "damage", at = @At("HEAD"), cancellable = true) - void damage(DamageSource source, float amount, CallbackInfoReturnable cir) { - if (!getWorld().isClient() && source.getAttacker() instanceof PlayerEntity attacker) { - if (!WorldProtection.canModify(getWorld(), getBlockPos(), attacker)) { - ServerUtils.protectionWarning(attacker, "entity_hurt"); - cir.setReturnValue(false); - } - } - }*/ -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/NoteBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/NoteBlockMixin.java deleted file mode 100644 index 6a5a955..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/NoteBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.NoteBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(NoteBlock.class) -public class NoteBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "noteblock"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PistonBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PistonBlockMixin.java deleted file mode 100644 index 53692d0..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PistonBlockMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import net.minecraft.block.AirBlock; -import net.minecraft.block.BlockState; -import net.minecraft.block.PistonBlock; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(PistonBlock.class) -public class PistonBlockMixin { - - @Inject(method = "isMovable", at = @At("HEAD"), cancellable = true) - private static void isMovable(BlockState state, World world, BlockPos pos, Direction direction, boolean canBreak, Direction pistonDir, CallbackInfoReturnable cir) { - if ((!WorldProtection.isWithinIsland(world, pos.offset(direction)) || !WorldProtection.isWithinIsland(world, pos)) && !(state.getBlock() instanceof AirBlock)) { - cir.setReturnValue(false); - } - } - - @Inject(method = "move", at = @At("HEAD"), cancellable = true) - private void move(World world, BlockPos pos, Direction dir, boolean retract, CallbackInfoReturnable cir) { - if ((!WorldProtection.isWithinIsland(world, pos.offset(dir)) || !WorldProtection.isWithinIsland(world, pos)) && !(world.getBlockState(pos).getBlock() instanceof AirBlock)) { - cir.setReturnValue(false); - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PlayerEntityMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PlayerEntityMixin.java deleted file mode 100644 index 5b4f198..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PlayerEntityMixin.java +++ /dev/null @@ -1,42 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(PlayerEntity.class) -public class PlayerEntityMixin { - - @Inject(method = "canPlaceOn", at = @At("HEAD"), cancellable = true) - private void canPlaceOn(BlockPos pos, Direction facing, ItemStack stack, CallbackInfoReturnable cir) { - PlayerEntity player = (PlayerEntity) (Object) this; - World world = player.getWorld(); - if (!world.isClient()) { - BlockPos blockPos = pos.offset(facing); - if (!WorldProtection.canModify(world, blockPos, player)) { - ServerUtils.protectionWarning(player, "place_on"); - cir.setReturnValue(false); - } - } - } - - @Inject(method = "canModifyBlocks", at = @At("HEAD"), cancellable = true) - private void canModifyBlocks(CallbackInfoReturnable cir) { - PlayerEntity player = (PlayerEntity) (Object) this; - World world = player.getWorld(); - if (!world.isClient()) { - if (!WorldProtection.canModify(world, player)) { - ServerUtils.protectionWarning(player, "modify"); - cir.setReturnValue(false); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PotionEntityMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PotionEntityMixin.java index 10e049a..7e70492 100644 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PotionEntityMixin.java +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PotionEntityMixin.java @@ -1,5 +1,7 @@ package com.awakenedredstone.neoskies.mixin.world.protection; +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; +import com.awakenedredstone.neoskies.logic.tags.NeoSkiesBlockTags; import com.awakenedredstone.neoskies.util.ServerUtils; import net.minecraft.block.AbstractCandleBlock; import net.minecraft.block.BlockState; @@ -27,14 +29,12 @@ public PotionEntityMixin(EntityType entityType, Worl @Inject(method = "extinguishFire", at = @At("HEAD"), cancellable = true) void interact(BlockPos pos, CallbackInfo ci) { if (!getWorld().isClient()) { - if ((getOwner() instanceof PlayerEntity player && !WorldProtection.canModify(getWorld(), pos, player))) { + if ((getOwner() instanceof PlayerEntity player && !WorldProtection.canModify(getWorld(), pos, player, NeoSkiesIslandSettings.BREAK_BLOCKS))) { BlockState blockState = this.getWorld().getBlockState(pos); - if (blockState.isIn(BlockTags.FIRE) || AbstractCandleBlock.isLitCandle(blockState) || CampfireBlock.isLitCampfire(blockState)) { - ServerUtils.protectionWarning(player, "extinguish"); + if (blockState.isIn(NeoSkiesBlockTags.EXTINGUISHABLE)) { + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.BREAK_BLOCKS); } ci.cancel(); - } else if (!WorldProtection.isWithinIsland(getWorld(), pos)) { - ci.cancel(); } } } diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PumpkinBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PumpkinBlockMixin.java deleted file mode 100644 index d24afea..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PumpkinBlockMixin.java +++ /dev/null @@ -1,33 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.PumpkinBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ShearsItem; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(PumpkinBlock.class) -public class PumpkinBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - if (player.getMainHandStack().getItem() instanceof ShearsItem) { - ServerUtils.protectionWarning(player, "shears_use"); - } - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/RedstoneWireMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/RedstoneWireMixin.java deleted file mode 100644 index 5455098..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/RedstoneWireMixin.java +++ /dev/null @@ -1,67 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.RedstoneWireBlock; -import net.minecraft.block.enums.WireConnection; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.Direction; -import net.minecraft.world.BlockView; -import net.minecraft.world.World; -import net.minecraft.world.WorldAccess; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(RedstoneWireBlock.class) -public class RedstoneWireMixin extends Block { - - public RedstoneWireMixin(Settings settings) { - super(settings); - } - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void preventInteraction(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "redstone"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } - - @Inject(method = "update", at = @At("HEAD"), cancellable = true) - void preventActivation(World world, BlockPos pos, BlockState state, CallbackInfo ci) { - if (!world.isClient()) { - if (!WorldProtection.isWithinIsland(world, pos)) { - ci.cancel(); - } - } - } - - @Inject(method = "getStateForNeighborUpdate", at = @At("HEAD"), cancellable = true) - void preventChange(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.isWithinIsland((World) world, pos) || !WorldProtection.isWithinIsland((World) world, neighborPos)) { - cir.setReturnValue(state); - } - } - } - - @Inject(method = "getRenderConnectionType(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;Z)Lnet/minecraft/block/enums/WireConnection;", at = @At("HEAD"), cancellable = true) - private void preventConnection(BlockView world, BlockPos pos, Direction direction, boolean bl, CallbackInfoReturnable cir) { - if (!((World) world).isClient()) { - if (!WorldProtection.isWithinIsland((World) world, pos.offset(direction))) { - cir.setReturnValue(WireConnection.NONE); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/RepeaterMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/RepeaterMixin.java deleted file mode 100644 index 4eafa4f..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/RepeaterMixin.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.AbstractRedstoneGateBlock; -import net.minecraft.block.BlockState; -import net.minecraft.block.RepeaterBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(RepeaterBlock.class) -public abstract class RepeaterMixin extends AbstractRedstoneGateBlock { - - protected RepeaterMixin(Settings settings) { - super(settings); - } - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "redstone"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/RespawnAnchorBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/RespawnAnchorBlockMixin.java deleted file mode 100644 index eb68184..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/RespawnAnchorBlockMixin.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.RespawnAnchorBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(RespawnAnchorBlock.class) -public class RespawnAnchorBlockMixin { - - //TODO: There was a todo here, idk why - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "interact"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SculkSpreadCursorMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SculkSpreadCursorMixin.java deleted file mode 100644 index 3e3c28a..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SculkSpreadCursorMixin.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import net.minecraft.block.entity.SculkSpreadManager; -import net.minecraft.server.world.ServerWorld; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.random.Random; -import net.minecraft.world.WorldAccess; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(SculkSpreadManager.Cursor.class) -public class SculkSpreadCursorMixin { - - @Inject(method = "spread", at = @At("HEAD"), cancellable = true) - private void spread(WorldAccess world, BlockPos pos, Random random, SculkSpreadManager spreadManager, boolean shouldConvertToBlock, CallbackInfo ci) { - if (world instanceof ServerWorld serverWorld) { - if (!WorldProtection.isWithinIsland(serverWorld, pos)) { - ci.cancel(); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ServerPlayerInteractionManagerMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ServerPlayerInteractionManagerMixin.java new file mode 100644 index 0000000..04780b2 --- /dev/null +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ServerPlayerInteractionManagerMixin.java @@ -0,0 +1,84 @@ +package com.awakenedredstone.neoskies.mixin.world.protection; + +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; +import com.awakenedredstone.neoskies.logic.settings.IslandSettings; +import com.awakenedredstone.neoskies.util.ServerUtils; +import com.awakenedredstone.neoskies.util.WorldProtection; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.item.ItemStack; +import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; +import net.minecraft.registry.tag.TagKey; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.server.network.ServerPlayerInteractionManager; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +import java.util.Map; + +@Mixin(ServerPlayerInteractionManager.class) +public class ServerPlayerInteractionManagerMixin { + + @Inject(method = "interactBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;onUse(Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ActionResult;"), cancellable = true) + private void onUse(ServerPlayerEntity player, World world, ItemStack stack, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable cir) { + if (!world.isClient()) { + BlockPos pos = hitResult.getBlockPos(); + BlockState state = world.getBlockState(pos); + + IslandSettings settings = null; + + for (Map.Entry, IslandSettings> entry : NeoSkiesIslandSettings.getRuleBlockTags().entrySet()) { + if (state.isIn(entry.getKey())) { + settings = entry.getValue(); + break; + } + } + + if (settings == null) { + return; + } + + if (!WorldProtection.canModify(world, pos, player, settings)) { + ServerUtils.protectionWarning(player, settings.getTranslationKey()); + int slot = hand == Hand.MAIN_HAND ? player.getInventory().selectedSlot : 40; + player.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(ScreenHandlerSlotUpdateS2CPacket.UPDATE_PLAYER_INVENTORY_SYNC_ID, 0, slot, stack)); + cir.setReturnValue(ActionResult.FAIL); + } + } + } + + @Inject(method = "interactBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;onUseWithItem(Lnet/minecraft/item/ItemStack;Lnet/minecraft/world/World;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/Hand;Lnet/minecraft/util/hit/BlockHitResult;)Lnet/minecraft/util/ItemActionResult;"), cancellable = true) + private void onUseWithItem(ServerPlayerEntity player, World world, ItemStack stack, Hand hand, BlockHitResult hitResult, CallbackInfoReturnable cir) { + if (!world.isClient()) { + BlockPos pos = hitResult.getBlockPos(); + BlockState state = world.getBlockState(pos); + + IslandSettings settings = null; + + for (Map.Entry, IslandSettings> entry : NeoSkiesIslandSettings.getRuleBlockUseTag().entrySet()) { + if (state.isIn(entry.getKey())) { + settings = entry.getValue(); + break; + } + } + + if (settings == null) { + return; + } + + if (!WorldProtection.canModify(world, pos, player, settings)) { + ServerUtils.protectionWarning(player, settings.getTranslationKey()); + int slot = hand == Hand.MAIN_HAND ? player.getInventory().selectedSlot : 40; + player.networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(ScreenHandlerSlotUpdateS2CPacket.UPDATE_PLAYER_INVENTORY_SYNC_ID, 0, slot, stack)); + cir.setReturnValue(ActionResult.FAIL); + } + } + } +} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ShulkerBoxBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ShulkerBoxBlockMixin.java deleted file mode 100644 index fc872af..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ShulkerBoxBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.ShulkerBoxBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(ShulkerBoxBlock.class) -public class ShulkerBoxBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "shulker_box_open"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/StorageMinecartMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/StorageMinecartMixin.java deleted file mode 100644 index 53f7d59..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/StorageMinecartMixin.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.vehicle.StorageMinecartEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(StorageMinecartEntity.class) -public class StorageMinecartMixin { - - @Inject(method = "interact", at = @At("HEAD"), cancellable = true) - void interact(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - if (!player.getWorld().isClient()) { - if (!WorldProtection.canModify(player.getWorld(), player)) { - ServerUtils.protectionWarning(player, "minecart_open"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } - -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SweetBerryBushBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SweetBerryBushBlockMixin.java deleted file mode 100644 index 3075619..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SweetBerryBushBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.SweetBerryBushBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(SweetBerryBushBlock.class) -public class SweetBerryBushBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "interact"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/TntBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/TntBlockMixin.java deleted file mode 100644 index 566bc7b..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/TntBlockMixin.java +++ /dev/null @@ -1,93 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.block.TntBlock; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.projectile.ProjectileEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import net.minecraft.world.explosion.Explosion; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(TntBlock.class) -public class TntBlockMixin { - - @Inject(method = "primeTnt(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/LivingEntity;)V", at = @At("HEAD"), cancellable = true) - private static void primeTnt(World world, BlockPos pos, LivingEntity igniter, CallbackInfo ci) { - if (!world.isClient()) { - if (!WorldProtection.isWithinIsland(world, pos)) { - ci.cancel(); - } - } - } - - @Inject(method = "onProjectileHit", at = @At("HEAD"), cancellable = true) - private void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile, CallbackInfo ci) { - if (!world.isClient()) { - if (!WorldProtection.isWithinIsland(world, hit.getBlockPos())) { - ci.cancel(); - } - } - } - - @Inject(method = "neighborUpdate", at = @At("HEAD"), cancellable = true) - private void neighborUpdate(BlockState state, World world, BlockPos pos, Block sourceBlock, BlockPos sourcePos, boolean notify, CallbackInfo ci) { - if (!world.isClient()) { - if (!WorldProtection.isWithinIsland(world, pos)) { - ci.cancel(); - } - } - } - - @Inject(method = "onBlockAdded", at = @At("HEAD"), cancellable = true) - private void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify, CallbackInfo ci) { - if (!world.isClient()) { - if (!WorldProtection.isWithinIsland(world, pos)) { - ci.cancel(); - } - } - } - - @Inject(method = "onDestroyedByExplosion", at = @At("HEAD"), cancellable = true) - private void onDestroyedByExplosion(World world, BlockPos pos, Explosion explosion, CallbackInfo ci) { - if (!world.isClient()) { - if (!WorldProtection.isWithinIsland(world, pos)) { - ci.cancel(); - } - } - } - - @Inject(method = "onBreak", at = @At("HEAD"), cancellable = true) - private void onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "tnt_break"); - cir.setReturnValue(state); - } - } - } - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - private void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ItemStack itemStack = player.getStackInHand(hand); - if (!itemStack.isOf(Items.FLINT_AND_STEEL) && !itemStack.isOf(Items.FIRE_CHARGE)) ServerUtils.protectionWarning(player, "tnt_ignite"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/TrapdoorBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/TrapdoorBlockMixin.java deleted file mode 100644 index 19bbf05..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/TrapdoorBlockMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.BlockState; -import net.minecraft.block.TrapdoorBlock; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(TrapdoorBlock.class) -public class TrapdoorBlockMixin { - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - ServerUtils.protectionWarning(player, "trapdoor_open"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/VibrationListenerMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/VibrationListenerMixin.java index 63a9252..1242d32 100644 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/VibrationListenerMixin.java +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/VibrationListenerMixin.java @@ -1,7 +1,10 @@ package com.awakenedredstone.neoskies.mixin.world.protection; import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; +import net.minecraft.entity.Entity; +import net.minecraft.entity.Ownable; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.Vec3d; @@ -12,6 +15,7 @@ import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; import com.awakenedredstone.neoskies.util.WorldProtection; @@ -19,12 +23,10 @@ @Mixin(Vibrations.VibrationListener.class) public abstract class VibrationListenerMixin { + @Shadow public abstract PositionSource getPositionSource(); - @Shadow - public abstract PositionSource getPositionSource(); - - @Inject(method = "listen*", at = @At("HEAD"), cancellable = true) - private void accept(ServerWorld world, GameEvent event, GameEvent.Emitter emitter, Vec3d emitterPos, CallbackInfoReturnable cir) { + @Inject(method = "listen(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/registry/entry/RegistryEntry;Lnet/minecraft/world/event/GameEvent$Emitter;Lnet/minecraft/util/math/Vec3d;)Z", at = @At("HEAD"), cancellable = true) + private void manageVibrations0(ServerWorld world, RegistryEntry event, GameEvent.Emitter emitter, Vec3d emitterPos, CallbackInfoReturnable cir) { if (!world.isClient()) { Optional optional = getPositionSource().getPos(world); if (optional.isEmpty()) return; @@ -34,4 +36,30 @@ private void accept(ServerWorld world, GameEvent event, GameEvent.Emitter emitte } } } + + @Inject(method = "listen(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/world/event/Vibrations$ListenerData;Lnet/minecraft/registry/entry/RegistryEntry;Lnet/minecraft/world/event/GameEvent$Emitter;Lnet/minecraft/util/math/Vec3d;Lnet/minecraft/util/math/Vec3d;)V", at = @At("HEAD"), cancellable = true) + private void manageVibrations1(ServerWorld world, Vibrations.ListenerData listenerData, RegistryEntry event, GameEvent.Emitter emitter, Vec3d emitterPos, Vec3d listenerPos, CallbackInfo ci) { + if (!world.isClient()) { + Optional optional = getPositionSource().getPos(world); + if (optional.isEmpty()) return; + BlockPos pos = BlockPos.ofFloored(optional.get()); + Entity entity = emitter.sourceEntity(); + + PlayerEntity player = null; + + if (entity instanceof PlayerEntity) { + player = (PlayerEntity) entity; + } else if (entity instanceof Ownable ownable && ownable.getOwner() instanceof PlayerEntity owner) { + player = owner; + } + + if (player == null) { + return; + } + + if (!WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.INTERACT_SCULK)) { + ci.cancel(); + } + } + } } diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/VillagerEntityMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/VillagerEntityMixin.java deleted file mode 100644 index e107cb4..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/VillagerEntityMixin.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.passive.VillagerEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.util.ActionResult; -import net.minecraft.util.Hand; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(VillagerEntity.class) -public class VillagerEntityMixin { - - @Inject(method = "interactMob", at = @At("HEAD"), cancellable = true) - void interact(PlayerEntity player, Hand hand, CallbackInfoReturnable cir) { - if (!player.getWorld().isClient()) { - if (!WorldProtection.canModify(player.getWorld(), player)) { - ServerUtils.protectionWarning(player, "villager_use"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } - -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/WorldMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/WorldMixin.java deleted file mode 100644 index 3997677..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/WorldMixin.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.logic.Skylands; -import net.minecraft.block.BlockState; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.SkylandsMain; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(World.class) -public class WorldMixin { - - @Inject(method = "setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;II)Z", at = @At("HEAD"), cancellable = true) - private void setBlockState(BlockPos pos, BlockState state, int flags, int maxUpdateDepth, CallbackInfoReturnable cir) { - if (!Skylands.getConfig().disableBlocksOutsideIslands) return; - if (!WorldProtection.isWithinIsland((World) (Object) this, pos)) cir.setReturnValue(false); - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/WritableBookItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/WritableBookItemMixin.java deleted file mode 100644 index 71acdcd..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/WritableBookItemMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.item.WritableBookItem; -import net.minecraft.util.ActionResult; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(WritableBookItem.class) -public class WritableBookItemMixin { - - @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) - void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { - World world = context.getWorld(); - PlayerEntity player = context.getPlayer(); - if (!world.isClient() && player != null) { - if (!WorldProtection.canModify(world, context.getBlockPos(), player)) { - ServerUtils.protectionWarning(player, "lectern"); - player.getInventory().updateItems(); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/WrittenBookItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/WrittenBookItemMixin.java deleted file mode 100644 index f45de03..0000000 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/WrittenBookItemMixin.java +++ /dev/null @@ -1,30 +0,0 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; - -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.ItemUsageContext; -import net.minecraft.item.WrittenBookItem; -import net.minecraft.util.ActionResult; -import net.minecraft.world.World; -import org.spongepowered.asm.mixin.Mixin; -import org.spongepowered.asm.mixin.injection.At; -import org.spongepowered.asm.mixin.injection.Inject; -import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; - -@Mixin(WrittenBookItem.class) -public class WrittenBookItemMixin { - - @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) - void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { - World world = context.getWorld(); - PlayerEntity player = context.getPlayer(); - if (!world.isClient() && player != null) { - if (!WorldProtection.canModify(world, context.getBlockPos(), player)) { - ServerUtils.protectionWarning(player, "lectern"); - player.getInventory().updateItems(); - cir.setReturnValue(ActionResult.FAIL); - } - } - } -} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/AbstractCandleBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/AbstractCandleBlockMixin.java similarity index 66% rename from src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/AbstractCandleBlockMixin.java rename to src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/AbstractCandleBlockMixin.java index 0bf32f8..5e8e644 100644 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/AbstractCandleBlockMixin.java +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/AbstractCandleBlockMixin.java @@ -1,5 +1,6 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; +package com.awakenedredstone.neoskies.mixin.world.protection.block; +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; import com.awakenedredstone.neoskies.util.ServerUtils; import net.minecraft.block.AbstractCandleBlock; import net.minecraft.block.BlockState; @@ -16,15 +17,12 @@ @Mixin(AbstractCandleBlock.class) public class AbstractCandleBlockMixin { - - @Inject(method = "onProjectileHit", at = @At("HEAD"), cancellable = true) + @Inject(method = "onProjectileHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/AbstractCandleBlock;setLit(Lnet/minecraft/world/WorldAccess;Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Z)V", shift = At.Shift.BEFORE), cancellable = true) private void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile, CallbackInfo ci) { if (!world.isClient()) { BlockPos pos = hit.getBlockPos(); - if ((projectile.getOwner() instanceof PlayerEntity player && !WorldProtection.canModify(world, pos, player))) { - if (projectile.isOnFire()) ServerUtils.protectionWarning(player, "ignite"); - ci.cancel(); - } else if (!WorldProtection.isWithinIsland(world, pos)) { + if ((projectile.getOwner() instanceof PlayerEntity player && !WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.PLACE_BLOCKS))) { + if (projectile.isOnFire()) ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.PLACE_BLOCKS); ci.cancel(); } } diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/BigDripLeafMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/BigDripLeafMixin.java new file mode 100644 index 0000000..b408765 --- /dev/null +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/BigDripLeafMixin.java @@ -0,0 +1,59 @@ +package com.awakenedredstone.neoskies.mixin.world.protection.block; + +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; +import com.awakenedredstone.neoskies.util.WorldProtection; +import net.minecraft.block.BigDripleafBlock; +import net.minecraft.block.BlockState; +import net.minecraft.entity.Entity; +import net.minecraft.entity.Ownable; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.projectile.ProjectileEntity; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(BigDripleafBlock.class) +public abstract class BigDripLeafMixin { + @Inject(method = "onProjectileHit", at = @At("HEAD"), cancellable = true) + private void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile, CallbackInfo ci) { + if (!world.isClient()) { + PlayerEntity player = null; + if (projectile.getOwner() instanceof PlayerEntity owner) { + player = owner; + } + + if (player == null) { + return; + } + + BlockPos pos = hit.getBlockPos(); + if (!WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.INTERACT_DRIPLEAF)) { + ci.cancel(); + } + } + } + + @Inject(method = "onEntityCollision", at = @At("HEAD"), cancellable = true) + private void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity, CallbackInfo ci) { + if (!world.isClient()) { + PlayerEntity player = null; + if (entity instanceof PlayerEntity) { + player = (PlayerEntity) entity; + } else if (entity instanceof Ownable ownable && ownable.getOwner() instanceof PlayerEntity owner) { + player = owner; + } + + if (player == null) { + return; + } + + if (!WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.INTERACT_DRIPLEAF)) { + ci.cancel(); + } + } + } +} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/ButtonBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/ButtonBlockMixin.java new file mode 100644 index 0000000..ea9fd08 --- /dev/null +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/ButtonBlockMixin.java @@ -0,0 +1,38 @@ +package com.awakenedredstone.neoskies.mixin.world.protection.block; + +import blue.endless.jankson.annotation.Nullable; +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; +import com.awakenedredstone.neoskies.util.WorldProtection; +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.block.BlockState; +import net.minecraft.block.ButtonBlock; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.projectile.PersistentProjectileEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(ButtonBlock.class) +public class ButtonBlockMixin { + @Inject(method = "tryPowerWithProjectiles", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;get(Lnet/minecraft/state/property/Property;)Ljava/lang/Comparable;", shift = At.Shift.BEFORE), cancellable = true) + private void onProjectileHit(BlockState state, World world, BlockPos pos, CallbackInfo ci, @Nullable @Local PersistentProjectileEntity projectile) { + if (projectile == null) return; + if (!world.isClient()) { + PlayerEntity player = null; + if (projectile.getOwner() instanceof PlayerEntity owner) { + player = owner; + } + + if (player == null) { + return; + } + + if (!WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.USE_REDSTONE)) { + ci.cancel(); + } + } + } +} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CampfireBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/CampfireBlockMixin.java similarity index 68% rename from src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CampfireBlockMixin.java rename to src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/CampfireBlockMixin.java index df1225f..d5566bd 100644 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/CampfireBlockMixin.java +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/CampfireBlockMixin.java @@ -1,13 +1,16 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; +package com.awakenedredstone.neoskies.mixin.world.protection.block; +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; import com.awakenedredstone.neoskies.util.ServerUtils; import net.minecraft.block.BlockState; import net.minecraft.block.CampfireBlock; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.ProjectileEntity; +import net.minecraft.item.ItemStack; import net.minecraft.state.property.BooleanProperty; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; +import net.minecraft.util.ItemActionResult; import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -22,27 +25,12 @@ @Mixin(CampfireBlock.class) public class CampfireBlockMixin { - - @Shadow - @Final - public static BooleanProperty LIT; - - @Inject(method = "onUse", at = @At("HEAD"), cancellable = true) - void onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { - if (!world.isClient()) { - if (!WorldProtection.canModify(world, pos, player)) { - if (state.get(LIT)) ServerUtils.protectionWarning(player, "interact"); - cir.setReturnValue(ActionResult.FAIL); - } - } - } - @Inject(method = "onProjectileHit", at = @At("HEAD"), cancellable = true) private void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile, CallbackInfo ci) { if (!world.isClient()) { BlockPos pos = hit.getBlockPos(); - if ((projectile.getOwner() instanceof PlayerEntity player && !WorldProtection.canModify(world, pos, player))) { - if (projectile.isOnFire()) ServerUtils.protectionWarning(player, "ignite"); + if ((projectile.getOwner() instanceof PlayerEntity player && !WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.USE_CONTAINERS))) { + if (projectile.isOnFire()) ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.USE_CONTAINERS); ci.cancel(); } else if (!WorldProtection.isWithinIsland(world, pos)) { ci.cancel(); diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/CauldronBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/CauldronBlockMixin.java new file mode 100644 index 0000000..c78b767 --- /dev/null +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/CauldronBlockMixin.java @@ -0,0 +1,37 @@ +package com.awakenedredstone.neoskies.mixin.world.protection.block; + +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; +import com.awakenedredstone.neoskies.util.ServerUtils; +import net.minecraft.block.AbstractCauldronBlock; +import net.minecraft.block.BlockState; +import net.minecraft.block.cauldron.CauldronBehavior; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.ItemActionResult; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Final; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.Shadow; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; +import com.awakenedredstone.neoskies.util.WorldProtection; + +@Mixin(AbstractCauldronBlock.class) +public class CauldronBlockMixin { + @Shadow @Final protected CauldronBehavior.CauldronBehaviorMap behaviorMap; + + @Inject(method = "onUseWithItem", at = @At("HEAD"), cancellable = true) + void onUse(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { + if (!world.isClient()) { + if (behaviorMap.map().containsKey(stack.getItem()) && !WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.USE_CONTAINERS)) { + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.USE_CONTAINERS); + cir.setReturnValue(ItemActionResult.FAIL); + } + } + } +} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/LightningRodBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/LightningRodBlockMixin.java new file mode 100644 index 0000000..b46f335 --- /dev/null +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/LightningRodBlockMixin.java @@ -0,0 +1,38 @@ +package com.awakenedredstone.neoskies.mixin.world.protection.block; + +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; +import com.awakenedredstone.neoskies.util.ServerUtils; +import com.awakenedredstone.neoskies.util.WorldProtection; +import net.minecraft.block.BlockState; +import net.minecraft.block.LightningRodBlock; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.projectile.ProjectileEntity; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(LightningRodBlock.class) +public class LightningRodBlockMixin { + @Inject(method = "onProjectileHit", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityType;create(Lnet/minecraft/world/World;)Lnet/minecraft/entity/Entity;"), cancellable = true) + private void preventStrike(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile, CallbackInfo ci) { + if (!world.isClient()) { + PlayerEntity player = null; + + if (projectile.getOwner() instanceof PlayerEntity owner) { + player = owner; + } + + if (player == null) { + return; + } + + if (!WorldProtection.canModify(world, hit.getBlockPos(), player, NeoSkiesIslandSettings.USE_REDSTONE)) { + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.USE_REDSTONE); + ci.cancel(); + } + } + } +} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PressurePlateBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/PressurePlateBlockMixin.java similarity index 58% rename from src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PressurePlateBlockMixin.java rename to src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/PressurePlateBlockMixin.java index 3bd5c48..8d3113e 100644 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/PressurePlateBlockMixin.java +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/PressurePlateBlockMixin.java @@ -1,9 +1,11 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; +package com.awakenedredstone.neoskies.mixin.world.protection.block; -import com.awakenedredstone.neoskies.util.ServerUtils; +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; +import com.awakenedredstone.neoskies.util.WorldProtection; import net.minecraft.block.AbstractPressurePlateBlock; import net.minecraft.block.BlockState; import net.minecraft.entity.Entity; +import net.minecraft.entity.Ownable; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -11,18 +13,25 @@ import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.awakenedredstone.neoskies.util.WorldProtection; @Mixin(AbstractPressurePlateBlock.class) public class PressurePlateBlockMixin { - @Inject(method = "updatePlateState", at = @At("HEAD"), cancellable = true) private void updatePlateState(Entity entity, World world, BlockPos pos, BlockState state, int output, CallbackInfo ci) { if (!world.isClient()) { - if ((entity instanceof PlayerEntity player && !WorldProtection.canModify(world, pos, player))) { - ServerUtils.protectionWarning(player, "redstone"); - ci.cancel(); - } else if (!WorldProtection.isWithinIsland(world, pos)) { + PlayerEntity player = null; + + if (entity instanceof PlayerEntity) { + player = (PlayerEntity) entity; + } else if (entity instanceof Ownable ownable && ownable.getOwner() instanceof PlayerEntity owner) { + player = owner; + } + + if (player == null) { + return; + } + + if (!WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.USE_REDSTONE)) { ci.cancel(); } } diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SculkSensorBlockEntityMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/SculkSensorBlockEntityMixin.java similarity index 50% rename from src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SculkSensorBlockEntityMixin.java rename to src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/SculkSensorBlockEntityMixin.java index 298dada..a26872e 100644 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SculkSensorBlockEntityMixin.java +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/SculkSensorBlockEntityMixin.java @@ -1,12 +1,15 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; +package com.awakenedredstone.neoskies.mixin.world.protection.block; import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; import net.minecraft.block.entity.SculkSensorBlockEntity; import net.minecraft.entity.Entity; +import net.minecraft.entity.Ownable; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.world.event.GameEvent; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -17,9 +20,20 @@ public class SculkSensorBlockEntityMixin { @Inject(method = "accept", at = @At("HEAD"), cancellable = true) - private void accept(ServerWorld world, BlockPos pos, GameEvent event, Entity sourceEntity, Entity entity, float distance, CallbackInfo ci) { + private void accept(ServerWorld world, BlockPos pos, RegistryEntry event, @Nullable Entity sourceEntity, @Nullable Entity entity, float distance, CallbackInfo ci) { if (!world.isClient()) { - if ((entity instanceof PlayerEntity player && !WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.INTERACT_SCULK))) { + PlayerEntity player = null; + + if (entity instanceof PlayerEntity) { + player = (PlayerEntity) entity; + } else if (entity instanceof Ownable ownable && ownable.getOwner() instanceof PlayerEntity owner) { + player = owner; + } + + if (player == null) { + return; + } + if (!WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.INTERACT_SCULK)) { ci.cancel(); } } diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SculkShriekerBlockEntityMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/SculkShriekerBlockEntityMixin.java similarity index 51% rename from src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SculkShriekerBlockEntityMixin.java rename to src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/SculkShriekerBlockEntityMixin.java index e607bd1..9261095 100644 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SculkShriekerBlockEntityMixin.java +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/SculkShriekerBlockEntityMixin.java @@ -1,12 +1,15 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; +package com.awakenedredstone.neoskies.mixin.world.protection.block; import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; import net.minecraft.block.entity.SculkShriekerBlockEntity; import net.minecraft.entity.Entity; +import net.minecraft.entity.Ownable; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.registry.entry.RegistryEntry; import net.minecraft.server.world.ServerWorld; import net.minecraft.util.math.BlockPos; import net.minecraft.world.event.GameEvent; +import org.jetbrains.annotations.Nullable; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; @@ -17,9 +20,21 @@ public class SculkShriekerBlockEntityMixin { @Inject(method = "accept", at = @At("HEAD"), cancellable = true) - private void accept(ServerWorld world, BlockPos pos, GameEvent event, Entity sourceEntity, Entity entity, float distance, CallbackInfo ci) { + private void accept(ServerWorld world, BlockPos pos, RegistryEntry event, @Nullable Entity sourceEntity, @Nullable Entity entity, float distance, CallbackInfo ci) { if (!world.isClient()) { - if ((entity instanceof PlayerEntity player && !WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.INTERACT_SCULK))) { + PlayerEntity player = null; + + if (entity instanceof PlayerEntity) { + player = (PlayerEntity) entity; + } else if (entity instanceof Ownable ownable && ownable.getOwner() instanceof PlayerEntity owner) { + player = owner; + } + + if (player == null) { + return; + } + + if (!WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.INTERACT_SCULK)) { ci.cancel(); } } diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SculkShriekerBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/SculkShriekerBlockMixin.java similarity index 61% rename from src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SculkShriekerBlockMixin.java rename to src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/SculkShriekerBlockMixin.java index 5d069a1..58248f3 100644 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/SculkShriekerBlockMixin.java +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/SculkShriekerBlockMixin.java @@ -1,9 +1,10 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; +package com.awakenedredstone.neoskies.mixin.world.protection.block; import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; import net.minecraft.block.BlockState; import net.minecraft.block.SculkShriekerBlock; import net.minecraft.entity.Entity; +import net.minecraft.entity.Ownable; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -19,7 +20,19 @@ public class SculkShriekerBlockMixin { @Inject(method = "onSteppedOn", at = @At("HEAD"), cancellable = true) private void onSteppedOn(World world, BlockPos pos, BlockState state, Entity entity, CallbackInfo ci) { if (!world.isClient()) { - if ((entity instanceof PlayerEntity player && !WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.INTERACT_SCULK))) { + PlayerEntity player = null; + + if (entity instanceof PlayerEntity) { + player = (PlayerEntity) entity; + } else if (entity instanceof Ownable ownable && ownable.getOwner() instanceof PlayerEntity owner) { + player = owner; + } + + if (player == null) { + return; + } + + if (!WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.INTERACT_SCULK)) { ci.cancel(); } } diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/TargetBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/TargetBlockMixin.java similarity index 77% rename from src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/TargetBlockMixin.java rename to src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/TargetBlockMixin.java index d0b6809..929d7a9 100644 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/TargetBlockMixin.java +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/TargetBlockMixin.java @@ -1,18 +1,18 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; +package com.awakenedredstone.neoskies.mixin.world.protection.block; +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; import com.awakenedredstone.neoskies.util.ServerUtils; +import com.awakenedredstone.neoskies.util.WorldProtection; import net.minecraft.block.BlockState; import net.minecraft.block.TargetBlock; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.util.hit.BlockHitResult; -import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; -import com.awakenedredstone.neoskies.util.WorldProtection; @Mixin(TargetBlock.class) public class TargetBlockMixin { @@ -21,15 +21,11 @@ public class TargetBlockMixin { private void useOnBlock(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile, CallbackInfo ci) { if (!world.isClient()) { if (projectile.getOwner() instanceof PlayerEntity player) { - if (!WorldProtection.canModify(world, hit.getBlockPos(), player)) { - ServerUtils.protectionWarning(player, "target"); + if (!WorldProtection.canModify(world, hit.getBlockPos(), player, NeoSkiesIslandSettings.USE_REDSTONE)) { + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.USE_REDSTONE); ci.cancel(); } } - - if (!WorldProtection.isWithinIsland(world, BlockPos.ofFloored(hit.getPos()))) { - ci.cancel(); - } } } } diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/TntBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/TntBlockMixin.java new file mode 100644 index 0000000..d123e73 --- /dev/null +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/TntBlockMixin.java @@ -0,0 +1,92 @@ +package com.awakenedredstone.neoskies.mixin.world.protection.block; + +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; +import com.awakenedredstone.neoskies.util.ServerUtils; +import com.awakenedredstone.neoskies.util.WorldProtection; +import net.minecraft.block.BlockState; +import net.minecraft.block.TntBlock; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.Ownable; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.entity.projectile.ProjectileEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Hand; +import net.minecraft.util.ItemActionResult; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import net.minecraft.world.explosion.Explosion; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(TntBlock.class) +public class TntBlockMixin { + @Inject(method = "primeTnt(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/LivingEntity;)V", at = @At("HEAD"), cancellable = true) + private static void primeTnt(World world, BlockPos pos, LivingEntity igniter, CallbackInfo ci) { + if (!world.isClient()) { + PlayerEntity player = null; + + if (igniter instanceof PlayerEntity) { + player = (PlayerEntity) igniter; + } else if (igniter instanceof Ownable ownable && ownable.getOwner() instanceof PlayerEntity owner) { + player = owner; + } + + if (player == null) { + return; + } + + if (!WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.USE_TNT, NeoSkiesIslandSettings.BREAK_BLOCKS)) { + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.USE_TNT); + ci.cancel(); + } + } + } + + @Inject(method = "onProjectileHit", at = @At("HEAD"), cancellable = true) + private void onProjectileHit(World world, BlockState state, BlockHitResult hit, ProjectileEntity projectile, CallbackInfo ci) { + if (!world.isClient()) { + PlayerEntity player = null; + + if (projectile.getOwner() instanceof PlayerEntity owner) { + player = owner; + } + + if (player == null) { + return; + } + + if (!WorldProtection.canModify(world, hit.getBlockPos(), player, NeoSkiesIslandSettings.USE_TNT, NeoSkiesIslandSettings.BREAK_BLOCKS)) { + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.USE_TNT); + ci.cancel(); + } + } + } + + @Inject(method = "onDestroyedByExplosion", at = @At("HEAD"), cancellable = true) + private void onDestroyedByExplosion(World world, BlockPos pos, Explosion explosion, CallbackInfo ci) { + if (!world.isClient()) { + LivingEntity causingEntity = explosion.getCausingEntity(); + if (causingEntity instanceof PlayerEntity player && !WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.USE_TNT, NeoSkiesIslandSettings.BREAK_BLOCKS)) { + ci.cancel(); + } + } + } + + @Inject(method = "onUseWithItem", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/TntBlock;primeTnt(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/LivingEntity;)V", shift = At.Shift.BEFORE), cancellable = true) + private void onUse(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit, CallbackInfoReturnable cir) { + if (!world.isClient()) { + if (!WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.USE_TNT, NeoSkiesIslandSettings.BREAK_BLOCKS)) { + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.USE_TNT); + int slot = hand == Hand.MAIN_HAND ? player.getInventory().selectedSlot : 40; + ((ServerPlayerEntity) player).networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(ScreenHandlerSlotUpdateS2CPacket.UPDATE_PLAYER_INVENTORY_SYNC_ID, 0, slot, stack)); + cir.setReturnValue(ItemActionResult.FAIL); + } + } + } +} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/TripwireBlockMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/TripwireBlockMixin.java new file mode 100644 index 0000000..a42d26f --- /dev/null +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/block/TripwireBlockMixin.java @@ -0,0 +1,40 @@ +package com.awakenedredstone.neoskies.mixin.world.protection.block; + +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; +import com.awakenedredstone.neoskies.util.WorldProtection; +import net.minecraft.block.BlockState; +import net.minecraft.block.TripwireBlock; +import net.minecraft.entity.Entity; +import net.minecraft.entity.Ownable; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; + +@Mixin(TripwireBlock.class) +public class TripwireBlockMixin { + @Inject(method = "onEntityCollision", at = @At("HEAD"), cancellable = true) + private void updatePlateState(BlockState state, World world, BlockPos pos, Entity entity, CallbackInfo ci) { + if (!world.isClient()) { + PlayerEntity player = null; + + if (entity instanceof PlayerEntity) { + player = (PlayerEntity) entity; + } else if (entity instanceof Ownable ownable && ownable.getOwner() instanceof PlayerEntity owner) { + player = owner; + } + + if (player == null) { + return; + } + + if (!WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.USE_REDSTONE)) { + + ci.cancel(); + } + } + } +} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/item/AxeItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/item/AxeItemMixin.java new file mode 100644 index 0000000..5a6ad9b --- /dev/null +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/item/AxeItemMixin.java @@ -0,0 +1,40 @@ +package com.awakenedredstone.neoskies.mixin.world.protection.item; + +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; +import com.awakenedredstone.neoskies.util.ServerUtils; +import com.llamalad7.mixinextras.injector.ModifyExpressionValue; +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.block.BlockState; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.AxeItem; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUsageContext; +import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.Hand; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import com.awakenedredstone.neoskies.util.WorldProtection; + +import java.util.Optional; + +@Mixin({AxeItem.class}) +public class AxeItemMixin { + @ModifyExpressionValue(method = "useOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/item/AxeItem;tryStrip(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/block/BlockState;)Ljava/util/Optional;")) + private Optional useOnBlock(Optional original, ItemUsageContext context, @Local World world, @Local PlayerEntity player, @Local BlockPos pos) { + if (!world.isClient() && player != null && original.isPresent()) { + if (!WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.PLACE_BLOCKS)) { + Hand hand = context.getHand(); + ItemStack stack = context.getStack(); + int slot = hand == Hand.MAIN_HAND ? player.getInventory().selectedSlot : 40; + ((ServerPlayerEntity) player).networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(ScreenHandlerSlotUpdateS2CPacket.UPDATE_PLAYER_INVENTORY_SYNC_ID, 0, slot, stack)); + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.PLACE_BLOCKS); + return Optional.empty(); + } + } + + return original; + } +} diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FlintAndSteelMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/item/FlintAndSteelMixin.java similarity index 58% rename from src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FlintAndSteelMixin.java rename to src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/item/FlintAndSteelMixin.java index 301a924..64408e1 100644 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/FlintAndSteelMixin.java +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/item/FlintAndSteelMixin.java @@ -1,31 +1,35 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; +package com.awakenedredstone.neoskies.mixin.world.protection.item; -import com.awakenedredstone.neoskies.util.ServerUtils; -import net.minecraft.block.TntBlock; +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; +import com.awakenedredstone.neoskies.util.WorldProtection; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.item.FlintAndSteelItem; +import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUsageContext; +import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; import org.spongepowered.asm.mixin.injection.Inject; import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; -import com.awakenedredstone.neoskies.util.WorldProtection; @Mixin(FlintAndSteelItem.class) public class FlintAndSteelMixin { - @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { World world = context.getWorld(); PlayerEntity player = context.getPlayer(); BlockPos blockPos = context.getBlockPos(); if (!world.isClient() && player != null) { - if (!WorldProtection.canModify(world, blockPos.offset(context.getSide()), player)) { - if (!(world.getBlockState(blockPos).getBlock() instanceof TntBlock)) - ServerUtils.protectionWarning(player, "flint_and_steel_use"); + if (!WorldProtection.canModify(world, blockPos.offset(context.getSide()), player, NeoSkiesIslandSettings.PLACE_BLOCKS)) { + Hand hand = context.getHand(); + ItemStack stack = context.getStack(); + int slot = hand == Hand.MAIN_HAND ? player.getInventory().selectedSlot : 40; + ((ServerPlayerEntity) player).networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(ScreenHandlerSlotUpdateS2CPacket.UPDATE_PLAYER_INVENTORY_SYNC_ID, 0, slot, stack)); cir.setReturnValue(ActionResult.FAIL); } } diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ShovelItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/item/ShovelItemMixin.java similarity index 54% rename from src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ShovelItemMixin.java rename to src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/item/ShovelItemMixin.java index 3d624d5..3e481bc 100644 --- a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/ShovelItemMixin.java +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/item/ShovelItemMixin.java @@ -1,10 +1,15 @@ -package com.awakenedredstone.neoskies.mixin.world.protection; +package com.awakenedredstone.neoskies.mixin.world.protection.item; +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; import com.awakenedredstone.neoskies.util.ServerUtils; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; import net.minecraft.item.ItemUsageContext; import net.minecraft.item.ShovelItem; +import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; +import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; import net.minecraft.world.World; import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.injection.At; @@ -14,14 +19,17 @@ @Mixin(ShovelItem.class) public class ShovelItemMixin { - @Inject(method = "useOnBlock", at = @At("HEAD"), cancellable = true) void useOnBlock(ItemUsageContext context, CallbackInfoReturnable cir) { World world = context.getWorld(); PlayerEntity player = context.getPlayer(); if (!world.isClient() && player != null) { - if (!WorldProtection.canModify(world, context.getBlockPos(), player)) { - ServerUtils.protectionWarning(player, "shovel_use"); + if (!WorldProtection.canModify(world, context.getBlockPos(), player, NeoSkiesIslandSettings.PLACE_BLOCKS)) { + Hand hand = context.getHand(); + ItemStack stack = context.getStack(); + int slot = hand == Hand.MAIN_HAND ? player.getInventory().selectedSlot : 40; + ((ServerPlayerEntity) player).networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(ScreenHandlerSlotUpdateS2CPacket.UPDATE_PLAYER_INVENTORY_SYNC_ID, 0, slot, stack)); + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.PLACE_BLOCKS); cir.setReturnValue(ActionResult.FAIL); } } diff --git a/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/item/SpawnEggItemMixin.java b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/item/SpawnEggItemMixin.java new file mode 100644 index 0000000..95cbdb0 --- /dev/null +++ b/src/main/java/com/awakenedredstone/neoskies/mixin/world/protection/item/SpawnEggItemMixin.java @@ -0,0 +1,50 @@ +package com.awakenedredstone.neoskies.mixin.world.protection.item; + +import com.awakenedredstone.neoskies.logic.registry.NeoSkiesIslandSettings; +import com.awakenedredstone.neoskies.util.ServerUtils; +import com.awakenedredstone.neoskies.util.WorldProtection; +import com.llamalad7.mixinextras.sugar.Local; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.ItemUsageContext; +import net.minecraft.item.SpawnEggItem; +import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.TypedActionResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; +import org.spongepowered.asm.mixin.Mixin; +import org.spongepowered.asm.mixin.injection.At; +import org.spongepowered.asm.mixin.injection.Inject; +import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; + +@Mixin(SpawnEggItem.class) +public class SpawnEggItemMixin { + @Inject(method = "useOnBlock", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityType;spawnFromItemStack(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/item/ItemStack;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/SpawnReason;ZZ)Lnet/minecraft/entity/Entity;"), cancellable = true) + private void preventSpawn(ItemUsageContext context, CallbackInfoReturnable cir, @Local BlockPos pos, @Local World world, @Local ItemStack stack) { + PlayerEntity player = context.getPlayer(); + if (!world.isClient() && player != null) { + if (!WorldProtection.canModify(world, context.getBlockPos(), player, NeoSkiesIslandSettings.USE_SPAWNER)) { + Hand hand = context.getHand(); + int slot = hand == Hand.MAIN_HAND ? player.getInventory().selectedSlot : 40; + ((ServerPlayerEntity) player).networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(ScreenHandlerSlotUpdateS2CPacket.UPDATE_PLAYER_INVENTORY_SYNC_ID, 0, slot, stack)); + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.USE_SPAWNER); + cir.setReturnValue(ActionResult.FAIL); + } + } + } + + @Inject(method = "use", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/EntityType;spawnFromItemStack(Lnet/minecraft/server/world/ServerWorld;Lnet/minecraft/item/ItemStack;Lnet/minecraft/entity/player/PlayerEntity;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/SpawnReason;ZZ)Lnet/minecraft/entity/Entity;"), cancellable = true) + private void preventSpawn(World world, PlayerEntity player, Hand hand, CallbackInfoReturnable> cir, @Local BlockPos pos, @Local ItemStack stack) { + if (!world.isClient() && player != null) { + if (!WorldProtection.canModify(world, pos, player, NeoSkiesIslandSettings.USE_SPAWNER)) { + int slot = hand == Hand.MAIN_HAND ? player.getInventory().selectedSlot : 40; + ((ServerPlayerEntity) player).networkHandler.sendPacket(new ScreenHandlerSlotUpdateS2CPacket(ScreenHandlerSlotUpdateS2CPacket.UPDATE_PLAYER_INVENTORY_SYNC_ID, 0, slot, stack)); + ServerUtils.protectionWarning(player, NeoSkiesIslandSettings.USE_SPAWNER); + cir.setReturnValue(TypedActionResult.fail(stack)); + } + } + } +} diff --git a/src/main/java/com/awakenedredstone/neoskies/util/ServerUtils.java b/src/main/java/com/awakenedredstone/neoskies/util/ServerUtils.java index 9e47ccc..f1a371a 100644 --- a/src/main/java/com/awakenedredstone/neoskies/util/ServerUtils.java +++ b/src/main/java/com/awakenedredstone/neoskies/util/ServerUtils.java @@ -1,10 +1,9 @@ package com.awakenedredstone.neoskies.util; -import com.awakenedredstone.neoskies.config.MainConfig; import com.awakenedredstone.neoskies.logic.Skylands; +import com.awakenedredstone.neoskies.logic.settings.IslandSettings; import net.minecraft.entity.player.PlayerEntity; import net.minecraft.text.Text; -import com.awakenedredstone.neoskies.SkylandsMain; import java.util.Map; import java.util.function.Consumer; @@ -12,7 +11,15 @@ public class ServerUtils { public static void protectionWarning(PlayerEntity player, String key) { - if (Skylands.getConfig().showProtectionMessages) actionbarPrefixed(player, "island_protection." + key); + if (Skylands.getConfig().showProtectionMessages) { + actionbarPrefixed(player, "island_protection." + key); + } + } + + public static void protectionWarning(PlayerEntity player, IslandSettings settings) { + if (Skylands.getConfig().showProtectionMessages && !settings.isSilent()) { + actionbarPrefixed(player, "island_protection." + settings.getTranslationKey()); + } } public static void actionbarPrefixed(PlayerEntity player, String message, Consumer> builder) { diff --git a/src/main/java/com/awakenedredstone/neoskies/util/WorldProtection.java b/src/main/java/com/awakenedredstone/neoskies/util/WorldProtection.java index 4134049..b17f7e4 100644 --- a/src/main/java/com/awakenedredstone/neoskies/util/WorldProtection.java +++ b/src/main/java/com/awakenedredstone/neoskies/util/WorldProtection.java @@ -11,13 +11,17 @@ import com.awakenedredstone.neoskies.logic.Skylands; import com.awakenedredstone.neoskies.logic.registry.SkylandsPermissionLevels; import com.awakenedredstone.neoskies.logic.settings.IslandSettings; +import org.jetbrains.annotations.NotNull; import java.util.Optional; public class WorldProtection { - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean canModify(World world, PlayerEntity player) { + /** + * @deprecated Please use {@link WorldProtection#canModify(World, PlayerEntity, IslandSettings)} + **/ + @Deprecated + public static boolean canModify(@NotNull World world, @NotNull PlayerEntity player) { if (SkylandsMain.PROTECTION_BYPASS.contains(player)) { if (Permissions.check(player, "neoskies.admin.protection.bypass", 4)) return true; else SkylandsMain.PROTECTION_BYPASS.remove(player); @@ -34,9 +38,11 @@ public static boolean canModify(World world, PlayerEntity player) { return true; } + /** + * @deprecated Please use {@link WorldProtection#canModify(World, BlockPos, PlayerEntity, IslandSettings)} + **/ @Deprecated - @SuppressWarnings("BooleanMethodIsAlwaysInverted") - public static boolean canModify(World world, BlockPos pos, PlayerEntity player) { + public static boolean canModify(@NotNull World world, @NotNull BlockPos pos, @NotNull PlayerEntity player) { if (SkylandsMain.PROTECTION_BYPASS.contains(player)) { if (Permissions.check(player, "neoskies.admin.protection.bypass", 4)) { return true; @@ -60,7 +66,18 @@ public static boolean canModify(World world, BlockPos pos, PlayerEntity player) return false; } - public static boolean canModify(World world, BlockPos pos, PlayerEntity player, T setting) { + @SafeVarargs + public static boolean canModify(@NotNull World world, @NotNull BlockPos pos, @NotNull PlayerEntity player, @NotNull T... settings) { + boolean allowed = true; + for (T setting : settings) { + if (!canModify(world, pos, player, setting)) { + return false; + } + } + return true; + } + + public static boolean canModify(@NotNull World world, @NotNull BlockPos pos, @NotNull PlayerEntity player, @NotNull T setting) { if (SkylandsMain.PROTECTION_BYPASS.contains(player)) { if (Permissions.check(player, "neoskies.admin.protection.bypass", 4)) { return true; @@ -86,7 +103,7 @@ public static boolean canModify(World world, BlockPos return false; } - public static boolean canModify(World world, PlayerEntity player, T setting) { + public static boolean canModify(@NotNull World world, @NotNull PlayerEntity player, @NotNull T setting) { if (SkylandsMain.PROTECTION_BYPASS.contains(player)) { if (Permissions.check(player, "neoskies.admin.protection.bypass", 4)) { return true; @@ -109,7 +126,7 @@ public static boolean canModify(World world, PlayerEn return false; } - public static PermissionLevel getPlayerPermissionLevel(World world, PlayerEntity player) { + public static @NotNull PermissionLevel getPlayerPermissionLevel(@NotNull World world, @NotNull PlayerEntity player) { Optional island = SkylandsAPI.getIsland(world); if (island.isPresent() && island.get().isMember(player)) { if (island.get().owner.uuid == player.getUuid()) { @@ -123,7 +140,7 @@ public static PermissionLevel getPlayerPermissionLevel(World world, PlayerEntity return SkylandsPermissionLevels.VISITOR; } - public static boolean isWithinIsland(World world, BlockPos pos) { + public static boolean isWithinIsland(@NotNull World world, @NotNull BlockPos pos) { Optional island = SkylandsAPI.getIsland(world); if (SkylandsAPI.isHub(world)) { diff --git a/src/main/resources/data/neoskies/lang/en_us.json b/src/main/resources/data/neoskies/lang/en_us.json index db3ba35..764b775 100644 --- a/src/main/resources/data/neoskies/lang/en_us.json +++ b/src/main/resources/data/neoskies/lang/en_us.json @@ -1,5 +1,130 @@ { - "message.neoskies.prefix": "Server : ", + "commands.neoskies.admin.bypass.enable": "Enabled protection bypass", + "commands.neoskies.admin.bypass.disable": "Disabled protection bypass", + "commands.neoskies.reload": "Reloading configs!", + "commands.neoskies.error.player_only": "Only players can execute this!", + + "island_protection.neoskies.place/blocks": "You can't place blocks out here!", + "island_protection.neoskies.place/minecarts": "You can't place minecarts out here!", + "island_protection.neoskies.break/blocks": "You can't break blocks out here!", + "island_protection.neoskies.use/anvil": "You can't use anvils out here!", + "island_protection.neoskies.use/armor_stand": "You can't interact with armor stands out here!", + "island_protection.neoskies.use/beacon": "You can't use beacons out here!", + "island_protection.neoskies.use/brewing_stand": "You can't use brewing stands out here!", + "island_protection.neoskies.use/composter": "You can't use composters out here!", + "island_protection.neoskies.use/containers": "You can't interact with containers out here!", + "island_protection.neoskies.use/doors": "You can't use doors out here!", + "island_protection.neoskies.use/item_frame": "You can't use item frames out here!", + "island_protection.neoskies.use/lectern": "You can't use lecterns out here!", + "island_protection.neoskies.use/lodestone": "You can't use lodestones out here!", + "island_protection.neoskies.use/redstone": "You can't use redstone out here!", + "island_protection.neoskies.use/respawn_anchor": "You can't use respawn anchors out here!", + "island_protection.neoskies.use/signs": "You can't use signs out here!", + "island_protection.neoskies.use/spawner": "You can't use spawners out here!", + "island_protection.neoskies.use/tnt": "You can't ignite TNT out here!", + "island_protection.neoskies.interact/dragon_egg": "You can't interact with the dragon egg out here!", + "island_protection.neoskies.interact/dripleaf": "You can't interact with dripleafs out here!", + "island_protection.neoskies.interact/other_blocks": "You can't interact with this out here!", + "island_protection.neoskies.interact/sculk": "You can't interact with sculk out here!", + "island_protection.neoskies.ride/minecarts": "You can't ride minecarts out here!", + "island_protection.neoskies.ride/boats": "You can't ride boats out here!", + "island_protection.neoskies.ride/others": "You can't ride this out here!", + "island_protection.neoskies.hurt/hostile": "You can't attack monsters out here!", + "island_protection.neoskies.hurt/passive": "You can't attack mobs out here!", + "island_protection.neoskies.shear/entity": "You can't shear entities out here!", + "island_protection.neoskies.leash/entity": "You can't leash entities out here!", + "island_protection.neoskies.bucket/passive": "You can't bucket mobs out here!", + "island_protection.neoskies.harvest": "You can't harvest this out here!", + + "island_settings.neoskies.place/blocks": "Place blocks", + "island_settings.neoskies.place/minecarts": "Place minecarts", + "island_settings.neoskies.break/blocks": "Break blocks", + "island_settings.neoskies.use/anvil": "Use Anvil", + "island_settings.neoskies.use/armor_stand": "Use Armor Stand", + "island_settings.neoskies.use/beacon": "Use Beacon", + "island_settings.neoskies.use/brewing_stand": "Use Brewing Stand", + "island_settings.neoskies.use/composter": "Use Composter", + "island_settings.neoskies.use/containers": "Use Containers", + "island_settings.neoskies.use/doors": "Use Doors", + "island_settings.neoskies.use/item_frame": "Use Item Frame", + "island_settings.neoskies.use/lectern": "Use Lectern", + "island_settings.neoskies.use/lodestone": "Use Lodestone", + "island_settings.neoskies.use/redstone": "Use Redstone", + "island_settings.neoskies.use/respawn_anchor": "Use Respawn Anchor", + "island_settings.neoskies.use/signs": "Use Signs", + "island_settings.neoskies.use/spawner": "Use Spawner", + "island_settings.neoskies.use/tnt": "Use Tnt", + "island_settings.neoskies.interact/dragon_egg": "Interact with Dragon Egg", + "island_settings.neoskies.interact/dripleaf": "Interact with Dripleaf", + "island_settings.neoskies.interact/other_blocks": "Interact with other blocks", + "island_settings.neoskies.interact/sculk": "Interact with Sculk", + "island_settings.neoskies.hurt/hostile": "Hurt hostile mobs", + "island_settings.neoskies.hurt/passive": "Hurt passive mobs", + "island_settings.neoskies.ride/boats": "Ride Boats", + "island_settings.neoskies.ride/minecarts": "Ride Minecarts", + "island_settings.neoskies.ride/others": "Ride mobs", + "island_settings.neoskies.leash/entity": "Leash entities", + "island_settings.neoskies.shear/entity": "Shear entities", + "island_settings.neoskies.bucket/passive": "Bucket passive mobs", + "island_settings.neoskies.harvest": "Harvest crops", + + "island_settings.neoskies.place/blocks.description": "Allows players to place blocks", + "island_settings.neoskies.place/minecarts.description": "Allows players to place minecarts", + "island_settings.neoskies.break/blocks.description": "Allows players to break blocks", + "island_settings.neoskies.use/anvil.description": "Allows players to use anvil blocks", + "island_settings.neoskies.use/armor_stand.description": "Allows players to use Armor Stands", + "island_settings.neoskies.use/beacon.description": "Allows players to use Beacon blocks", + "island_settings.neoskies.use/brewing_stand.description": "Allows players to use Brewing Stand blocks", + "island_settings.neoskies.use/composter.description": "Allows players to use Composter blocks", + "island_settings.neoskies.use/containers.description": "Allows players to use containers", + "island_settings.neoskies.use/doors.description": "Allows players to use door blocks", + "island_settings.neoskies.use/item_frame.description": "Allows players to use Item Frames", + "island_settings.neoskies.use/lectern.description": "Allows players to use Lectern blocks", + "island_settings.neoskies.use/lodestone.description": "Allows players to use Lodestone blocks", + "island_settings.neoskies.use/redstone.description": "Allows players to use redstone blocks", + "island_settings.neoskies.use/respawn_anchor.description": "Allows players to use Respawn Anchor blocks", + "island_settings.neoskies.use/signs.description": "Allows players to use signs", + "island_settings.neoskies.use/spawner.description": "Allows players to use spawner blocks", + "island_settings.neoskies.use/tnt.description": "Allows players to use TNT blocks", + "island_settings.neoskies.interact/dragon_egg.description": "Allows players to interact with Dragon Egg blocks", + "island_settings.neoskies.interact/dripleaf.description": "Allows players to interact with Dripleaf blocks", + "island_settings.neoskies.interact/other_blocks.description": "Allows players to interact with other blocks", + "island_settings.neoskies.interact/sculk.description": "Allows players to interact with sculk blocks", + "island_settings.neoskies.hurt/hostile.description": "Allows players to hurt hostile mobs", + "island_settings.neoskies.hurt/passive.description": "Allows players to hurt passive mobs", + "island_settings.neoskies.ride/boats.description": "Allows players to ride boats", + "island_settings.neoskies.ride/minecarts.description": "Allows players to ride minecarts", + "island_settings.neoskies.ride/others.description": "Allows players to ride mobs", + "island_settings.neoskies.leash/entity.description": "Allows players to leash entities", + "island_settings.neoskies.shear/entity.description": "Allows players to shear entities", + "island_settings.neoskies.bucket/passive.description": "Allow players to bucket passive mobs", + "island_settings.neoskies.harvest.description": "Allows players to harvest crops", + + "island_settings/selected": "> %level%", + "island_settings/unselected": "> %level%", + "island_settings/level.0": "VISITOR", + "island_settings/level.5": "MEMBER", + "island_settings/level.99": "OWNER", + + + + + + + + + + + + + + + + + + + + "message.neoskies.prefix": "NeoSkies : ", "message.neoskies.now_playing": "Now Playing: %song%", "message.neoskies.right_click_harvest.tip": "You can harvest crops faster by right clicking!", "message.neoskies.island_create.fail": "You already have an Island!", @@ -62,7 +187,6 @@ "message.neoskies.settings.spawn_pos_change": "Spawn position got changed to %pos%", "message.neoskies.settings.visits_pos_change": "Visits position got changed to %pos%", "message.neoskies.settings.no_island": "You don't have an Island yet!", - "message.neoskies.error.player_only": "Only players can execute this!", "message.neoskies.island.level.scan.opening": "Opening scan menu...", "message.neoskies.island.level.scan.time_taken": "Scan finished in %time%", "message.neoskies.island.level.scan.block_info": "%amount%x %block%", @@ -78,68 +202,6 @@ "message.neoskies.island.modify.size": "Successfully modified the size of %player%'s island to %size%", - "island_protection.neoskies.place_blocks": "You can't place blocks out here!", - "island_protection.neoskies.break_blocks": "You can't break blocks out here!", - "island_protection.neoskies.use_anvil": "You can't use anvils out here!", - "island_protection.neoskies.use_beacon": "You can't use beacons out here!", - "island_protection.neoskies.use_brewing_stand": "You can't use brewing stands out here!", - "island_protection.neoskies.use_composter": "You can't use composters out here!", - "island_protection.neoskies.use_containers": "You can't open containers out here!", - "island_protection.neoskies.use_doors": "You can't use doors out here!", - "island_protection.neoskies.use_lectern": "You can't use lecterns out here!", - "island_protection.neoskies.use_lodestone": "You can't use lodestones out here!", - "island_protection.neoskies.use_redstone": "You can't use redstone out here!", - "island_protection.neoskies.use_respawn_anchor": "You can't use respawn anchors out here!", - "island_protection.neoskies.interact_other_blocks": "You can't interact with this out here!", - "island_protection.neoskies.use_armor_stand": "You can't interact with armor stands out here!", - "island_protection.neoskies.shear_entity": "You can't shear entities out here!", - "island_protection.neoskies.hurt_hostile": "You can't attack monsters out here!", - "island_protection.neoskies.hurt_passive": "You can't attack mobs out here!", - - "island_protection.neoskies.axe_use": "You can't modify blocks out here!", - "island_protection.neoskies.barrel_open": "You can't open barrels out here!", - "island_protection.neoskies.boat_open": "You can't interact with entities out here!", - "island_protection.neoskies.bone_meal_use": "You can't use bone meal out here!", - "island_protection.neoskies.brewing_stand": "You can't open brewing stands out here!", - "island_protection.neoskies.bucket_use": "You can't use bucket out here!", - "island_protection.neoskies.cauldron": "You can't interact with cauldrons out here!", - "island_protection.neoskies.chest_open": "You can't open chests out here!", - "island_protection.neoskies.composter": "You can't interact with composters out here!", - "island_protection.neoskies.damage_take": "You can't take damage out here!", - "island_protection.neoskies.dispenser_open": "You can't open dispensers out here!", - "island_protection.neoskies.door_open": "You can't interact with doors out here!", - "island_protection.neoskies.dripleaf": "You can't interact with dripleafs out here!", - "island_protection.neoskies.entity_hurt": "You can't damage entities out here!", - "island_protection.neoskies.extinguish": "You can't extinguish this out here!", - "island_protection.neoskies.farmland_spoil": "You can't spoil farmlands out here!", - "island_protection.neoskies.fence": "You can't interact with fences out here!", - "island_protection.neoskies.fence_gate_open": "You can't interact with fence gates out here!", - "island_protection.neoskies.flint_and_steel_use": "You can't place fire out here!", - "island_protection.neoskies.flower_pot_use": "You can't interact with flower pots out here!", - "island_protection.neoskies.furnace_open": "You can't open furnaces out here!", - "island_protection.neoskies.harvest": "You can't harvest crops out here!", - "island_protection.neoskies.hoe_use": "You can't modify blocks out here!", - "island_protection.neoskies.hopper_open": "You can't open hoppers out here!", - "island_protection.neoskies.ignite": "You can't ignite this out here!", - "island_protection.neoskies.interact": "You can't interact with this out here!", - "island_protection.neoskies.item_frame_use": "You can't interact with entities out here!", - "island_protection.neoskies.item_place": "You can't place items out here!", - "island_protection.neoskies.item_use": "You can't use items out here!", - "island_protection.neoskies.leash": "You can't break leashes out here!", - "island_protection.neoskies.lectern": "You can't interact with lecterns out here!", - "island_protection.neoskies.lodestone": "You can't interact with lodestones out here!", - "island_protection.neoskies.minecart_open": "You can't interact with entities out here!", - "island_protection.neoskies.modify": "You can't modify this out here!", - "island_protection.neoskies.noteblock": "You can't interact with noteblocks out here!", - "island_protection.neoskies.redstone": "You can't interact with redstone out here!", - "island_protection.neoskies.shears_use": "You can't use shears out here!", - "island_protection.neoskies.shovel_use": "You can't modify blocks out here!", - "island_protection.neoskies.shulker_box_open": "You can't open shulker boxes out here!", - "island_protection.neoskies.target": "You can't interact with targets out here!", - "island_protection.neoskies.tnt_ignite": "You can't ignite this out here!", - "island_protection.neoskies.trapdoor_open": "You can't interact with trapdoors out here!", - "island_protection.neoskies.villager_use": "You can't interact with entities out here!", - "message.neoskies.help.0": "- /%prefix% hub → Teleport to the Hub.", "message.neoskies.help.1": "- /%prefix% create → Creates an Island.", "message.neoskies.help.2": "- /%prefix% home → Teleport to your Island.", @@ -160,15 +222,10 @@ "message.neoskies.help.17": "- /%prefix% help → Sends this list.", "message.neoskies.error.player_not_found": "Player %player% not found!", "message.neoskies.island_data": "Island data:\n Id: %id%\n Owner: %owner%\n Members: %members%\n Radius: %radius%\n Balance: $%balance%\n Spawn position: %spawn_pos%\n Visit position: %visit_pos%\n Has Nether: %has_nether%\n Has End: %has_end%\n Locked: %locked%\n Created at: %created%\n", - "message.neoskies.reload": "Reloading NeoSkies!", "text.neoskies.nyi": "Not yet implemented", "text.neoskies.protection_bypass": "Bypass status: %value%", - "text.neoskies.island_settings.selected": "> %level%", - "text.neoskies.island_settings.unselected": "> %level%", - "text.neoskies.island_settings.level.0": "VISITOR", - "text.neoskies.island_settings.level.5": "MEMBER", - "text.neoskies.island_settings.level.99": "OWNER", + "gui.neoskies.menu": "Skylands menu", "gui.neoskies.island_settings": "Island settings", "gui.neoskies.close": "Close", @@ -179,34 +236,6 @@ "item_name.neoskies.protection_bypass": "Protection bypass", "item_name.neoskies.mod_settings": "Skylands settings", - "neoskies.island_settings.containers": "Open containers", - "neoskies.island_settings.place": "Place blocks", - "neoskies.island_settings.lodestone": "Use lodestone", - "neoskies.island_settings.redstone": "Interact with redstone", - "neoskies.island_settings.break": "Break blocks", - "neoskies.island_settings.dripleaf": "Interact with dripleaf", - "neoskies.island_settings.beacon": "Interact with beacon", - "neoskies.island_settings.anvil": "Use anvils", - "neoskies.island_settings.respawn_anchor": "Use Respawn Anchors", - "neoskies.island_settings.brewing_stand": "Use Brewing Stands", - "neoskies.island_settings.composter": "Use Composters", - "neoskies.island_settings.hurt_hostile": "Hurt hostile mobs", - "neoskies.island_settings.hurt_passive": "Hurt passive mobs", - - "neoskies.island_settings.containers.description": "Allows opening, chests, dispensers, shulker boxes, etc.", - "neoskies.island_settings.place.description": "Sets block placing permission", - "neoskies.island_settings.lodestone.description": "Allows using the lodestone", - "neoskies.island_settings.redstone.description": "Allows interacting with redstone", - "neoskies.island_settings.break.description": "Sets block breaking permission", - "neoskies.island_settings.dripleaf.description": "Sets if dripleafs fall when stepped on", - "neoskies.island_settings.beacon.description": "Allows setting the beacon effect", - "neoskies.island_settings.anvil.description": "Allows using and damaging the anvil", - "neoskies.island_settings.respawn_anchor.description": "Allows using Respawn Anchors, use with caution", - "neoskies.island_settings.brewing_stand.description": "Allows using Brewing Stands", - "neoskies.island_settings.composter.description": "Allows filling Composters", - "neoskies.island_settings.hurt_hostile.description": "Allows players to hurt hostile mobs", - "neoskies.island_settings.hurt_passive.description": "Allows players to hurt passive mobs", - "neoskies.economy.name": "SkyCoin", "neoskies.economy.transaction.fail": "Failed to apply transaction", "neoskies.economy.transaction.success": "Transaction applied successfully", diff --git a/src/main/resources/fabric.mod.json b/src/main/resources/fabric.mod.json index 2078a50..981d07e 100644 --- a/src/main/resources/fabric.mod.json +++ b/src/main/resources/fabric.mod.json @@ -34,8 +34,8 @@ "depends": { "fabricloader": "*", "fabric-api": ">=0.76.0", - "minecraft": "1.20.4", - "java": ">=17" + "minecraft": ">=1.20.5-rc.2", + "java": ">=21" }, "breaks": { "skylands": "*" diff --git a/src/main/resources/neoskies.mixins.json b/src/main/resources/neoskies.mixins.json index b3e32ee..d6ca0c5 100644 --- a/src/main/resources/neoskies.mixins.json +++ b/src/main/resources/neoskies.mixins.json @@ -10,24 +10,38 @@ "block.entity.EndGatewayBlockEntityMixin", "compat.JanksonAcessor", "compat.POJODeserializerAccessor", + "entity.DataTrackerAccessor", "entity.EntityMixin", "entity.PlayerManagerMixin", "entity.ServerPlayerEntityMixin", - "item.ArmorStandItemMixin", - "item.BlockItemMixin", - "item.BoatItemMixin", + "item.BoneMealItemMixin", "item.ItemStackMixin", - "item.MinecartItemMixin", "world.ChunkMixin", "world.PlayerEntityMixin", "world.PortalForcerMixin", "world.ServerWorldMixin", - "world.protection.SculkCatalystBlockEntityMixin", - "world.protection.SculkSensorBlockEntityMixin", - "world.protection.SculkSensorBlockMixin", - "world.protection.SculkShriekerBlockEntityMixin", - "world.protection.SculkShriekerBlockMixin", - "world.protection.VibrationListenerMixin" + "world.protection.BucketableMixin", + "world.protection.EntityMixin", + "world.protection.ExplosionBehaviorMixin", + "world.protection.PotionEntityMixin", + "world.protection.ServerPlayerInteractionManagerMixin", + "world.protection.VibrationListenerMixin", + "world.protection.block.AbstractCandleBlockMixin", + "world.protection.block.BigDripLeafMixin", + "world.protection.block.ButtonBlockMixin", + "world.protection.block.CampfireBlockMixin", + "world.protection.block.CauldronBlockMixin", + "world.protection.block.LightningRodBlockMixin", + "world.protection.block.PressurePlateBlockMixin", + "world.protection.block.SculkCatalystBlockEntityMixin", + "world.protection.block.SculkSensorBlockEntityMixin", + "world.protection.block.SculkSensorBlockMixin", + "world.protection.block.SculkShriekerBlockEntityMixin", + "world.protection.block.SculkShriekerBlockMixin", + "world.protection.block.TargetBlockMixin", + "world.protection.block.TntBlockMixin", + "world.protection.block.TripwireBlockMixin", + "world.protection.item.BucketItemMixin" ], "injectors": { "defaultRequire": 1 diff --git a/src/testmod/java/com/awakenedredstone/neoskies/test/SkylandsTestMain.java b/src/testmod/java/com/awakenedredstone/neoskies/test/SkylandsTestMain.java new file mode 100644 index 0000000..bb1bb9d --- /dev/null +++ b/src/testmod/java/com/awakenedredstone/neoskies/test/SkylandsTestMain.java @@ -0,0 +1,116 @@ +package com.awakenedredstone.neoskies.test; + +import com.awakenedredstone.neoskies.api.island.IslandSettingsManager; +import com.awakenedredstone.neoskies.command.utils.CommandUtils; +import com.google.common.collect.ImmutableList; +import com.mojang.brigadier.builder.LiteralArgumentBuilder; +import eu.pb4.polymer.core.api.item.PolymerBlockItem; +import net.fabricmc.api.ModInitializer; +import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback; +import net.minecraft.block.AbstractBlock; +import net.minecraft.command.argument.EntityArgumentType; +import net.minecraft.entity.Entity; +import net.minecraft.item.Item; +import net.minecraft.item.Items; +import net.minecraft.registry.Registries; +import net.minecraft.registry.Registry; +import net.minecraft.server.command.CommandManager; +import net.minecraft.server.command.KillCommand; +import net.minecraft.server.command.ServerCommandSource; +import net.minecraft.text.MutableText; +import net.minecraft.text.Text; +import net.minecraft.util.Formatting; +import net.minecraft.util.Identifier; +import net.minecraft.util.Language; + +import java.util.Collection; + +import static net.minecraft.server.command.CommandManager.argument; +import static net.minecraft.server.command.CommandManager.literal; + +public final class SkylandsTestMain implements ModInitializer { + @Override + public void onInitialize() { + TestBlock testBlock = Registry.register(Registries.BLOCK, new Identifier("neoskies", "test_block"), new TestBlock(AbstractBlock.Settings.create().dropsNothing().solid().strength(999, 999))); + Registry.register(Registries.ITEM, new Identifier("neoskies", "test_block"), new PolymerBlockItem(testBlock, new Item.Settings(), Items.RED_CONCRETE)); + + CommandRegistrationCallback.EVENT.register((dispatcher, registryAccess, environment) -> { + dispatcher.register(literal("discard").requires(source -> source.hasPermissionLevel(2)) + .then(argument("targets", EntityArgumentType.entities()) + .executes(context -> { + ServerCommandSource source = context.getSource(); + Collection targets = EntityArgumentType.getEntities(context, "targets"); + + for (Entity entity : targets) { + entity.discard(); + } + if (targets.size() == 1) { + source.sendFeedback(() -> Text.translatable("commands.kill.success.single", targets.iterator().next().getDisplayName()), true); + } else { + source.sendFeedback(() -> Text.translatable("commands.kill.success.multiple", targets.size()), true); + } + return targets.size(); + }) + ) + ); + + CommandUtils.registerAdmin(dispatcher, literal("test") + .then(literal("protection_translations") + .executes(context -> { + ServerCommandSource source = context.getSource(); + MutableText text = Text.empty(); + for (Identifier settings : IslandSettingsManager.getDefaultSettings().keySet()) { + Language lang = Language.getInstance(); + String translationKey = settings.toTranslationKey(); + boolean hasTranslation = lang.hasTranslation("island_protection." + translationKey); + text.append(Text.literal(translationKey)); + text.append(Text.literal(": ")); + Text text1 = Text.literal(hasTranslation ? "Translated" : "Untranslated").formatted(hasTranslation ? Formatting.GREEN : Formatting.RED); + text.append(text1); + text.append(Text.literal("\n")); + } + + source.sendFeedback(() -> text, false); + return 0; + }) + ).then(literal("settings_translations") + .executes(context -> { + ServerCommandSource source = context.getSource(); + MutableText text = Text.empty(); + for (Identifier settings : IslandSettingsManager.getDefaultSettings().keySet()) { + Language lang = Language.getInstance(); + String translationKey = settings.toTranslationKey(); + boolean hasTranslation = lang.hasTranslation("island_settings." + translationKey); + text.append(Text.literal(translationKey)); + text.append(Text.literal(": ")); + Text text1 = Text.literal(hasTranslation ? "Translated" : "Untranslated").formatted(hasTranslation ? Formatting.GREEN : Formatting.RED); + text.append(text1); + text.append(Text.literal("\n")); + } + + source.sendFeedback(() -> text, false); + return 0; + }) + ).then(literal("settings_description_translations") + .executes(context -> { + ServerCommandSource source = context.getSource(); + MutableText text = Text.empty(); + for (Identifier settings : IslandSettingsManager.getDefaultSettings().keySet()) { + Language lang = Language.getInstance(); + String translationKey = settings.toTranslationKey(); + boolean hasTranslation = lang.hasTranslation("island_settings." + translationKey + ".description"); + text.append(Text.literal(translationKey)); + text.append(Text.literal(": ")); + Text text1 = Text.literal(hasTranslation ? "Translated" : "Untranslated").formatted(hasTranslation ? Formatting.GREEN : Formatting.RED); + text.append(text1); + text.append(Text.literal("\n")); + } + + source.sendFeedback(() -> text, false); + return 0; + }) + ) + ); + }); + } +} diff --git a/src/testmod/java/com/awakenedredstone/neoskies/test/TestBlock.java b/src/testmod/java/com/awakenedredstone/neoskies/test/TestBlock.java new file mode 100644 index 0000000..815dfd4 --- /dev/null +++ b/src/testmod/java/com/awakenedredstone/neoskies/test/TestBlock.java @@ -0,0 +1,68 @@ +package com.awakenedredstone.neoskies.test; + +import eu.pb4.polymer.core.api.block.SimplePolymerBlock; +import net.minecraft.block.Block; +import net.minecraft.block.BlockState; +import net.minecraft.block.Blocks; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.ItemStack; +import net.minecraft.server.network.ServerPlayerEntity; +import net.minecraft.state.StateManager; +import net.minecraft.state.property.EnumProperty; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.ItemActionResult; +import net.minecraft.util.StringIdentifiable; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class TestBlock extends SimplePolymerBlock { + public static EnumProperty TEST_STATE = EnumProperty.of("test_state", State.class); + + public TestBlock(Settings settings) { + super(settings, Blocks.RED_CONCRETE); + this.setDefaultState(this.getStateManager().getDefaultState().with(TEST_STATE, State.NOT_WORKING)); + } + + @Override + protected void appendProperties(StateManager.Builder builder) { + builder.add(TEST_STATE); + } + + @Override + public BlockState getPolymerBlockState(BlockState state, ServerPlayerEntity player) { + return ( + switch (state.get(TEST_STATE)) { + case NOT_WORKING -> Blocks.RED_CONCRETE; + case PARTIAL -> Blocks.YELLOW_CONCRETE; + case WORKING -> Blocks.LIME_CONCRETE; + } + ).getDefaultState(); + } + + @Override + protected ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, BlockHitResult hit) { + world.setBlockState(pos, state.cycle(TEST_STATE), 0); + return ActionResult.SUCCESS; + } + + @Override + protected ItemActionResult onUseWithItem(ItemStack stack, BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { + if (!stack.isEmpty()) { + return ItemActionResult.SUCCESS; + } + return super.onUseWithItem(stack, state, world, pos, player, hand, hit); + } + + public enum State implements StringIdentifiable { + NOT_WORKING, + PARTIAL, + WORKING; + + @Override + public String asString() { + return this.name().toLowerCase(); + } + } +} diff --git a/src/testmod/resources/fabric.mod.json b/src/testmod/resources/fabric.mod.json new file mode 100644 index 0000000..51959d4 --- /dev/null +++ b/src/testmod/resources/fabric.mod.json @@ -0,0 +1,15 @@ +{ + "schemaVersion": 1, + "id": "neoskies-test", + "version": "${version}", + "name": "NeoSkies TestMod", + "description": "Library to work with server-side events with the ability to filter by event source", + "authors": ["Nucleoid Contributors"], + "license": "LGPLv3", + "environment": "*", + "entrypoints": { + "main": [ + "com.awakenedredstone.neoskies.test.SkylandsTestMain" + ] + } +}