finishing architectury version mostly

This commit is contained in:
Flemmli97 2021-06-12 00:15:14 +02:00
parent 0b9365a955
commit fbed8b8785
47 changed files with 384 additions and 749 deletions

View File

@ -12,7 +12,6 @@ subprojects {
loom {
silentMojangMappingsLicense()
useFabricMixin = true
}
dependencies {
@ -27,19 +26,9 @@ allprojects {
apply plugin: "maven-publish"
archivesBaseName = rootProject.archives_base_name
version = project.minecraft_version + "-"+ rootProject.mod_version
version = project.minecraft_version + "-" + rootProject.mod_version
group = rootProject.maven_group
configurations {
modOptional
modCompileOnly.extendsFrom(modOptional)
modRuntime.extendsFrom(modOptional)
optional
compileOnly.extendsFrom(optional)
runtime.extendsFrom(optional)
}
tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
def targetVersion = 8

View File

@ -12,4 +12,22 @@ architectury {
java {
withSourcesJar()
}
publishing {
publications {
mavenCommon(MavenPublication) {
artifactId = rootProject.archives_base_name
// add all the jars that should be included when publishing to maven
artifact remapJar
artifact(sourcesJar) {
builtBy remapSourcesJar
}
}
}
// See https://docs.gradle.org/current/userguide/publishing_maven.html for information on how to set up publishing.
repositories {
// Add repositories to publish to here.
}
}

View File

@ -0,0 +1,13 @@
package io.github.flemmli97.flan;
import me.shedaniel.architectury.annotations.ExpectPlatform;
import java.nio.file.Path;
public class ConfigPath {
@ExpectPlatform
public static Path configPath() {
throw new AssertionError();
}
}

View File

@ -25,11 +25,11 @@ import io.github.flemmli97.flan.player.EnumDisplayType;
import io.github.flemmli97.flan.player.EnumEditMode;
import io.github.flemmli97.flan.player.OfflinePlayerData;
import io.github.flemmli97.flan.player.PlayerClaimData;
import net.minecraft.command.CommandSource;
import net.minecraft.command.argument.BlockPosArgumentType;
import net.minecraft.command.argument.GameProfileArgumentType;
import net.minecraft.server.MinecraftServer;
import net.minecraft.server.command.CommandManager;
import net.minecraft.server.command.CommandSource;
import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;

View File

@ -3,10 +3,10 @@ package io.github.flemmli97.flan.config;
import com.google.common.collect.Lists;
import com.google.gson.JsonArray;
import com.google.gson.JsonObject;
import io.github.flemmli97.flan.ConfigPath;
import io.github.flemmli97.flan.Flan;
import io.github.flemmli97.flan.api.ClaimPermission;
import io.github.flemmli97.flan.api.PermissionRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.item.Item;
import net.minecraft.item.Items;
import net.minecraft.server.MinecraftServer;
@ -83,7 +83,7 @@ public class Config {
})));
public Config(MinecraftServer server) {
File configDir = FabricLoader.getInstance().getConfigDir().resolve("flan").toFile();
File configDir = ConfigPath.configPath().resolve("flan").toFile();
try {
if (!configDir.exists())
configDir.mkdirs();

View File

@ -4,9 +4,9 @@ import com.google.gson.JsonArray;
import com.google.gson.JsonElement;
import com.google.gson.JsonObject;
import com.google.gson.JsonParseException;
import io.github.flemmli97.flan.ConfigPath;
import io.github.flemmli97.flan.api.ClaimPermission;
import io.github.flemmli97.flan.api.PermissionRegistry;
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.server.MinecraftServer;
import java.io.File;
@ -137,7 +137,7 @@ public class LangConfig {
public LangCommands cmdLang = new LangCommands();
public LangConfig(MinecraftServer server) {
File configDir = FabricLoader.getInstance().getConfigDir().resolve("flan").toFile();
File configDir = ConfigPath.configPath().resolve("flan").toFile();
//server.getSavePath(WorldSavePath.ROOT).resolve("config/claimConfigs").toFile();
try {
if (!configDir.exists())

View File

@ -34,6 +34,7 @@ import net.minecraft.util.TypedActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.RaycastContext;
import net.minecraft.world.World;
import java.util.Set;
@ -46,7 +47,7 @@ public class ItemInteractEvents {
ServerPlayerEntity player = (ServerPlayerEntity) p;
ItemStack stack = player.getStackInHand(hand);
if (stack.getItem() == ConfigHandler.config.claimingItem) {
HitResult ray = player.rayTrace(64, 0, false);
HitResult ray = player.raycast(64, 0, false);
if (ray != null && ray.getType() == HitResult.Type.BLOCK) {
claimLandHandling(player, ((BlockHitResult) ray).getBlockPos());
return TypedActionResult.success(stack);
@ -54,7 +55,7 @@ public class ItemInteractEvents {
return TypedActionResult.pass(stack);
}
if (stack.getItem() == ConfigHandler.config.inspectionItem) {
HitResult ray = player.rayTrace(32, 0, false);
HitResult ray = player.raycast(32, 0, false);
if (ray != null && ray.getType() == HitResult.Type.BLOCK) {
inspect(player, ((BlockHitResult) ray).getBlockPos());
return TypedActionResult.success(stack);

View File

@ -1,7 +1,7 @@
package io.github.flemmli97.flan.integration.permissionapi;
import me.shedaniel.architectury.annotations.ExpectPlatform;
import net.minecraft.server.command.CommandSource;
import net.minecraft.command.CommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
public class CommandPermission {

View File

@ -5,7 +5,6 @@ import net.minecraft.block.BlockState;
import net.minecraft.block.FireBlock;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraft.world.WorldView;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
@ -32,11 +31,4 @@ public abstract class FireBlockMixin {
info.cancel();
}
}
@Inject(method = "trySpreadingFire", at = @At(value = "HEAD"), cancellable = true)
public void spread(World world, BlockPos pos, int spreadFactor, Random rand, int currentAge, CallbackInfo info) {
if (!world.isClient && !WorldEvents.canFireSpread((ServerWorld) world, pos)) {
info.cancel();
}
}
}

View File

@ -1,7 +1,6 @@
package io.github.flemmli97.flan.mixin;
import io.github.flemmli97.flan.claim.Claim;
import io.github.flemmli97.flan.event.EntityInteractEvents;
import io.github.flemmli97.flan.player.IPlayerClaimImpl;
import io.github.flemmli97.flan.player.PlayerClaimData;
import net.minecraft.nbt.CompoundTag;
@ -41,9 +40,9 @@ public abstract class PlayerClaimMixin implements IPlayerClaimImpl {
this.claimData.save(this.server);
}
@Inject(method = "tick", at = @At("RETURN"))
@Inject(method = "tick", at = @At("HEAD"))
private void tickData(CallbackInfo info) {
this.claimData.tick();
this.claimData.tick(this.currentClaim, claim -> this.currentClaim = claim);
}
@Inject(method = "copyFrom", at = @At("RETURN"))
@ -51,11 +50,6 @@ public abstract class PlayerClaimMixin implements IPlayerClaimImpl {
this.claimData.clone(PlayerClaimData.get(oldPlayer));
}
@Inject(method = "tick", at = @At("HEAD"))
private void claimupdate(CallbackInfo info) {
EntityInteractEvents.updateClaim((ServerPlayerEntity) (Object) this, this.currentClaim, claim -> this.currentClaim = claim);
}
@Override
public PlayerClaimData get() {
return this.claimData;

View File

@ -4,25 +4,15 @@ import io.github.flemmli97.flan.event.EntityInteractEvents;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
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.ModifyVariable;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
@Mixin(PlayerEntity.class)
public abstract class PlayerMixin {
@Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At(value = "HEAD"), cancellable = true)
public void drop(ItemStack stack, boolean throwRandomly, boolean retainOwnership, CallbackInfoReturnable<ItemEntity> info) {
if (!EntityInteractEvents.canDropItem((PlayerEntity) (Object) this, stack)) {
info.setReturnValue(null);
info.cancel();
}
}
@ModifyVariable(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/ItemEntity;setPickupDelay(I)V"))
private ItemEntity ownerDrop(ItemEntity entity) {
EntityInteractEvents.updateDroppedItem((PlayerEntity) (Object) this, entity);

View File

@ -2,19 +2,12 @@ package io.github.flemmli97.flan.mixin;
import io.github.flemmli97.flan.claim.ClaimStorage;
import io.github.flemmli97.flan.claim.IClaimStorage;
import io.github.flemmli97.flan.event.WorldEvents;
import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.world.explosion.Explosion;
import net.minecraft.world.explosion.ExplosionBehavior;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Unique;
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 org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(ServerWorld.class)
public abstract class ServerWorldMixin implements IClaimStorage {
@ -33,11 +26,6 @@ public abstract class ServerWorldMixin implements IClaimStorage {
this.claimData.save(world.getServer(), world.getRegistryKey());
}
@Inject(method = "createExplosion", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/explosion/Explosion;collectBlocksAndDamageEntities()V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
private void explosionHook(Entity entity, DamageSource damageSource, ExplosionBehavior explosionBehavior, double d, double e, double f, float g, boolean bl, Explosion.DestructionType destructionType, CallbackInfoReturnable<Explosion> info, Explosion explosion) {
WorldEvents.modifyExplosion(explosion, (ServerWorld) (Object) this);
}
@Override
public ClaimStorage get() {
return this.claimData;

View File

@ -142,7 +142,7 @@ public class ClaimDisplay {
if (state.getMaterial().isReplaceable()) {
pos = pos.down();
state = world.getBlockState(pos);
while (state.getMaterial().isReplaceable() && !World.isHeightInvalid(pos)) {
while (state.getMaterial().isReplaceable() && !World.isOutOfBuildLimitVertically(pos)) {
pos = pos.down();
state = world.getBlockState(pos);
}

View File

@ -10,6 +10,7 @@ import io.github.flemmli97.flan.claim.IPermissionContainer;
import io.github.flemmli97.flan.claim.ParticleIndicators;
import io.github.flemmli97.flan.claim.PermHelper;
import io.github.flemmli97.flan.config.ConfigHandler;
import io.github.flemmli97.flan.event.EntityInteractEvents;
import net.minecraft.block.BlockState;
import net.minecraft.network.packet.s2c.play.ParticleS2CPacket;
import net.minecraft.server.MinecraftServer;
@ -32,6 +33,7 @@ import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.UUID;
import java.util.function.Consumer;
public class PlayerClaimData {
@ -212,7 +214,8 @@ public class PlayerClaimData {
return false;
}
public void tick() {
public void tick(Claim currentClaim, Consumer<Claim> cons) {
EntityInteractEvents.updateClaim(this.player, currentClaim, cons);
boolean tool = this.player.getMainHandStack().getItem() == ConfigHandler.config.claimingItem
|| this.player.getOffHandStack().getItem() == ConfigHandler.config.claimingItem;
boolean stick = this.player.getMainHandStack().getItem() == ConfigHandler.config.inspectionItem

View File

Before

Width:  |  Height:  |  Size: 2.9 KiB

After

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -6,27 +6,19 @@
"mixins": [
"PlayerClaimMixin",
"ServerWorldMixin",
"ServerPlayNetworkHandlerMixin",
"AbstractBlockStateMixin",
"EntityMixin",
"ProjectileMixin",
"TurtleEggMixin",
"XpEntityMixin",
"WitherMixin",
"IPersistentProjectileVars",
"EntityDamageMixin",
"ItemStackMixin",
"ILecternBlockValues",
"FluidMixin",
"PistonMixin",
"RaidManagerMixin",
"FireBlockMixin",
"SpawnHelperMixin",
"PlayerMixin",
"ItemEntityMixin",
"EndermanPickupMixin",
"EndermanPlaceMixin",
"SnowGolemMixin"
"EndermanPlaceMixin"
],
"server": [
],

View File

@ -0,0 +1,12 @@
package io.github.flemmli97.flan.fabric;
import net.fabricmc.loader.api.FabricLoader;
import java.nio.file.Path;
public class ConfigPathImpl {
public static Path configPath() {
return FabricLoader.getInstance().getConfigDir();
}
}

View File

@ -1,4 +1,4 @@
package io.github.flemmli97.flan.mixin;
package io.github.flemmli97.flan.fabric.mixin;
import io.github.flemmli97.flan.event.EntityInteractEvents;
import net.minecraft.entity.Entity;

View File

@ -0,0 +1,24 @@
package io.github.flemmli97.flan.fabric.mixin;
import io.github.flemmli97.flan.event.WorldEvents;
import net.minecraft.block.FireBlock;
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 java.util.Random;
@Mixin(FireBlock.class)
public class FabricFireMixin {
@Inject(method = "trySpreadingFire", at = @At(value = "HEAD"), cancellable = true)
public void spread(World world, BlockPos pos, int spreadFactor, Random rand, int currentAge, CallbackInfo info) {
if (!world.isClient && !WorldEvents.canFireSpread((ServerWorld) world, pos)) {
info.cancel();
}
}
}

View File

@ -1,4 +1,4 @@
package io.github.flemmli97.flan.mixin;
package io.github.flemmli97.flan.fabric.mixin;
import io.github.flemmli97.flan.event.WorldEvents;
import net.minecraft.block.BlockState;

View File

@ -0,0 +1,22 @@
package io.github.flemmli97.flan.fabric.mixin;
import io.github.flemmli97.flan.event.EntityInteractEvents;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
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(PlayerEntity.class)
public abstract class PlayerDropMixin {
@Inject(method = "dropItem(Lnet/minecraft/item/ItemStack;ZZ)Lnet/minecraft/entity/ItemEntity;", at = @At(value = "HEAD"), cancellable = true)
public void drop(ItemStack stack, boolean throwRandomly, boolean retainOwnership, CallbackInfoReturnable<ItemEntity> info) {
if (!EntityInteractEvents.canDropItem((PlayerEntity) (Object) this, stack)) {
info.setReturnValue(null);
info.cancel();
}
}
}

View File

@ -1,4 +1,4 @@
package io.github.flemmli97.flan.mixin;
package io.github.flemmli97.flan.fabric.mixin;
import io.github.flemmli97.flan.event.EntityInteractEvents;
import net.minecraft.entity.projectile.DragonFireballEntity;

View File

@ -1,4 +1,4 @@
package io.github.flemmli97.flan.mixin;
package io.github.flemmli97.flan.fabric.mixin;
import io.github.flemmli97.flan.event.EntityInteractEvents;
import net.minecraft.entity.Entity;
@ -20,7 +20,7 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
public abstract class ServerPlayNetworkHandlerMixin {
@Shadow
public ServerPlayerEntity player;
private ServerPlayerEntity player;
@Inject(method = "onPlayerInteractEntity", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/network/ServerPlayerEntity;interact(Lnet/minecraft/entity/Entity;Lnet/minecraft/util/Hand;)Lnet/minecraft/util/ActionResult;"), cancellable = true)
public void onPlayerInteractEntity(PlayerInteractEntityC2SPacket packet, CallbackInfo info) {

View File

@ -0,0 +1,22 @@
package io.github.flemmli97.flan.fabric.mixin;
import io.github.flemmli97.flan.event.WorldEvents;
import net.minecraft.entity.Entity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.server.world.ServerWorld;
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;
import org.spongepowered.asm.mixin.injection.callback.LocalCapture;
@Mixin(ServerWorld.class)
public abstract class ServerWorldMixin {
@Inject(method = "createExplosion", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/explosion/Explosion;collectBlocksAndDamageEntities()V", shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILHARD)
private void explosionHook(Entity entity, DamageSource damageSource, ExplosionBehavior explosionBehavior, double d, double e, double f, float g, boolean bl, Explosion.DestructionType destructionType, CallbackInfoReturnable<Explosion> info, Explosion explosion) {
WorldEvents.modifyExplosion(explosion, (ServerWorld) (Object) this);
}
}

View File

@ -1,4 +1,4 @@
package io.github.flemmli97.flan.mixin;
package io.github.flemmli97.flan.fabric.mixin;
import io.github.flemmli97.flan.event.EntityInteractEvents;
import net.minecraft.entity.passive.SnowGolemEntity;

View File

@ -1,4 +1,4 @@
package io.github.flemmli97.flan.mixin;
package io.github.flemmli97.flan.fabric.mixin;
import io.github.flemmli97.flan.event.WorldEvents;
import net.minecraft.entity.mob.MobEntity;

View File

@ -1,4 +1,4 @@
package io.github.flemmli97.flan.mixin;
package io.github.flemmli97.flan.fabric.mixin;
import io.github.flemmli97.flan.event.EntityInteractEvents;
import net.minecraft.entity.boss.WitherEntity;

View File

@ -1,4 +1,4 @@
package io.github.flemmli97.flan.mixin;
package io.github.flemmli97.flan.fabric.mixin;
import io.github.flemmli97.flan.event.EntityInteractEvents;
import net.minecraft.entity.ExperienceOrbEntity;

View File

@ -3,7 +3,7 @@ package io.github.flemmli97.flan.integration.permissionapi.fabric;
import io.github.flemmli97.flan.Flan;
import io.github.flemmli97.flan.config.ConfigHandler;
import me.lucko.fabric.api.permissions.v0.Permissions;
import net.minecraft.server.command.CommandSource;
import net.minecraft.command.CommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
public class CommandPermissionImpl {

View File

@ -20,7 +20,8 @@
]
},
"mixins": [
"flan.mixins.json"
"flan.mixins.json",
"flan.fabric.mixins.json"
],
"depends": {
"fabricloader": ">=0.7.4",

View File

@ -0,0 +1,24 @@
{
"required": true,
"minVersion": "0.8",
"package": "io.github.flemmli97.flan.fabric.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"ServerWorldMixin",
"PistonMixin",
"SpawnHelperMixin",
"ServerPlayNetworkHandlerMixin",
"ProjectileMixin",
"EntityDamageMixin",
"XpEntityMixin",
"PlayerDropMixin",
"WitherMixin",
"SnowGolemMixin",
"FabricFireMixin"
],
"server": [
],
"injectors": {
"defaultRequire": 1
}
}

View File

@ -23,7 +23,7 @@ architectury {
}
loom {
//mixinConfigs = ["flan.mixins.json"]
mixinConfigs = ["flan.mixins.json", "flan.forge.mixins.json"]
useFabricMixin = true
}

View File

@ -1,10 +1,11 @@
package io.github.flemmli97.flan;
import io.github.flemmli97.flan.forgeevent.BlockInteractEventsForge;
import io.github.flemmli97.flan.forgeevent.EntityInteractEventsForge;
import io.github.flemmli97.flan.forgeevent.ItemInteractEventsForge;
import io.github.flemmli97.flan.forgeevent.ServerEvents;
import io.github.flemmli97.flan.forgeevent.WorldEventsForge;
import net.minecraft.world.explosion.Explosion;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.common.Mod;
@ -18,5 +19,19 @@ public class FlanForge {
forge.addListener(WorldEventsForge::modifyExplosion);
forge.addListener(WorldEventsForge::pistonCanPush);
forge.addListener(WorldEventsForge::preventMobSpawn);
forge.addListener(ItemInteractEventsForge::useItem);
forge.addListener(BlockInteractEventsForge::breakBlocks);
forge.addListener(BlockInteractEventsForge::useBlocks);
forge.addListener(EntityInteractEventsForge::attackEntity);
forge.addListener(EntityInteractEventsForge::useAtEntity);
forge.addListener(EntityInteractEventsForge::useEntity);
forge.addListener(EntityInteractEventsForge::projectileHit);
forge.addListener(EntityInteractEventsForge::preventDamage);
forge.addListener(EntityInteractEventsForge::xpAbsorb);
forge.addListener(EntityInteractEventsForge::canDropItem);
forge.addListener(EntityInteractEventsForge::mobGriefing);
forge.addListener(ServerEvents::serverStart);
forge.addListener(ServerEvents::commands);
}
}

View File

@ -0,0 +1,12 @@
package io.github.flemmli97.flan.forge;
import net.minecraftforge.fml.loading.FMLPaths;
import java.nio.file.Path;
public class ConfigPathImpl {
public static Path configPath() {
return FMLPaths.CONFIGDIR.get();
}
}

View File

@ -0,0 +1,25 @@
package io.github.flemmli97.flan.forge.mixin;
import io.github.flemmli97.flan.event.WorldEvents;
import net.minecraft.block.FireBlock;
import net.minecraft.server.world.ServerWorld;
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.CallbackInfo;
import java.util.Random;
@Mixin(FireBlock.class)
public class ForgeFireMixin {
@Inject(method = "tryCatchFire", at = @At(value = "HEAD"), cancellable = true)
public void spread(World world, BlockPos pos, int spreadFactor, Random rand, int currentAge, Direction dir, CallbackInfo info) {
if (!world.isClient && !WorldEvents.canFireSpread((ServerWorld) world, pos)) {
info.cancel();
}
}
}

View File

@ -1,214 +0,0 @@
package io.github.flemmli97.flan.forgeevent;
import io.github.flemmli97.flan.api.ClaimPermission;
import io.github.flemmli97.flan.api.PermissionRegistry;
import io.github.flemmli97.flan.claim.ClaimStorage;
import io.github.flemmli97.flan.claim.IPermissionContainer;
import io.github.flemmli97.flan.claim.ObjectToPermissionMap;
import io.github.flemmli97.flan.config.ConfigHandler;
import io.github.flemmli97.flan.gui.LockedLecternScreenHandler;
import io.github.flemmli97.flan.player.EnumDisplayType;
import io.github.flemmli97.flan.player.PlayerClaimData;
import net.minecraft.block.BlockState;
import net.minecraft.block.DoorBlock;
import net.minecraft.block.InventoryProvider;
import net.minecraft.block.LecternBlock;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.block.entity.LecternBlockEntity;
import net.minecraft.block.enums.DoubleBlockHalf;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
public class BlockInteractEvents {
public static boolean breakBlocks(World world, PlayerEntity p, BlockPos pos, BlockState state, BlockEntity tile) {
if (world.isClient || p.isSpectator())
return true;
ServerPlayerEntity player = (ServerPlayerEntity) p;
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (claim != null) {
Identifier id = Registry.BLOCK.getId(state.getBlock());
if (alwaysAllowBlock(id, world.getBlockEntity(pos)))
return true;
if (!claim.canInteract(player, PermissionRegistry.BREAK, pos, true)) {
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
return false;
}
}
return true;
}
//Right click block
public static ActionResult useBlocks(PlayerEntity p, World world, Hand hand, BlockHitResult hitResult) {
if (world.isClient)
return ActionResult.PASS;
ServerPlayerEntity player = (ServerPlayerEntity) p;
ItemStack stack = player.getStackInHand(hand);
if (stack.getItem() == ConfigHandler.config.claimingItem) {
ItemInteractEventsForge.claimLandHandling(player, hitResult.getBlockPos());
return ActionResult.SUCCESS;
}
if (stack.getItem() == ConfigHandler.config.inspectionItem) {
ItemInteractEventsForge.inspect(player, hitResult.getBlockPos());
return ActionResult.SUCCESS;
}
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
IPermissionContainer claim = storage.getForPermissionCheck(hitResult.getBlockPos());
if (claim != null) {
boolean emptyHand = !player.getMainHandStack().isEmpty() || !player.getOffHandStack().isEmpty();
boolean cancelBlockInteract = player.shouldCancelInteraction() && emptyHand;
if (!cancelBlockInteract) {
BlockState state = world.getBlockState(hitResult.getBlockPos());
Identifier id = Registry.BLOCK.getId(state.getBlock());
BlockEntity blockEntity = world.getBlockEntity(hitResult.getBlockPos());
if (alwaysAllowBlock(id, blockEntity))
return ActionResult.PASS;
ClaimPermission perm = ObjectToPermissionMap.getFromBlock(state.getBlock());
if (perm == PermissionRegistry.PROJECTILES)
perm = PermissionRegistry.OPENCONTAINER;
//Pressureplate handled elsewhere
if (perm != null && perm != PermissionRegistry.PRESSUREPLATE) {
if (claim.canInteract(player, perm, hitResult.getBlockPos(), true))
return ActionResult.PASS;
if (state.getBlock() instanceof DoorBlock) {
DoubleBlockHalf half = state.get(DoorBlock.HALF);
if (half == DoubleBlockHalf.LOWER) {
BlockState other = world.getBlockState(hitResult.getBlockPos().up());
player.networkHandler.sendPacket(new BlockUpdateS2CPacket(hitResult.getBlockPos().up(), other));
} else {
BlockState other = world.getBlockState(hitResult.getBlockPos().down());
player.networkHandler.sendPacket(new BlockUpdateS2CPacket(hitResult.getBlockPos().down(), other));
}
}
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
return ActionResult.FAIL;
}
if (blockEntity != null) {
if (blockEntity instanceof LecternBlockEntity) {
if (claim.canInteract(player, PermissionRegistry.LECTERNTAKE, hitResult.getBlockPos(), false))
return ActionResult.PASS;
if (state.get(LecternBlock.HAS_BOOK))
LockedLecternScreenHandler.create(player, (LecternBlockEntity) blockEntity);
return ActionResult.FAIL;
}
if (!ConfigHandler.config.lenientBlockEntityCheck || blockEntity instanceof Inventory || blockEntity instanceof InventoryProvider) {
if (claim.canInteract(player, PermissionRegistry.OPENCONTAINER, hitResult.getBlockPos(), true))
return ActionResult.PASS;
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
return ActionResult.FAIL;
}
}
}
}
return ActionResult.PASS;
}
public static boolean alwaysAllowBlock(Identifier id, BlockEntity blockEntity) {
return ConfigHandler.config.ignoredBlocks.contains(id.toString())
|| (blockEntity != null
&& ConfigHandler.config.blockEntityTagIgnore.stream().anyMatch(blockEntity.toTag(new CompoundTag())::contains));
}
public static boolean cancelEntityBlockCollision(BlockState state, World world, BlockPos pos, Entity entity) {
if (world.isClient)
return false;
ServerPlayerEntity player = null;
if (entity instanceof ServerPlayerEntity)
player = (ServerPlayerEntity) entity;
else if (entity instanceof ProjectileEntity) {
Entity owner = ((ProjectileEntity) entity).getOwner();
if (owner instanceof ServerPlayerEntity)
player = (ServerPlayerEntity) owner;
} else if (entity instanceof ItemEntity) {
Entity owner = ((ServerWorld) world).getEntity(((ItemEntity) entity).getThrower());
if (owner instanceof ServerPlayerEntity)
player = (ServerPlayerEntity) owner;
}
if (player == null)
return false;
ClaimPermission perm = ObjectToPermissionMap.getFromBlock(state.getBlock());
if (perm == null)
return false;
if (perm != PermissionRegistry.PRESSUREPLATE && perm != PermissionRegistry.PORTAL)
return false;
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (claim != null)
return !claim.canInteract(player, perm, pos, false);
return false;
}
public static boolean preventFallOn(Entity entity, double heightDifference, boolean onGround, BlockState landedState, BlockPos landedPosition) {
if (entity.world.isClient)
return false;
if (entity instanceof ServerPlayerEntity) {
ClaimPermission perm = ObjectToPermissionMap.getFromBlock(landedState.getBlock());
if (perm != PermissionRegistry.TRAMPLE)
return false;
ClaimStorage storage = ClaimStorage.get((ServerWorld) entity.world);
IPermissionContainer claim = storage.getForPermissionCheck(landedPosition);
if (claim == null)
return false;
return !claim.canInteract((ServerPlayerEntity) entity, perm, landedPosition, true);
} else if (entity instanceof ProjectileEntity) {
Entity owner = ((ProjectileEntity) entity).getOwner();
if (owner instanceof ServerPlayerEntity) {
ClaimPermission perm = ObjectToPermissionMap.getFromBlock(landedState.getBlock());
if (perm != PermissionRegistry.TRAMPLE)
return false;
ClaimStorage storage = ClaimStorage.get((ServerWorld) entity.world);
IPermissionContainer claim = storage.getForPermissionCheck(landedPosition);
return !claim.canInteract((ServerPlayerEntity) owner, perm, landedPosition, true);
}
}
return false;
}
public static boolean canBreakTurtleEgg(World world, BlockPos pos, Entity entity) {
if (world.isClient)
return false;
ServerWorld serverWorld = (ServerWorld) world;
if (entity instanceof ServerPlayerEntity) {
ClaimStorage storage = ClaimStorage.get(serverWorld);
IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (claim == null)
return false;
return !claim.canInteract((ServerPlayerEntity) entity, PermissionRegistry.TRAMPLE, pos, true);
} else if (entity instanceof ProjectileEntity) {
Entity owner = ((ProjectileEntity) entity).getOwner();
if (owner instanceof ServerPlayerEntity) {
ClaimStorage storage = ClaimStorage.get(serverWorld);
IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (claim == null)
return false;
return !claim.canInteract((ServerPlayerEntity) owner, PermissionRegistry.TRAMPLE, pos, true);
}
} else if (entity instanceof ItemEntity) {
Entity owner = serverWorld.getEntity(((ItemEntity) entity).getThrower());
if (owner instanceof ServerPlayerEntity) {
ClaimStorage storage = ClaimStorage.get(serverWorld);
IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (claim == null)
return false;
return !claim.canInteract((ServerPlayerEntity) owner, PermissionRegistry.TRAMPLE, pos, true);
}
}
return false;
}
}

View File

@ -0,0 +1,26 @@
package io.github.flemmli97.flan.forgeevent;
import io.github.flemmli97.flan.event.BlockInteractEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
public class BlockInteractEventsForge {
public static void breakBlocks(BlockEvent.BreakEvent event) {
if (!(event.getWorld() instanceof World))
return;
if (BlockInteractEvents.breakBlocks((World) event.getWorld(), event.getPlayer(), event.getPos(), event.getState(), event.getWorld().getBlockEntity(event.getPos())))
event.setCanceled(true);
}
//Right click block
public static void useBlocks(PlayerInteractEvent.RightClickBlock event) {
ActionResult result = BlockInteractEvents.useBlocks(event.getPlayer(), event.getWorld(), event.getHand(), event.getHitVec());
if (result != ActionResult.PASS) {
event.setCancellationResult(result);
event.setCanceled(true);
}
}
}

View File

@ -1,330 +0,0 @@
package io.github.flemmli97.flan.forgeevent;
import io.github.flemmli97.flan.api.ClaimPermission;
import io.github.flemmli97.flan.api.PermissionRegistry;
import io.github.flemmli97.flan.claim.Claim;
import io.github.flemmli97.flan.claim.ClaimStorage;
import io.github.flemmli97.flan.claim.IPermissionContainer;
import io.github.flemmli97.flan.claim.ObjectToPermissionMap;
import io.github.flemmli97.flan.config.ConfigHandler;
import io.github.flemmli97.flan.mixin.IPersistentProjectileVars;
import io.github.flemmli97.flan.player.IOwnedItem;
import io.github.flemmli97.flan.player.PlayerClaimData;
import io.github.flemmli97.flan.player.TeleportUtils;
import it.unimi.dsi.fastutil.ints.IntOpenHashSet;
import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.ItemEntity;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.boss.WitherEntity;
import net.minecraft.entity.damage.DamageSource;
import net.minecraft.entity.decoration.ArmorStandEntity;
import net.minecraft.entity.decoration.ItemFrameEntity;
import net.minecraft.entity.mob.EndermanEntity;
import net.minecraft.entity.mob.Monster;
import net.minecraft.entity.passive.SnowGolemEntity;
import net.minecraft.entity.passive.TameableEntity;
import net.minecraft.entity.passive.VillagerEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.PersistentProjectileEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.entity.projectile.thrown.EggEntity;
import net.minecraft.entity.projectile.thrown.EnderPearlEntity;
import net.minecraft.entity.projectile.thrown.PotionEntity;
import net.minecraft.entity.vehicle.AbstractMinecartEntity;
import net.minecraft.entity.vehicle.BoatEntity;
import net.minecraft.entity.vehicle.StorageMinecartEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.network.packet.s2c.play.InventoryS2CPacket;
import net.minecraft.network.packet.s2c.play.PlayerAbilitiesS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundEvents;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.math.Vec3d;
import net.minecraft.world.World;
import java.util.function.Consumer;
public class EntityInteractEvents {
public static ActionResult attackEntity(PlayerEntity player, World world, Hand hand, Entity entity, EntityHitResult hitResult) {
return attackSimple(player, entity, true);
}
public static ActionResult useAtEntity(PlayerEntity player, World world, Hand hand, Entity entity, /* Nullable */ EntityHitResult hitResult) {
if (player.world.isClient || player.isSpectator() || canInteract(entity))
return ActionResult.PASS;
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
BlockPos pos = entity.getBlockPos();
IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (claim != null) {
if (entity instanceof ArmorStandEntity) {
if (!claim.canInteract((ServerPlayerEntity) player, PermissionRegistry.ARMORSTAND, pos, true))
return ActionResult.FAIL;
}
}
return ActionResult.PASS;
}
public static ActionResult useEntity(PlayerEntity p, World world, Hand hand, Entity entity) {
if (p.world.isClient || p.isSpectator() || canInteract(entity))
return ActionResult.PASS;
ServerPlayerEntity player = (ServerPlayerEntity) p;
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
BlockPos pos = entity.getBlockPos();
IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (claim != null) {
if (entity instanceof BoatEntity)
return claim.canInteract(player, PermissionRegistry.BOAT, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
if (entity instanceof AbstractMinecartEntity) {
if (entity instanceof StorageMinecartEntity)
return claim.canInteract(player, PermissionRegistry.OPENCONTAINER, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
return claim.canInteract(player, PermissionRegistry.MINECART, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
}
if (entity instanceof VillagerEntity)
return claim.canInteract(player, PermissionRegistry.TRADING, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
if (entity instanceof ItemFrameEntity)
return claim.canInteract(player, PermissionRegistry.ITEMFRAMEROTATE, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
if (entity instanceof TameableEntity) {
TameableEntity tame = (TameableEntity) entity;
if (tame.isOwner(player))
return ActionResult.PASS;
}
return claim.canInteract(player, PermissionRegistry.ANIMALINTERACT, pos, true) ? ActionResult.PASS : ActionResult.FAIL;
}
return ActionResult.PASS;
}
public static boolean canInteract(Entity entity) {
return entity.getScoreboardTags().stream().anyMatch(ConfigHandler.config.entityTagIgnore::contains);
}
public static boolean projectileHit(ProjectileEntity proj, HitResult res) {
if (proj.world.isClient)
return false;
Entity owner = proj.getOwner();
if (owner instanceof ServerPlayerEntity) {
ServerPlayerEntity player = (ServerPlayerEntity) owner;
if (res.getType() == HitResult.Type.BLOCK) {
BlockHitResult blockRes = (BlockHitResult) res;
BlockPos pos = blockRes.getBlockPos();
BlockState state = proj.world.getBlockState(pos);
ClaimPermission perm;
if (proj instanceof EnderPearlEntity)
perm = PermissionRegistry.ENDERPEARL;
else if (proj instanceof EggEntity || proj instanceof PotionEntity)
perm = PermissionRegistry.PROJECTILES;
else
perm = ObjectToPermissionMap.getFromBlock(state.getBlock());
if (perm != PermissionRegistry.ENDERPEARL && perm != PermissionRegistry.TARGETBLOCK && perm != PermissionRegistry.PROJECTILES)
return false;
ClaimStorage storage = ClaimStorage.get((ServerWorld) proj.world);
IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (claim == null)
return false;
boolean flag = !claim.canInteract(player, perm, pos, true);
if (flag) {
if (proj instanceof PersistentProjectileEntity) {
PersistentProjectileEntity pers = (PersistentProjectileEntity) proj;
((IPersistentProjectileVars) pers).setInBlockState(pers.world.getBlockState(pos));
Vec3d vec3d = blockRes.getPos().subtract(pers.getX(), pers.getY(), pers.getZ());
pers.setVelocity(vec3d);
Vec3d vec3d2 = vec3d.normalize().multiply(0.05000000074505806D);
pers.setPos(pers.getX() - vec3d2.x, pers.getY() - vec3d2.y, pers.getZ() - vec3d2.z);
pers.playSound(((IPersistentProjectileVars) pers).getSoundEvent(), 1.0F, 1.2F / (pers.world.random.nextFloat() * 0.2F + 0.9F));
((IPersistentProjectileVars) pers).setInGround(true);
pers.shake = 7;
pers.setCritical(false);
pers.setPierceLevel((byte) 0);
pers.setSound(SoundEvents.ENTITY_ARROW_HIT);
pers.setShotFromCrossbow(false);
((IPersistentProjectileVars) pers).resetPiercingStatus();
}
//TODO: find a way to properly update chorus fruit break on hit
//player.getServer().send(new ServerTask(player.getServer().getTicks()+2, ()->player.world.updateListeners(pos, state, state, 2)));
}
return flag;
} else if (res.getType() == HitResult.Type.ENTITY) {
if (proj instanceof EnderPearlEntity) {
ClaimStorage storage = ClaimStorage.get((ServerWorld) proj.world);
IPermissionContainer claim = storage.getForPermissionCheck(proj.getBlockPos());
return claim.canInteract(player, PermissionRegistry.ENDERPEARL, proj.getBlockPos(), true);
}
Entity hit = ((EntityHitResult) res).getEntity();
boolean fail = attackSimple(player, hit, true) != ActionResult.PASS;
if (fail && proj instanceof PersistentProjectileEntity && ((PersistentProjectileEntity) proj).getPierceLevel() > 0) {
PersistentProjectileEntity pers = (PersistentProjectileEntity) proj;
IntOpenHashSet pierced = ((IPersistentProjectileVars) pers).getPiercedEntities();
if (pierced == null)
pierced = new IntOpenHashSet(5);
pierced.add(hit.getEntityId());
((IPersistentProjectileVars) pers).setPiercedEntities(pierced);
pers.setPierceLevel((byte) (pers.getPierceLevel() + 1));
}
return fail;
}
}
return false;
}
public static boolean preventDamage(Entity entity, DamageSource source) {
if (source.getAttacker() instanceof ServerPlayerEntity)
return attackSimple((ServerPlayerEntity) source.getAttacker(), entity, true) != ActionResult.PASS;
else if (source.isExplosive() && !entity.world.isClient) {
IPermissionContainer claim = ClaimStorage.get((ServerWorld) entity.world).getForPermissionCheck(entity.getBlockPos());
return claim != null && !claim.canInteract(null, PermissionRegistry.EXPLOSIONS, entity.getBlockPos());
}
return false;
}
public static ActionResult attackSimple(PlayerEntity p, Entity entity, boolean message) {
if (p.world.isClient || p.isSpectator() || canInteract(entity))
return ActionResult.PASS;
if (entity instanceof Monster)
return ActionResult.PASS;
ServerPlayerEntity player = (ServerPlayerEntity) p;
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
BlockPos pos = entity.getBlockPos();
IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (claim != null) {
if (!(entity instanceof LivingEntity))
return claim.canInteract(player, PermissionRegistry.BREAKNONLIVING, pos, message) ? ActionResult.PASS : ActionResult.FAIL;
if (entity instanceof PlayerEntity)
return claim.canInteract(player, PermissionRegistry.HURTPLAYER, pos, message) ? ActionResult.PASS : ActionResult.FAIL;
return claim.canInteract(player, PermissionRegistry.HURTANIMAL, pos, message) ? ActionResult.PASS : ActionResult.FAIL;
}
return ActionResult.PASS;
}
public static boolean xpAbsorb(PlayerEntity player) {
if (player instanceof ServerPlayerEntity) {
ClaimStorage storage = ClaimStorage.get((ServerWorld) player.world);
BlockPos pos = player.getBlockPos();
IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (claim != null)
return !claim.canInteract((ServerPlayerEntity) player, PermissionRegistry.XP, pos, false);
}
return false;
}
public static boolean canCollideWith(PlayerEntity player, Entity entity) {
if (player instanceof ServerPlayerEntity) {
ServerPlayerEntity sPlayer = (ServerPlayerEntity) player;
if (entity instanceof ItemEntity) {
IOwnedItem ownedItem = (IOwnedItem) entity;
if (ownedItem.getDeathPlayer() != null && ConfigHandler.config.lockDrops) {
ServerPlayerEntity other = sPlayer.getServer().getPlayerManager().getPlayer(ownedItem.getDeathPlayer());
if (other == null)
return false;
return ownedItem.getDeathPlayer().equals(player.getUuid()) || PlayerClaimData.get(other).deathItemsUnlocked();
}
if (sPlayer.getUuid().equals(ownedItem.getPlayerOrigin()))
return true;
ClaimStorage storage = ClaimStorage.get(sPlayer.getServerWorld());
BlockPos pos = sPlayer.getBlockPos();
IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (claim != null)
return claim.canInteract(sPlayer, PermissionRegistry.PICKUP, pos, false);
}
}
return true;
}
public static boolean canDropItem(PlayerEntity player, ItemStack stack) {
if (!player.isDead() && player instanceof ServerPlayerEntity) {
ClaimStorage storage = ClaimStorage.get((ServerWorld) player.world);
BlockPos pos = player.getBlockPos();
IPermissionContainer claim = storage.getForPermissionCheck(pos);
boolean allow = true;
if (claim != null)
allow = claim.canInteract((ServerPlayerEntity) player, PermissionRegistry.DROP, pos, false);
if (!allow) {
player.inventory.insertStack(stack);
DefaultedList<ItemStack> stacks = DefaultedList.of();
for (int j = 0; j < player.currentScreenHandler.slots.size(); ++j) {
ItemStack itemStack2 = player.currentScreenHandler.slots.get(j).getStack();
stacks.add(itemStack2.isEmpty() ? ItemStack.EMPTY : itemStack2);
}
((ServerPlayerEntity) player).networkHandler.sendPacket(new InventoryS2CPacket(player.currentScreenHandler.syncId, stacks));
}
return allow;
}
return true;
}
public static boolean witherCanDestroy(WitherEntity wither) {
if (wither.world.isClient)
return true;
ClaimStorage storage = ClaimStorage.get((ServerWorld) wither.world);
BlockPos.Mutable pos = wither.getBlockPos().mutableCopy();
for (int x = -1; x <= 1; x++)
for (int z = -1; z <= 1; z++) {
IPermissionContainer claim = storage.getForPermissionCheck(wither.getBlockPos().add(x, 0, z));
if (!claim.canInteract(null, PermissionRegistry.WITHER, pos.set(pos.getX() + x, pos.getY() + 3, pos.getZ() + z), false))
return false;
}
return true;
}
public static boolean canEndermanInteract(EndermanEntity enderman, BlockPos pos) {
if (enderman.world.isClient)
return true;
ClaimStorage storage = ClaimStorage.get((ServerWorld) enderman.world);
IPermissionContainer claim = storage.getForPermissionCheck(pos);
return claim.canInteract(null, PermissionRegistry.ENDERMAN, pos, false);
}
public static boolean canSnowGolemInteract(SnowGolemEntity snowgolem) {
if (snowgolem.world.isClient)
return true;
int x, y, z;
for (int l = 0; l < 4; ++l) {
x = MathHelper.floor(snowgolem.getX() + (l % 2 * 2 - 1) * 0.25F);
y = MathHelper.floor(snowgolem.getY());
z = MathHelper.floor(snowgolem.getZ() + (l / 2 % 2 * 2 - 1) * 0.25F);
BlockPos pos = new BlockPos(x, y, z);
IPermissionContainer claim = ClaimStorage.get((ServerWorld) snowgolem.world).getForPermissionCheck(pos);
if (!claim.canInteract(null, PermissionRegistry.SNOWGOLEM, pos, false))
return false;
}
return true;
}
public static void updateDroppedItem(PlayerEntity player, ItemEntity entity) {
((IOwnedItem) entity).setOriginPlayer((player));
}
public static void updateClaim(ServerPlayerEntity player, Claim currentClaim, Consumer<Claim> cons) {
Vec3d pos = player.getPos();
BlockPos rounded = TeleportUtils.roundedBlockPos(pos.add(0, player.getActiveEyeHeight(player.getPose(), player.getDimensions(player.getPose())), 0));
ClaimStorage storage = ClaimStorage.get(player.getServerWorld());
if (currentClaim != null) {
if (!currentClaim.insideClaim(rounded)) {
cons.accept(null);
} else {
if (!player.isSpectator()) {
BlockPos.Mutable bPos = rounded.mutableCopy();
if (!currentClaim.canInteract(player, PermissionRegistry.CANSTAY, bPos, true)) {
Vec3d tp = TeleportUtils.getTeleportPos(player, pos, storage, currentClaim.getDimensions(), bPos, (claim, nPos) -> claim.canInteract(player, PermissionRegistry.CANSTAY, nPos, false));
player.teleport(tp.getX(), tp.getY(), tp.getZ());
}
if (player.abilities.flying && !player.isCreative() && !currentClaim.canInteract(player, PermissionRegistry.FLIGHT, rounded, true)) {
player.abilities.flying = false;
player.networkHandler.sendPacket(new PlayerAbilitiesS2CPacket(player.abilities));
}
}
}
} else if (player.age % 3 == 0) {
Claim claim = storage.getClaimAt(rounded);
cons.accept(claim);
}
}
}

View File

@ -0,0 +1,84 @@
package io.github.flemmli97.flan.forgeevent;
import io.github.flemmli97.flan.event.EntityInteractEvents;
import net.minecraft.entity.Entity;
import net.minecraft.entity.boss.WitherEntity;
import net.minecraft.entity.passive.SnowGolemEntity;
import net.minecraft.entity.projectile.ProjectileEntity;
import net.minecraft.util.ActionResult;
import net.minecraft.util.hit.EntityHitResult;
import net.minecraftforge.event.entity.EntityMobGriefingEvent;
import net.minecraftforge.event.entity.ProjectileImpactEvent;
import net.minecraftforge.event.entity.item.ItemTossEvent;
import net.minecraftforge.event.entity.living.LivingDamageEvent;
import net.minecraftforge.event.entity.player.AttackEntityEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.entity.player.PlayerXpEvent;
import net.minecraftforge.eventbus.api.Event;
public class EntityInteractEventsForge {
public static ActionResult attackEntity(AttackEntityEvent event) {
return EntityInteractEvents.attackSimple(event.getPlayer(), event.getTarget(), true);
}
public static void useAtEntity(PlayerInteractEvent.EntityInteractSpecific event) {
Entity target = event.getTarget();
ActionResult result = EntityInteractEvents.useAtEntity(event.getPlayer(), event.getWorld(), event.getHand(), target,
new EntityHitResult(target, event.getLocalPos().add(target.getX(), target.getY(), target.getZ())));
if (result != ActionResult.PASS) {
event.setCancellationResult(result);
event.setCanceled(true);
}
}
public static void useEntity(PlayerInteractEvent.EntityInteract event) {
ActionResult result = EntityInteractEvents.useEntity(event.getPlayer(), event.getWorld(), event.getHand(), event.getTarget());
if (result != ActionResult.PASS) {
event.setCancellationResult(result);
event.setCanceled(true);
}
}
public static void projectileHit(ProjectileImpactEvent event) {
if (!(event.getEntity() instanceof ProjectileEntity))
return;
boolean stop = EntityInteractEvents.projectileHit((ProjectileEntity) event.getEntity(), event.getRayTraceResult());
if (stop) {
event.setCanceled(true);
}
}
public static void preventDamage(LivingDamageEvent event) {
boolean prevent = EntityInteractEvents.preventDamage(event.getEntity(), event.getSource());
if (prevent) {
event.setCanceled(true);
}
}
public static void xpAbsorb(PlayerXpEvent.PickupXp event) {
boolean prevent = EntityInteractEvents.xpAbsorb(event.getPlayer());
if (prevent)
event.setCanceled(true);
}
public static void canDropItem(ItemTossEvent event) {
boolean canDrop = EntityInteractEvents.canDropItem(event.getPlayer(), event.getEntityItem().getStack());
if (!canDrop) {
event.setCanceled(true);
}
}
/**
* EntityInteractEvents.witherCanDestroy
* EntityInteractEvents.canSnowGolemInteract
*/
public static void mobGriefing(EntityMobGriefingEvent event) {
if (event.getEntity() instanceof WitherEntity && EntityInteractEvents.witherCanDestroy((WitherEntity) event.getEntity())) {
event.setResult(Event.Result.DENY);
}
if (event.getEntity() instanceof SnowGolemEntity && !EntityInteractEvents.canSnowGolemInteract((SnowGolemEntity) event.getEntity())) {
event.setResult(Event.Result.DENY);
}
}
}

View File

@ -1,119 +1,18 @@
package io.github.flemmli97.flan.forgeevent;
import com.google.common.collect.Sets;
import com.mojang.authlib.GameProfile;
import io.github.flemmli97.flan.api.ClaimPermission;
import io.github.flemmli97.flan.api.PermissionRegistry;
import io.github.flemmli97.flan.claim.Claim;
import io.github.flemmli97.flan.claim.ClaimStorage;
import io.github.flemmli97.flan.claim.IPermissionContainer;
import io.github.flemmli97.flan.claim.ObjectToPermissionMap;
import io.github.flemmli97.flan.claim.PermHelper;
import io.github.flemmli97.flan.config.ConfigHandler;
import io.github.flemmli97.flan.integration.permissionapi.CommandPermission;
import io.github.flemmli97.flan.player.EnumDisplayType;
import io.github.flemmli97.flan.player.EnumEditMode;
import io.github.flemmli97.flan.player.PlayerClaimData;
import net.minecraft.block.BlockState;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem;
import net.minecraft.item.Item;
import net.minecraft.item.ItemPlacementContext;
import io.github.flemmli97.flan.event.ItemInteractEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.item.Items;
import net.minecraft.network.packet.s2c.play.BlockUpdateS2CPacket;
import net.minecraft.network.packet.s2c.play.ScreenHandlerSlotUpdateS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Formatting;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import java.util.Set;
public class ItemInteractEventsForge {
public static TypedActionResult<ItemStack> useItem(PlayerInteractEvent.RightClickItem event) {
event.set
PlayerInteractEvent.RightClickItem event
if (world.isClient || p.isSpectator())
return TypedActionResult.pass(p.getStackInHand(hand));
ServerPlayerEntity player = (ServerPlayerEntity) p;
ItemStack stack = player.getStackInHand(hand);
if (stack.getItem() == ConfigHandler.config.claimingItem) {
HitResult ray = player.rayTrace(64, 0, false);
if (ray != null && ray.getType() == HitResult.Type.BLOCK) {
claimLandHandling(player, ((BlockHitResult) ray).getBlockPos());
return TypedActionResult.success(stack);
}
return TypedActionResult.pass(stack);
public static void useItem(PlayerInteractEvent.RightClickItem event) {
TypedActionResult<ItemStack> result = ItemInteractEvents.useItem(event.getPlayer(), event.getWorld(), event.getHand());
if (result.getResult() != ActionResult.PASS) {
event.setCanceled(true);
event.setCancellationResult(result.getResult());
}
if (stack.getItem() == ConfigHandler.config.inspectionItem) {
HitResult ray = player.rayTrace(32, 0, false);
if (ray != null && ray.getType() == HitResult.Type.BLOCK) {
inspect(player, ((BlockHitResult) ray).getBlockPos());
return TypedActionResult.success(stack);
}
return TypedActionResult.pass(stack);
}
ClaimStorage storage = ClaimStorage.get((ServerWorld) world);
BlockPos pos = player.getBlockPos();
IPermissionContainer claim = storage.getForPermissionCheck(pos);
if (claim == null)
return TypedActionResult.pass(stack);
ClaimPermission perm = ObjectToPermissionMap.getFromItem(stack.getItem());
if (perm != null)
return claim.canInteract(player, perm, pos, true) ? TypedActionResult.pass(stack) : TypedActionResult.fail(stack);
return TypedActionResult.pass(stack);
}
private static final Set<Item> blackListedItems = Sets.newHashSet(Items.COMPASS, Items.FILLED_MAP, Items.FIREWORK_ROCKET);
public static ActionResult onItemUseBlock(ItemUsageContext context) {
//Check for Fakeplayer. Since there is no api for that directly check the class
if (!(context.getPlayer() instanceof ServerPlayerEntity) || !context.getPlayer().getClass().equals(ServerPlayerEntity.class) || context.getStack().isEmpty())
return ActionResult.PASS;
ClaimStorage storage = ClaimStorage.get((ServerWorld) context.getWorld());
BlockPos placePos = new ItemPlacementContext(context).getBlockPos();
IPermissionContainer claim = storage.getForPermissionCheck(placePos.add(0, 255, 0));
if (claim == null)
return ActionResult.PASS;
if (blackListedItems.contains(context.getStack().getItem()))
return ActionResult.PASS;
boolean actualInClaim = !(claim instanceof Claim) || placePos.getY() >= ((Claim) claim).getDimensions()[4];
ServerPlayerEntity player = (ServerPlayerEntity) context.getPlayer();
ClaimPermission perm = ObjectToPermissionMap.getFromItem(context.getStack().getItem());
if (perm != null) {
if (claim.canInteract(player, perm, placePos, false))
return ActionResult.PASS;
else if (actualInClaim) {
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
return ActionResult.FAIL;
}
}
if (claim.canInteract(player, PermissionRegistry.PLACE, placePos, false)) {
if (!actualInClaim && context.getStack().getItem() instanceof BlockItem) {
((Claim) claim).extendDownwards(placePos);
}
return ActionResult.PASS;
} else if (actualInClaim) {
player.sendMessage(PermHelper.simpleColoredText(ConfigHandler.lang.noPermissionSimple, Formatting.DARK_RED), true);
BlockState other = context.getWorld().getBlockState(placePos.up());
player.networkHandler.sendPacket(new BlockUpdateS2CPacket(placePos.up(), other));
PlayerClaimData.get(player).addDisplayClaim(claim, EnumDisplayType.MAIN, player.getBlockPos().getY());
updateHeldItem(player);
return ActionResult.FAIL;
}
return ActionResult.PASS;
}
}

View File

@ -0,0 +1,21 @@
package io.github.flemmli97.flan.forgeevent;
import io.github.flemmli97.flan.Flan;
import io.github.flemmli97.flan.claim.ObjectToPermissionMap;
import io.github.flemmli97.flan.commands.CommandClaim;
import io.github.flemmli97.flan.config.ConfigHandler;
import net.minecraftforge.event.RegisterCommandsEvent;
import net.minecraftforge.fml.event.server.FMLServerAboutToStartEvent;
public class ServerEvents {
public static void serverStart(FMLServerAboutToStartEvent event) {
ConfigHandler.serverLoad(event.getServer());
ObjectToPermissionMap.reload(event.getServer());
Flan.lockRegistry(event.getServer());
}
public static void commands(RegisterCommandsEvent event) {
CommandClaim.register(event.getDispatcher(), false);
}
}

View File

@ -1,21 +1,13 @@
package io.github.flemmli97.flan.forgeevent;
import io.github.flemmli97.flan.api.PermissionRegistry;
import io.github.flemmli97.flan.claim.ClaimStorage;
import io.github.flemmli97.flan.claim.IPermissionContainer;
import io.github.flemmli97.flan.event.WorldEvents;
import net.minecraft.block.BlockState;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraftforge.event.entity.living.LivingSpawnEvent;
import net.minecraftforge.event.world.ExplosionEvent;
import net.minecraftforge.event.world.PistonEvent;
import net.minecraftforge.eventbus.api.Event;
public class WorldEventsForge {
@ -35,6 +27,6 @@ public class WorldEventsForge {
if (!(event.getWorld() instanceof ServerWorld) || !(event.getEntityLiving() instanceof MobEntity))
return;
if (WorldEvents.preventMobSpawn((ServerWorld) event.getWorld(), (MobEntity) event.getEntityLiving()))
event.setCanceled(true);
event.setResult(Event.Result.DENY);
}
}

View File

@ -1,7 +1,7 @@
package io.github.flemmli97.flan.integration.permissionapi.forge;
import io.github.flemmli97.flan.config.ConfigHandler;
import net.minecraft.server.command.CommandSource;
import net.minecraft.command.CommandSource;
import net.minecraft.server.network.ServerPlayerEntity;
public class CommandPermissionImpl {

View File

@ -3,13 +3,13 @@ loaderVersion="[35,)"
license="All rights reserved"
issueTrackerURL="https://github.com/Flemmli97/Flan/issues"
displayURL="https://github.com/Flemmli97/Flan"
# logoFile="flan/icon.png"
# logoFile="assets/flan/icon.png"
credits=""
authors="Flemmli97"
[[mods]]
modId="flan"
version="${file.jarVersion}"
version="${version}"
displayName="Flan"
# updateJSONURL=""
authors="Flemmli97"
description='''Land claiming mod'''
description='''Flan (Forge version): A serverside claiming mod'''

View File

@ -0,0 +1,14 @@
{
"required": true,
"minVersion": "0.8",
"package": "io.github.flemmli97.flan.forge.mixin",
"compatibilityLevel": "JAVA_8",
"mixins": [
"ForgeFireMixin"
],
"server": [
],
"injectors": {
"defaultRequire": 1
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 2.9 KiB

View File

@ -0,0 +1,6 @@
{
"pack": {
"description": "Flan resources",
"pack_format": 6
}
}