Bug fixes
- Fix rift signatures overwriting old rift/replacing blocks - Fix rifts placed by door break being refreshed by Minecraft - Fix pitch and yaw being inverted on teleport
This commit is contained in:
parent
abdfd49822
commit
5ad37b1992
4 changed files with 72 additions and 39 deletions
|
@ -1,6 +1,7 @@
|
|||
package org.dimdev.dimdoors.shared.items;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.util.*;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
@ -54,22 +55,27 @@ public class ItemRiftSignature extends Item {
|
|||
}
|
||||
pos = pos.offset(side);
|
||||
|
||||
RotatedLocation source = getSource(stack);
|
||||
RotatedLocation target = getSource(stack);
|
||||
|
||||
if (source != null) {
|
||||
// Place a rift at the destination point
|
||||
if (target != null) {
|
||||
// Place a rift at the saved point TODO: check that the player still has permission
|
||||
if (!target.getLocation().getBlockState().equals(ModBlocks.RIFT)) {
|
||||
if (!target.getLocation().getBlockState().getBlock().equals(Blocks.AIR)) {
|
||||
return EnumActionResult.FAIL; // TODO: send a message
|
||||
}
|
||||
World sourceWorld = target.getLocation().getWorld();
|
||||
sourceWorld.setBlockState(target.getLocation().getPos(), ModBlocks.RIFT.getDefaultState());
|
||||
TileEntityRift rift1 = (TileEntityRift) target.getLocation().getTileEntity();
|
||||
rift1.setSingleDestination(new GlobalDestination(new Location(world, pos)));
|
||||
rift1.register();
|
||||
rift1.setRotation(target.getYaw(), 0);
|
||||
}
|
||||
|
||||
// Place a rift at the target point
|
||||
world.setBlockState(pos, ModBlocks.RIFT.getDefaultState());
|
||||
TileEntityRift rift1 = (TileEntityRift) world.getTileEntity(pos);
|
||||
rift1.setSingleDestination(new GlobalDestination(source.getLocation()));
|
||||
rift1.setRotation(player.rotationYaw, 0);
|
||||
rift1.register();
|
||||
|
||||
// Place a rift at the source point
|
||||
World sourceWorld = source.getLocation().getWorld();
|
||||
sourceWorld.setBlockState(source.getLocation().getPos(), ModBlocks.RIFT.getDefaultState());
|
||||
TileEntityRift rift2 = (TileEntityRift) source.getLocation().getTileEntity();
|
||||
rift2.setSingleDestination(new GlobalDestination(rift1.getLocation()));
|
||||
rift2.setRotation(source.getYaw(), 0);
|
||||
TileEntityRift rift2 = (TileEntityRift) world.getTileEntity(pos);
|
||||
rift2.setSingleDestination(new GlobalDestination(target.getLocation()));
|
||||
rift2.setRotation(player.rotationYaw, 0);
|
||||
rift2.register();
|
||||
|
||||
stack.damageItem(1, player); // TODO: calculate damage based on position?
|
||||
|
|
|
@ -2,6 +2,7 @@ package org.dimdev.dimdoors.shared.items;
|
|||
|
||||
import net.minecraft.client.util.ITooltipFlag;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -59,6 +60,9 @@ public class ItemStabilizedRiftSignature extends Item { // TODO: common supercla
|
|||
if (target != null) {
|
||||
// Place a rift at the target point
|
||||
if (!target.getLocation().getBlockState().getBlock().equals(ModBlocks.RIFT)) {
|
||||
if (!target.getLocation().getBlockState().getBlock().equals(Blocks.AIR)) {
|
||||
return EnumActionResult.FAIL; // TODO: send a message
|
||||
}
|
||||
World targetWorld = target.getLocation().getWorld();
|
||||
targetWorld.setBlockState(target.getLocation().getPos(), ModBlocks.RIFT.getDefaultState());
|
||||
TileEntityRift rift1 = (TileEntityRift) target.getLocation().getTileEntity();
|
||||
|
@ -66,7 +70,7 @@ public class ItemStabilizedRiftSignature extends Item { // TODO: common supercla
|
|||
rift1.register();
|
||||
}
|
||||
|
||||
// Place a rift at the target point
|
||||
// Place a rift at the source point
|
||||
world.setBlockState(pos, ModBlocks.RIFT.getDefaultState());
|
||||
TileEntityRift rift2 = (TileEntityRift) world.getTileEntity(pos);
|
||||
rift2.setSingleDestination(new GlobalDestination(target.getLocation()));
|
||||
|
|
|
@ -2,22 +2,22 @@ package org.dimdev.dimdoors.shared.rifts;
|
|||
|
||||
import com.google.common.collect.ConcurrentHashMultiset;
|
||||
import com.google.common.collect.Multiset;
|
||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
||||
import org.dimdev.ddutils.nbt.SavedToNBT;
|
||||
import org.dimdev.dimdoors.shared.world.ModDimensions;
|
||||
import org.dimdev.ddutils.nbt.INBTStorable; // Don't change imports order! (Gradle bug): https://stackoverflow.com/questions/26557133/
|
||||
import org.dimdev.ddutils.Location;
|
||||
import org.dimdev.ddutils.WorldUtils;
|
||||
import lombok.*;
|
||||
import lombok.experimental.Wither;
|
||||
import org.dimdev.dimdoors.DimDoors;
|
||||
import org.dimdev.dimdoors.shared.VirtualLocation;
|
||||
import org.dimdev.dimdoors.shared.rifts.RiftRegistry.RiftInfo.AvailableLinkInfo;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.storage.MapStorage;
|
||||
import net.minecraft.world.storage.WorldSavedData;
|
||||
import net.minecraftforge.common.DimensionManager;
|
||||
import org.dimdev.ddutils.Location;
|
||||
import org.dimdev.ddutils.WorldUtils;
|
||||
import org.dimdev.ddutils.nbt.INBTStorable;
|
||||
import org.dimdev.ddutils.nbt.NBTUtils;
|
||||
import org.dimdev.ddutils.nbt.SavedToNBT;
|
||||
import org.dimdev.dimdoors.DimDoors;
|
||||
import org.dimdev.dimdoors.shared.VirtualLocation;
|
||||
import org.dimdev.dimdoors.shared.rifts.RiftRegistry.RiftInfo.AvailableLinkInfo;
|
||||
import org.dimdev.dimdoors.shared.world.ModDimensions;
|
||||
|
||||
import java.util.*;
|
||||
|
||||
|
@ -50,6 +50,7 @@ import java.util.*;
|
|||
@SavedToNBT @Getter /*package-private*/ UUID uuid;
|
||||
|
||||
@Override public void readFromNBT(NBTTagCompound nbt) { NBTUtils.readFromNBT(this, nbt); }
|
||||
|
||||
@Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { return NBTUtils.writeToNBT(this, nbt); }
|
||||
}
|
||||
|
||||
|
@ -60,6 +61,7 @@ import java.util.*;
|
|||
}
|
||||
|
||||
@Override public void readFromNBT(NBTTagCompound nbt) { NBTUtils.readFromNBT(this, nbt); }
|
||||
|
||||
@Override public NBTTagCompound writeToNBT(NBTTagCompound nbt) { return NBTUtils.writeToNBT(this, nbt); }
|
||||
}
|
||||
|
||||
|
@ -116,7 +118,7 @@ import java.util.*;
|
|||
// Upgrade to 2 or return false
|
||||
case 2:
|
||||
// Upgrade to 3 or return false
|
||||
// ...
|
||||
// ...
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
@ -132,52 +134,59 @@ import java.util.*;
|
|||
}
|
||||
|
||||
public static void addRift(Location rift) {
|
||||
DimDoors.log.info("Rift added at " + rift);
|
||||
RiftRegistry registry = getRegistry(rift);
|
||||
registry.rifts.put(rift, new RiftInfo());
|
||||
registry.rifts.computeIfAbsent(rift, k -> new RiftInfo());
|
||||
registry.markDirty();
|
||||
}
|
||||
|
||||
public static void removeRift(Location rift) {
|
||||
DimDoors.log.info("Rift removed at " + rift);
|
||||
RiftRegistry registry = getRegistry(rift);
|
||||
RiftInfo oldRift = registry.rifts.remove(rift);
|
||||
if (oldRift == null) return;
|
||||
List<TileEntityRift> updateQueue = new ArrayList<>();
|
||||
for (Location source : oldRift.sources) {
|
||||
RiftRegistry sourceRegistry = getRegistry(source);
|
||||
sourceRegistry.rifts.get(source).destinations.remove(rift);
|
||||
sourceRegistry.markDirty();
|
||||
TileEntityRift riftEntity = (TileEntityRift) sourceRegistry.world.getTileEntity(source.getPos());
|
||||
riftEntity.destinationGone(rift);
|
||||
updateQueue.add(riftEntity);
|
||||
}
|
||||
for (Location destination : oldRift.destinations) {
|
||||
RiftRegistry destinationRegistry = getRegistry(destination);
|
||||
destinationRegistry.rifts.get(destination).sources.remove(rift);
|
||||
destinationRegistry.markDirty();
|
||||
//TileEntityRift riftEntity = (TileEntityRift) destinationRegistry.world.getTileEntity(destination.getPos());
|
||||
TileEntityRift riftEntity = (TileEntityRift) destinationRegistry.world.getTileEntity(destination.getPos());
|
||||
updateQueue.add(riftEntity);
|
||||
//riftEntity.allSourcesGone(); // TODO
|
||||
}
|
||||
for (TileEntityRift riftEntity : updateQueue) {
|
||||
//riftEntity.updateColor();
|
||||
riftEntity.markDirty();
|
||||
}
|
||||
getForDim(ModDimensions.getPrivateDim()).privatePocketEntrances.entrySet().removeIf(e -> e.getValue().equals(rift));
|
||||
getForDim(0).overworldRifts.entrySet().removeIf(e -> e.getValue().equals(rift));
|
||||
registry.markDirty();
|
||||
}
|
||||
|
||||
public static void addLink(Location from, Location to) {
|
||||
DimDoors.log.info("Link added " + from + " -> " + to);
|
||||
RiftRegistry registryFrom = getRegistry(from);
|
||||
RiftRegistry registryTo = getRegistry(to);
|
||||
RiftInfo riftInfoFrom = registryFrom.rifts.get(from);
|
||||
RiftInfo riftInfoTo = registryTo.rifts.get(to);
|
||||
if (riftInfoFrom != null) {
|
||||
riftInfoFrom.destinations.add(to);
|
||||
registryFrom.markDirty();
|
||||
}
|
||||
if (riftInfoTo != null) {
|
||||
registryTo.rifts.get(to).sources.add(from);
|
||||
registryTo.markDirty();
|
||||
}
|
||||
RiftInfo riftInfoFrom = registryFrom.rifts.computeIfAbsent(from, k -> new RiftInfo());
|
||||
RiftInfo riftInfoTo = registryTo.rifts.computeIfAbsent(to, k -> new RiftInfo());
|
||||
riftInfoFrom.destinations.add(to);
|
||||
registryFrom.markDirty();
|
||||
riftInfoTo.sources.add(from);
|
||||
registryTo.markDirty();
|
||||
if (to.getTileEntity() instanceof TileEntityRift) ((TileEntityRift) to.getTileEntity()).updateColor();
|
||||
if (from.getTileEntity() instanceof TileEntityRift) ((TileEntityRift) from.getTileEntity()).updateColor();
|
||||
}
|
||||
|
||||
public static void removeLink(Location from, Location to) {
|
||||
DimDoors.log.info("Link removed " + from + " -> " + to);
|
||||
RiftRegistry registryFrom = getRegistry(from);
|
||||
RiftRegistry registryTo = getRegistry(to);
|
||||
registryFrom.rifts.get(from).destinations.remove(to);
|
||||
|
@ -189,24 +198,28 @@ import java.util.*;
|
|||
}
|
||||
|
||||
public static void addAvailableLink(Location rift, AvailableLinkInfo link) { // TODO cache rifts with availableLinks
|
||||
DimDoors.log.info("AvailableLink added at " + rift);
|
||||
RiftRegistry registry = getRegistry(rift);
|
||||
registry.rifts.get(rift).availableLinks.add(link);
|
||||
registry.markDirty();
|
||||
}
|
||||
|
||||
public static void removeAvailableLink(Location rift, AvailableLinkInfo link) {
|
||||
DimDoors.log.info("AvailableLink removed at " + rift);
|
||||
RiftRegistry registry = getRegistry(rift);
|
||||
registry.rifts.get(rift).availableLinks.remove(link);
|
||||
registry.markDirty();
|
||||
}
|
||||
|
||||
public static void clearAvailableLinks(Location rift) {
|
||||
DimDoors.log.info("AvailableLink cleared at " + rift);
|
||||
RiftRegistry registry = getRegistry(rift);
|
||||
registry.rifts.get(rift).availableLinks.clear();
|
||||
registry.markDirty();
|
||||
}
|
||||
|
||||
public static void removeAvailableLinkByUUID(Location rift, UUID uuid) {
|
||||
DimDoors.log.info("AvailableLink with uuid " + uuid + " removed at " + rift);
|
||||
RiftRegistry registry = getRegistry(rift);
|
||||
for (AvailableLinkInfo link : registry.rifts.get(rift).availableLinks) {
|
||||
if (link.uuid.equals(uuid)) {
|
||||
|
@ -232,10 +245,12 @@ import java.util.*;
|
|||
}
|
||||
|
||||
public void addPrivatePocketEntrance(String playerUUID, Location rift) {
|
||||
DimDoors.log.info("Private pocket entrance added for " + playerUUID + " at " + rift);
|
||||
privatePocketEntranceLists.computeIfAbsent(playerUUID, k -> new ArrayList<>()).add(rift);
|
||||
}
|
||||
|
||||
public void setPrivatePocketEntrance(String playerUUID, Location rift) {
|
||||
DimDoors.log.info("Last private pocket entrance set for " + playerUUID + " at " + rift);
|
||||
privatePocketEntrances.put(playerUUID, rift);
|
||||
markDirty();
|
||||
}
|
||||
|
@ -245,6 +260,7 @@ import java.util.*;
|
|||
}
|
||||
|
||||
public void setPrivatePocketExit(String playerUUID, Location rift) {
|
||||
DimDoors.log.info("Last private pocket exit set for " + playerUUID + " at " + rift);
|
||||
if (rift != null) {
|
||||
privatePocketExits.put(playerUUID, rift);
|
||||
} else {
|
||||
|
@ -258,6 +274,7 @@ import java.util.*;
|
|||
}
|
||||
|
||||
public static void setOverworldRift(String playerUUID, Location rift) {
|
||||
DimDoors.log.info("Overworld rift set for " + playerUUID + " at " + rift);
|
||||
if (rift != null) {
|
||||
getForDim(0).overworldRifts.put(playerUUID, rift);
|
||||
} else {
|
||||
|
|
|
@ -5,6 +5,8 @@ import org.dimdev.ddutils.nbt.SavedToNBT;
|
|||
import org.dimdev.ddutils.RGBA;
|
||||
import org.dimdev.dimdoors.DimDoors;
|
||||
import org.dimdev.dimdoors.shared.VirtualLocation;
|
||||
import org.dimdev.dimdoors.shared.blocks.BlockDimensionalDoor;
|
||||
import org.dimdev.dimdoors.shared.blocks.BlockFloatingRift;
|
||||
import org.dimdev.dimdoors.shared.pockets.Pocket;
|
||||
import org.dimdev.dimdoors.shared.pockets.PocketRegistry;
|
||||
import org.dimdev.ddutils.EntityUtils;
|
||||
|
@ -99,7 +101,11 @@ import java.util.*;
|
|||
// Use vanilla behavior of refreshing only when block changes, not state (otherwise, opening the door would destroy the tile entity)
|
||||
@Override
|
||||
public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IBlockState newSate) {
|
||||
return oldState.getBlock() != newSate.getBlock();
|
||||
// newState is not accurate if we change the state during onBlockBreak
|
||||
newSate = world.getBlockState(pos);
|
||||
return oldState.getBlock() != newSate.getBlock() &&
|
||||
!(oldState.getBlock() instanceof BlockDimensionalDoor
|
||||
&& newSate.getBlock() instanceof BlockFloatingRift);
|
||||
}
|
||||
|
||||
// Modification functions
|
||||
|
@ -290,7 +296,7 @@ import java.util.*;
|
|||
newYaw = yaw;
|
||||
newPitch = pitch;
|
||||
}
|
||||
TeleportUtils.teleport(entity, new Location(world, pos), newPitch, newYaw);
|
||||
TeleportUtils.teleport(entity, new Location(world, pos), newYaw, newPitch);
|
||||
}
|
||||
|
||||
public void updateColor() { // TODO: have the registry call this method too
|
||||
|
|
Loading…
Add table
Reference in a new issue