Skip to content

Commit

Permalink
bugfix for home cords being reset after playing is cloned (dimension …
Browse files Browse the repository at this point in the history
…change or respawn)

Secure chests are now resistant to Explosions
  • Loading branch information
Petersil1998 committed Dec 8, 2020
1 parent 7cdd79c commit c94b0d5
Showing 1 changed file with 40 additions and 1 deletion.
41 changes: 40 additions & 1 deletion src/main/java/net/petersil98/utilcraft/event/EventHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,13 @@
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.ServerPlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.GameRules;
import net.minecraft.world.World;
import net.minecraft.world.server.ServerWorld;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
Expand All @@ -25,19 +25,24 @@
import net.minecraftforge.event.AttachCapabilitiesEvent;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.TickEvent;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.event.world.ExplosionEvent;
import net.minecraftforge.eventbus.api.Event;
import net.minecraftforge.eventbus.api.EventPriority;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.ObfuscationReflectionHelper;
import net.petersil98.utilcraft.Main;
import net.petersil98.utilcraft.blocks.SecureChest;
import net.petersil98.utilcraft.data.KeyBindings;
import net.petersil98.utilcraft.data.ModWorldSavedData;
import net.petersil98.utilcraft.data.capabilities.home.CapabilityHome;
import net.petersil98.utilcraft.data.capabilities.home.HomeProvider;
import net.petersil98.utilcraft.data.capabilities.inventory.InventoryProvider;
import net.petersil98.utilcraft.data.capabilities.vein_miner.CapabilityVeinMiner;
import net.petersil98.utilcraft.data.capabilities.vein_miner.IVeinMiner;
import net.petersil98.utilcraft.data.capabilities.vein_miner.VeinMinerProvider;
import net.petersil98.utilcraft.items.TravelersBackpack;
import net.petersil98.utilcraft.network.PacketHandler;
Expand All @@ -48,9 +53,11 @@
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.UUID;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;

import static net.petersil98.utilcraft.utils.VeinMinerUtils.*;
Expand Down Expand Up @@ -168,6 +175,38 @@ public static void onWorldTick(TickEvent.WorldTickEvent event) {
}
}

@SubscribeEvent
public static void onRespawn(PlayerEvent.Clone event) {
PlayerEntity original = event.getOriginal();
PlayerEntity clone = event.getPlayer();

AtomicReference<Boolean> veinMiner = new AtomicReference<>();

original.getCapability(CapabilityVeinMiner.VEIN_MINER_CAPABILITY).ifPresent(iVeinMiner -> {
veinMiner.set(iVeinMiner.getVeinMiner());
});

clone.getCapability(CapabilityVeinMiner.VEIN_MINER_CAPABILITY).ifPresent(iVeinMiner -> {
iVeinMiner.setVeinMiner(veinMiner.get());
});

AtomicReference<BlockPos> blockPos = new AtomicReference<>();

original.getCapability(CapabilityHome.HOME_CAPABILITY).ifPresent(iHome -> {
blockPos.set(iHome.getHome());
});

clone.getCapability(CapabilityHome.HOME_CAPABILITY).ifPresent(iHome -> {
iHome.setHome(blockPos.get());
});
}

@SubscribeEvent
public static void onExplosionEvent(ExplosionEvent.Detonate event) {
ServerWorld world = (ServerWorld)event.getWorld();
event.getAffectedBlocks().removeIf(current -> world.getBlockState(current).getBlock() instanceof SecureChest);
}

@SubscribeEvent
@OnlyIn(Dist.CLIENT)
public static void addElementsToGUI(RenderGameOverlayEvent event) {
Expand Down

0 comments on commit c94b0d5

Please sign in to comment.