mirror of
https://github.com/GTNewHorizons/Botania.git
synced 2026-11-18 19:29:31 +00:00
Force relay tweaks, hopefully resolves #232
This commit is contained in:
3 files changed
+38
-34
No files matched your search
@@ -16,6 +16,7 @@ import java.util.HashSet;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
import java.util.UUID;
|
||||
|
||||
import gnu.trove.map.hash.TObjectIntHashMap;
|
||||
import net.minecraft.block.Block;
|
||||
@@ -55,12 +56,15 @@ import net.minecraftforge.fml.common.gameevent.TickEvent.Type;
|
||||
|
||||
public class BlockPistonRelay extends BlockMod implements IWandable, ILexiconable {
|
||||
|
||||
public static final Map<String, DimWithPos> playerPositions = new HashMap<>();
|
||||
public static final Map<DimWithPos, DimWithPos> mappedPositions = new HashMap<>();
|
||||
// Currently active binding attempts
|
||||
public final Map<UUID, DimWithPos> playerPositions = new HashMap<>();
|
||||
|
||||
private static final Set<DimWithPos> removeThese = new HashSet<>();
|
||||
private static final Set<DimWithPos> checkedCoords = new HashSet<>();
|
||||
private static final TObjectIntHashMap<DimWithPos> coordsToCheck = new TObjectIntHashMap<>(10, 0.5F, -1);
|
||||
// Bindings
|
||||
public final Map<DimWithPos, DimWithPos> mappedPositions = new HashMap<>();
|
||||
|
||||
private final Set<DimWithPos> removeQueue = new HashSet<>();
|
||||
private final Set<DimWithPos> checkedCoords = new HashSet<>();
|
||||
private final TObjectIntHashMap<DimWithPos> coordsToCheck = new TObjectIntHashMap<>(10, 0.5F, -1);
|
||||
|
||||
public BlockPistonRelay() {
|
||||
super(Material.gourd, LibBlockNames.PISTON_RELAY);
|
||||
@@ -83,50 +87,49 @@ public class BlockPistonRelay extends BlockMod implements IWandable, ILexiconabl
|
||||
|
||||
@Override
|
||||
public void breakBlock(World par1World, BlockPos pos, IBlockState state) {
|
||||
mapCoords(par1World.provider.getDimension(), pos, 2);
|
||||
if(!par1World.isRemote)
|
||||
mapCoords(par1World.provider.getDimension(), pos, 2);
|
||||
}
|
||||
|
||||
static void mapCoords(int world, BlockPos pos, int time) {
|
||||
private void mapCoords(int world, BlockPos pos, int time) {
|
||||
coordsToCheck.put(new DimWithPos(world, pos), time);
|
||||
}
|
||||
|
||||
static void decrCoords(DimWithPos key) {
|
||||
private void decrCoords(DimWithPos key) {
|
||||
int time = getTimeInCoords(key);
|
||||
|
||||
if(time <= 0)
|
||||
removeThese.add(key);
|
||||
removeQueue.add(key);
|
||||
else coordsToCheck.adjustValue(key, -1);
|
||||
}
|
||||
|
||||
static int getTimeInCoords(DimWithPos key) {
|
||||
private int getTimeInCoords(DimWithPos key) {
|
||||
return coordsToCheck.get(key);
|
||||
}
|
||||
|
||||
static Block getBlockAt(DimWithPos key) {
|
||||
IBlockState state = getStateAt(key);
|
||||
return state == null ? null : state.getBlock();
|
||||
private Block getBlockAt(DimWithPos key) {
|
||||
return getStateAt(key).getBlock();
|
||||
}
|
||||
|
||||
static IBlockState getStateAt(DimWithPos key) {
|
||||
private IBlockState getStateAt(DimWithPos key) {
|
||||
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
|
||||
if(server == null)
|
||||
return null;
|
||||
return Blocks.air.getDefaultState();
|
||||
return server.worldServerForDimension(key.dim).getBlockState(key.blockPos);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUsedByWand(EntityPlayer player, ItemStack stack, World world, BlockPos pos, EnumFacing side) {
|
||||
if(player == null)
|
||||
if(player == null || world.isRemote)
|
||||
return false;
|
||||
|
||||
if(!player.isSneaking()) {
|
||||
playerPositions.put(player.getName(), new DimWithPos(world.provider.getDimension(), pos));
|
||||
playerPositions.put(player.getUniqueID(), new DimWithPos(world.provider.getDimension(), pos));
|
||||
world.playSound(null, pos, BotaniaSoundEvents.ding, SoundCategory.BLOCKS, 0.5F, 1F);
|
||||
} else {
|
||||
spawnAsEntity(world, pos, new ItemStack(this));
|
||||
world.setBlockToAir(pos);
|
||||
if(!world.isRemote)
|
||||
world.playAuxSFX(2001, pos, Block.getIdFromBlock(this));
|
||||
world.playAuxSFX(2001, pos, Block.getStateId(getDefaultState()));
|
||||
}
|
||||
|
||||
return true;
|
||||
@@ -134,12 +137,14 @@ public class BlockPistonRelay extends BlockMod implements IWandable, ILexiconabl
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldLoad(WorldEvent.Load event) {
|
||||
WorldData.get(event.getWorld());
|
||||
if(!event.getWorld().isRemote)
|
||||
WorldData.get(event.getWorld());
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
public void onWorldUnload(WorldEvent.Unload event) {
|
||||
WorldData.get(event.getWorld()).markDirty();
|
||||
if(!event.getWorld().isRemote)
|
||||
WorldData.get(event.getWorld()).markDirty();
|
||||
}
|
||||
|
||||
public static class WorldData extends WorldSavedData {
|
||||
@@ -152,7 +157,7 @@ public class BlockPistonRelay extends BlockMod implements IWandable, ILexiconabl
|
||||
|
||||
@Override
|
||||
public void readFromNBT(NBTTagCompound nbttagcompound) {
|
||||
mappedPositions.clear();
|
||||
((BlockPistonRelay) (ModBlocks.pistonRelay)).mappedPositions.clear();
|
||||
|
||||
Collection<String> tags = nbttagcompound.getKeySet();
|
||||
for(String key : tags) {
|
||||
@@ -160,15 +165,15 @@ public class BlockPistonRelay extends BlockMod implements IWandable, ILexiconabl
|
||||
if(tag instanceof NBTTagString) {
|
||||
String value = ((NBTTagString) tag).getString();
|
||||
|
||||
mappedPositions.put(DimWithPos.fromString(key), DimWithPos.fromString(value));
|
||||
((BlockPistonRelay) (ModBlocks.pistonRelay)).mappedPositions.put(DimWithPos.fromString(key), DimWithPos.fromString(value));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void writeToNBT(NBTTagCompound nbttagcompound) {
|
||||
for(DimWithPos s : mappedPositions.keySet())
|
||||
nbttagcompound.setString(s.toString(), mappedPositions.get(s).toString());
|
||||
for(DimWithPos s : ((BlockPistonRelay) (ModBlocks.pistonRelay)).mappedPositions.keySet())
|
||||
nbttagcompound.setString(s.toString(), ((BlockPistonRelay) (ModBlocks.pistonRelay)).mappedPositions.get(s).toString());
|
||||
}
|
||||
|
||||
public static WorldData get(World world) {
|
||||
@@ -248,12 +253,11 @@ public class BlockPistonRelay extends BlockMod implements IWandable, ILexiconabl
|
||||
}
|
||||
}
|
||||
|
||||
for(DimWithPos s : removeThese) {
|
||||
for(DimWithPos s : removeQueue) {
|
||||
coordsToCheck.remove(s);
|
||||
if(checkedCoords.contains(s))
|
||||
checkedCoords.remove(s);
|
||||
checkedCoords.remove(s);
|
||||
}
|
||||
removeThese.clear();
|
||||
removeQueue.clear();
|
||||
}
|
||||
|
||||
public void save(World world) {
|
||||
|
||||
@@ -141,12 +141,12 @@ public class ItemTwigWand extends Item16Colors implements ICoordBoundItem {
|
||||
}
|
||||
|
||||
return wanded ? EnumActionResult.SUCCESS : EnumActionResult.FAIL;
|
||||
} else if(BlockPistonRelay.playerPositions.containsKey(par2EntityPlayer.getName()) && !par3World.isRemote) {
|
||||
BlockPistonRelay.DimWithPos bindPos = BlockPistonRelay.playerPositions.get(par2EntityPlayer.getName());
|
||||
} else if(((BlockPistonRelay) (ModBlocks.pistonRelay)).playerPositions.containsKey(par2EntityPlayer.getUniqueID()) && !par3World.isRemote) {
|
||||
BlockPistonRelay.DimWithPos bindPos = ((BlockPistonRelay) (ModBlocks.pistonRelay)).playerPositions.get(par2EntityPlayer.getUniqueID());
|
||||
BlockPistonRelay.DimWithPos currentPos = new BlockPistonRelay.DimWithPos(par3World.provider.getDimension(), pos);
|
||||
|
||||
BlockPistonRelay.playerPositions.remove(par2EntityPlayer.getName());
|
||||
BlockPistonRelay.mappedPositions.put(bindPos, currentPos);
|
||||
((BlockPistonRelay) (ModBlocks.pistonRelay)).playerPositions.remove(par2EntityPlayer.getUniqueID());
|
||||
((BlockPistonRelay) (ModBlocks.pistonRelay)).mappedPositions.put(bindPos, currentPos);
|
||||
BlockPistonRelay.WorldData.get(par3World).markDirty();
|
||||
|
||||
par3World.playSound(null, par2EntityPlayer.posX, par2EntityPlayer.posY, par2EntityPlayer.posZ, BotaniaSoundEvents.ding, SoundCategory.PLAYERS, 1F, 1F);
|
||||
|
||||
@@ -28,7 +28,7 @@ public class LensWarp extends Lens {
|
||||
|
||||
Block block = entity.worldObj.getBlockState(pos.getBlockPos()).getBlock();
|
||||
if(block == ModBlocks.pistonRelay) {
|
||||
BlockPistonRelay.DimWithPos key = BlockPistonRelay.mappedPositions.get(new BlockPistonRelay.DimWithPos(entity.worldObj.provider.getDimension(), pos.getBlockPos()));
|
||||
BlockPistonRelay.DimWithPos key = ((BlockPistonRelay) (ModBlocks.pistonRelay)).mappedPositions.get(new BlockPistonRelay.DimWithPos(entity.worldObj.provider.getDimension(), pos.getBlockPos()));
|
||||
if(key != null) {
|
||||
if(key.dim == entity.worldObj.provider.getDimension()) {
|
||||
entity.setPosition(key.blockPos.getX() + 0.5, key.blockPos.getY() + 0.5, key.blockPos.getZ() + 0.5);
|
||||
|
||||
Reference in new issue
Block a user