Skip to content

Commit

Permalink
bugfixes and 0.1.1
Browse files Browse the repository at this point in the history
- fix PinLib add/remove methods don't log like FilledMapItem.useOnBlock()
- replace dependence on Nameable.getDisplayName() with a custom method for use with BlockState and BlockEntity(s).
  • Loading branch information
rokoblox committed Jul 26, 2022
1 parent 2f2ea31 commit 1f329c1
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 16 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ minecraft_version=1.19
yarn_mappings=1.19+build.4
loader_version=0.14.8
# Mod Properties
mod_version=0.1.0+mc1.19
mod_version=0.1.1+mc1.19
maven_group=com.rokoblox
archives_base_name=pinlib
# Dependencies
Expand Down
10 changes: 8 additions & 2 deletions src/main/java/com/rokoblox/pinlib/PinLib.java
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,10 @@ else if (markerType != null)
mapMarker = new MapMarkerEntity(markerType, pos, displayName);
if (mapMarker == null)
return null;
return ((MapStateAccessor) mapState).addMapMarker(world, pos, mapMarker) ? mapMarker : null;
boolean success = ((MapStateAccessor) mapState).addMapMarker(world, pos, mapMarker);
if (success)
PinLib.LOGGER.info("Added map marker with id [{}] at: [{}]", mapMarker.getId().toString(), pos.toShortString());
return success ? mapMarker : null;
}

/**
Expand Down Expand Up @@ -122,7 +125,10 @@ public static MapMarkerEntity tryAddMapMarker(ItemStack stack, World world, Bloc
* @return Provided MapState
*/
public static boolean removeMapMarker(MapState mapState, int x, int z, @Nullable MapMarker markerType) {
return ((MapStateAccessor) mapState).removeMapMarker(null, x, z, false, markerType) != null;
MapMarkerEntity removeMapMarker = ((MapStateAccessor) mapState).removeMapMarker(null, x, z, false, markerType);
if (removeMapMarker != null)
PinLib.LOGGER.info("Removed map marker with id [{}] at: [{}]", removeMapMarker.getId(), removeMapMarker.getPos().toShortString());
return removeMapMarker != null;
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import com.rokoblox.pinlib.mapmarker.MapMarker;
import com.rokoblox.pinlib.mapmarker.MapMarkerEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import org.jetbrains.annotations.Nullable;

Expand All @@ -12,7 +12,7 @@
public interface MapStateAccessor {
boolean addMapMarker(WorldAccess world, BlockPos pos, MapMarkerEntity mapMarker);

@Nullable MapMarkerEntity removeMapMarker(@Nullable BlockView world, int x, int z, boolean keepStatic, @Nullable MapMarker markerType);
@Nullable MapMarkerEntity removeMapMarker(@Nullable World world, int x, int z, boolean keepStatic, @Nullable MapMarker markerType);

@Nullable MapMarkerEntity getMapMarker(int x, int z);

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package com.rokoblox.pinlib.mapmarker;

import com.rokoblox.pinlib.PinLib;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;

/**
* A block that uses PinLib's markers.
Expand All @@ -11,7 +14,12 @@ public interface MapMarkedBlock {
default MapMarker getCustomMarker() {
return PinLib.getDefaultMarker();
}

default long getMarkerColor() {
return 0xFFFFFFFFL;
}

default Text getDisplayName(BlockView world, BlockPos pos) {
return null;
}
}
11 changes: 4 additions & 7 deletions src/main/java/com/rokoblox/pinlib/mapmarker/MapMarkerEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,8 @@
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.Nameable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;

import java.util.Objects;
Expand Down Expand Up @@ -50,13 +49,11 @@ public MapMarkerEntity(MapMarker type, BlockPos pos, @Nullable Text displayName)
}

@Nullable
public static MapMarkerEntity fromWorldBlock(BlockView blockView, BlockPos blockPos) {
BlockState blockState = blockView.getBlockState(blockPos);
public static MapMarkerEntity fromWorldBlock(World world, BlockPos blockPos) {
BlockState blockState = world.getBlockState(blockPos);
if (blockState.getBlock() instanceof MapMarkedBlock mapMarkedBlock) {
MapMarker type = mapMarkedBlock.getCustomMarker();
Text text = null;
if (mapMarkedBlock instanceof Nameable namedMapMarkedBlock)
text = namedMapMarkedBlock.getDisplayName();
Text text = mapMarkedBlock.getDisplayName(world, blockPos);
return new MapMarkerEntity(type, blockPos, text, mapMarkedBlock.getMarkerColor());
}
return null;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/rokoblox/pinlib/mixin/MapStateMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.minecraft.nbt.NbtList;
import net.minecraft.text.Text;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import org.jetbrains.annotations.Nullable;
import org.spongepowered.asm.mixin.Mixin;
Expand Down Expand Up @@ -105,7 +105,7 @@ public boolean addMapMarker(WorldAccess world, BlockPos pos, MapMarkerEntity map
return false;
}

public @Nullable MapMarkerEntity removeMapMarker(@Nullable BlockView world, int x, int z, boolean keepStatic, @Nullable MapMarker markerType) {
public @Nullable MapMarkerEntity removeMapMarker(@Nullable World world, int x, int z, boolean keepStatic, @Nullable MapMarker markerType) {
Iterator<MapMarkerEntity> iterator = this.pinlib$customMarkerEntities.values().iterator();
while (iterator.hasNext()) {
MapMarkerEntity mapMarker = iterator.next();
Expand Down
6 changes: 4 additions & 2 deletions srcdev/TestingClass.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.Nameable;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.BlockView;

public class TestingClass {

Expand All @@ -25,7 +27,7 @@ public static void init() {
}
}

class TestBlock extends Block implements MapMarkedBlock, Nameable {
class TestBlock extends Block implements MapMarkedBlock {
public TestBlock(Settings settings) {
super(settings);
}
Expand All @@ -42,7 +44,7 @@ public long getMarkerColor() {
}

@Override
public Text getDisplayName() {
public Text getDisplayName(BlockView world, BlockPos pos) {
// It's a good idea to not leave style as null since the loaded
// map markers from NBT always load with an empty style, thus
// the game thinks the loaded display name and the one here
Expand Down

0 comments on commit 1f329c1

Please sign in to comment.