-
Notifications
You must be signed in to change notification settings - Fork 83
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
184 additions
and
184 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,80 +1,80 @@ | ||
package hunternif.mc.atlas.item; | ||
|
||
import java.util.ArrayList; | ||
import java.util.Collection; | ||
|
||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.TypedActionResult; | ||
import net.minecraft.world.World; | ||
import hunternif.mc.atlas.AntiqueAtlasMod; | ||
import hunternif.mc.atlas.core.AtlasData; | ||
import hunternif.mc.atlas.core.TileInfo; | ||
import hunternif.mc.atlas.marker.MarkersData; | ||
import hunternif.mc.atlas.network.PacketDispatcher; | ||
import hunternif.mc.atlas.network.client.DimensionUpdatePacket; | ||
|
||
public class ItemAtlas extends Item { | ||
static final String WORLD_ATLAS_DATA_ID = "aAtlas"; | ||
|
||
public ItemAtlas(Item.Settings settings) { | ||
super(settings); | ||
} | ||
|
||
public int getAtlasID(ItemStack stack) { | ||
return stack.getOrCreateTag().getInt("atlasID"); | ||
} | ||
|
||
/* @Override | ||
public String i(ItemStack stack) { | ||
return super.XX_1_13_i_XX(stack) + " #" + getAtlasID(stack); | ||
} */ | ||
|
||
@Override | ||
public TypedActionResult<ItemStack> use(World world, PlayerEntity playerIn, | ||
Hand hand) { | ||
ItemStack stack = playerIn.getStackInHand(hand); | ||
|
||
if (world.isClient) { | ||
AntiqueAtlasMod.proxy.openAtlasGUI(stack); | ||
} | ||
|
||
return new TypedActionResult<>(ActionResult.SUCCESS, stack); | ||
} | ||
|
||
@Override | ||
public void onEntityTick(ItemStack stack, World world, Entity entity, int slot, boolean isEquipped) { | ||
AtlasData data = AntiqueAtlasMod.atlasData.getAtlasData(stack, world); | ||
if (data == null || !(entity instanceof PlayerEntity)) return; | ||
|
||
int atlasId = ((ItemAtlas) stack.getItem()).getAtlasID(stack); | ||
|
||
// On the first run send the map from the server to the client: | ||
PlayerEntity player = (PlayerEntity) entity; | ||
if (!world.isClient && !data.isSyncedOnPlayer(player) && !data.isEmpty()) { | ||
data.syncOnPlayer(atlasId, player); | ||
} | ||
|
||
// Same thing with the local markers: | ||
MarkersData markers = AntiqueAtlasMod.markersData.getMarkersData(stack, world); | ||
if (!world.isClient && !markers.isSyncedOnPlayer(player) && !markers.isEmpty()) { | ||
markers.syncOnPlayer(atlasId, player); | ||
} | ||
|
||
// Updating map around player | ||
Collection<TileInfo> newTiles = data.updateMapAroundPlayer(player); | ||
|
||
if (!world.isClient) { | ||
if (!newTiles.isEmpty()) { | ||
DimensionUpdatePacket packet = new DimensionUpdatePacket(atlasId, player.dimension, newTiles); | ||
PacketDispatcher.sendToAll(((ServerWorld) world).getServer(), packet); | ||
} | ||
} | ||
} | ||
|
||
} | ||
package hunternif.mc.atlas.item; | ||
|
||
import java.util.Collection; | ||
|
||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.TypedActionResult; | ||
import net.minecraft.world.World; | ||
import hunternif.mc.atlas.AntiqueAtlasMod; | ||
import hunternif.mc.atlas.core.AtlasData; | ||
import hunternif.mc.atlas.core.TileInfo; | ||
import hunternif.mc.atlas.marker.MarkersData; | ||
import hunternif.mc.atlas.network.PacketDispatcher; | ||
import hunternif.mc.atlas.network.client.DimensionUpdatePacket; | ||
|
||
public class ItemAtlas extends Item { | ||
static final String WORLD_ATLAS_DATA_ID = "aAtlas"; | ||
|
||
public ItemAtlas(Item.Settings settings) { | ||
super(settings); | ||
} | ||
|
||
public int getAtlasID(ItemStack stack) { | ||
return stack.getOrCreateTag().getInt("atlasID"); | ||
} | ||
|
||
@Override | ||
public Text getName(ItemStack stack) { | ||
return super.getName(stack).append(" #" + getAtlasID(stack)); | ||
} | ||
|
||
@Override | ||
public TypedActionResult<ItemStack> use(World world, PlayerEntity playerIn, | ||
Hand hand) { | ||
ItemStack stack = playerIn.getStackInHand(hand); | ||
|
||
if (world.isClient) { | ||
AntiqueAtlasMod.proxy.openAtlasGUI(stack); | ||
} | ||
|
||
return new TypedActionResult<>(ActionResult.SUCCESS, stack); | ||
} | ||
|
||
@Override | ||
public void inventoryTick(ItemStack stack, World world, Entity entity, int slot, boolean isEquipped) { | ||
AtlasData data = AntiqueAtlasMod.atlasData.getAtlasData(stack, world); | ||
if (data == null || !(entity instanceof PlayerEntity)) return; | ||
|
||
int atlasId = ((ItemAtlas) stack.getItem()).getAtlasID(stack); | ||
|
||
// On the first run send the map from the server to the client: | ||
PlayerEntity player = (PlayerEntity) entity; | ||
if (!world.isClient && !data.isSyncedOnPlayer(player) && !data.isEmpty()) { | ||
data.syncOnPlayer(atlasId, player); | ||
} | ||
|
||
// Same thing with the local markers: | ||
MarkersData markers = AntiqueAtlasMod.markersData.getMarkersData(stack, world); | ||
if (!world.isClient && !markers.isSyncedOnPlayer(player) && !markers.isEmpty()) { | ||
markers.syncOnPlayer(atlasId, player); | ||
} | ||
|
||
// Updating map around player | ||
Collection<TileInfo> newTiles = data.updateMapAroundPlayer(player); | ||
|
||
if (!world.isClient) { | ||
if (!newTiles.isEmpty()) { | ||
DimensionUpdatePacket packet = new DimensionUpdatePacket(atlasId, player.dimension, newTiles); | ||
PacketDispatcher.sendToAll(((ServerWorld) world).getServer(), packet); | ||
} | ||
} | ||
} | ||
|
||
} |
110 changes: 55 additions & 55 deletions
110
src/main/java/hunternif/mc/atlas/item/ItemEmptyAtlas.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,55 +1,55 @@ | ||
package hunternif.mc.atlas.item; | ||
|
||
import hunternif.mc.atlas.AntiqueAtlasMod; | ||
import hunternif.mc.atlas.RegistrarAntiqueAtlas; | ||
import hunternif.mc.atlas.SettingsConfig; | ||
import hunternif.mc.atlas.core.AtlasData; | ||
import hunternif.mc.atlas.marker.MarkersData; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemGroup; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.TypedActionResult; | ||
import net.minecraft.world.World; | ||
|
||
public class ItemEmptyAtlas extends Item { | ||
public ItemEmptyAtlas(Item.Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, | ||
Hand hand) { | ||
ItemStack stack = player.getStackInHand(hand); | ||
if (world.isClient) | ||
return new TypedActionResult<>(ActionResult.SUCCESS, stack); | ||
|
||
int atlasID = AntiqueAtlasMod.getGlobalAtlasData(world).getNextAtlasId(); | ||
ItemStack atlasStack = new ItemStack(RegistrarAntiqueAtlas.ATLAS); | ||
|
||
atlasStack.getOrCreateTag().putInt("atlasID", atlasID); | ||
|
||
AtlasData atlasData = AntiqueAtlasMod.atlasData.getAtlasData(atlasID, world); | ||
atlasData.getDimensionData(player.dimension).setBrowsingPosition( | ||
(int)Math.round(-player.x * SettingsConfig.userInterface.defaultScale), | ||
(int)Math.round(-player.z * SettingsConfig.userInterface.defaultScale), | ||
SettingsConfig.userInterface.defaultScale); | ||
atlasData.markDirty(); | ||
|
||
MarkersData markersData = AntiqueAtlasMod.markersData.getMarkersData(atlasID, world); | ||
markersData.markDirty(); | ||
|
||
stack.subtractAmount(1); | ||
if (stack.isEmpty()) { | ||
return new TypedActionResult<>(ActionResult.SUCCESS, atlasStack); | ||
} else { | ||
if (!player.inventory.insertStack(atlasStack.copy())) { | ||
player.dropItem(atlasStack, true); | ||
} | ||
|
||
return new TypedActionResult<>(ActionResult.SUCCESS, stack); | ||
} | ||
} | ||
} | ||
package hunternif.mc.atlas.item; | ||
|
||
import hunternif.mc.atlas.AntiqueAtlasMod; | ||
import hunternif.mc.atlas.RegistrarAntiqueAtlas; | ||
import hunternif.mc.atlas.SettingsConfig; | ||
import hunternif.mc.atlas.core.AtlasData; | ||
import hunternif.mc.atlas.marker.MarkersData; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemGroup; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.TypedActionResult; | ||
import net.minecraft.world.World; | ||
|
||
public class ItemEmptyAtlas extends Item { | ||
public ItemEmptyAtlas(Item.Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
public TypedActionResult<ItemStack> use(World world, PlayerEntity player, | ||
Hand hand) { | ||
ItemStack stack = player.getStackInHand(hand); | ||
if (world.isClient) | ||
return new TypedActionResult<>(ActionResult.SUCCESS, stack); | ||
|
||
int atlasID = AntiqueAtlasMod.getGlobalAtlasData(world).getNextAtlasId(); | ||
ItemStack atlasStack = new ItemStack(RegistrarAntiqueAtlas.ATLAS); | ||
|
||
atlasStack.getOrCreateTag().putInt("atlasID", atlasID); | ||
|
||
AtlasData atlasData = AntiqueAtlasMod.atlasData.getAtlasData(atlasID, world); | ||
atlasData.getDimensionData(player.dimension).setBrowsingPosition( | ||
(int)Math.round(-player.x * SettingsConfig.userInterface.defaultScale), | ||
(int)Math.round(-player.z * SettingsConfig.userInterface.defaultScale), | ||
SettingsConfig.userInterface.defaultScale); | ||
atlasData.markDirty(); | ||
|
||
MarkersData markersData = AntiqueAtlasMod.markersData.getMarkersData(atlasID, world); | ||
markersData.markDirty(); | ||
|
||
stack.decrement(1); | ||
if (stack.isEmpty()) { | ||
return new TypedActionResult<>(ActionResult.SUCCESS, atlasStack); | ||
} else { | ||
if (!player.inventory.insertStack(atlasStack.copy())) { | ||
player.dropItem(atlasStack, true); | ||
} | ||
|
||
return new TypedActionResult<>(ActionResult.SUCCESS, stack); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.