Skip to content

Commit

Permalink
Minor changes / cleanup
Browse files Browse the repository at this point in the history
Changed config comments.
Removed reflection access for progressMap in MixinAdvancementProgress.
Removed MixinEntityVillager as it's no longer valid for 1.12.2.
  • Loading branch information
LXGaming committed May 17, 2018
1 parent d8af47a commit c1c0ffa
Show file tree
Hide file tree
Showing 10 changed files with 35 additions and 101 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ targetCompatibility = 1.8

group = "io.github.lxgaming"
archivesBaseName = "Sledgehammer"
version = "1.1.0-1.12.2"
version = "1.1.1-1.12.2"

minecraft {
version = "1.12.2-14.23.3.2655"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ private void register() {
getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.core.advancements.MixinAdvancementProgress", MixinCategory::isAdvancementProgress);
getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.core.block.MixinBlockGrass", MixinCategory::isBlockGrass);
getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.core.block.MixinBlockIce", MixinCategory::isBlockIce);
getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.core.entity.passive.MixinEntityVillager", MixinCategory::isEntityVillager);
getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.core.server.MixinDedicatedServer", (module) -> true);

getMixinMappings().put("io.github.lxgaming.sledgehammer.mixin.forge.common.MixinForgeHooks", MixinCategory::isAdvancementStacktrace);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,25 +22,22 @@
@ConfigSerializable
public class MixinCategory {

@Setting(value = "advancement-progress", comment = "Fixes Advancement Progress")
@Setting(value = "advancement-progress", comment = "Fixes https://github.com/SpongePowered/SpongeCommon/issues/1904")
private boolean advancementProgress = false;

@Setting(value = "advancement-stacktrace", comment = "Catches the stacktrace thrown by the AdvancementManager")
@Setting(value = "advancement-stacktrace", comment = "Prints a single message instead of a stacktrace for advancement errors")
private boolean advancementStacktrace = false;

@Setting(value = "block-grass", comment = "Prevents BlockGrass turning into BlockDirt")
@Setting(value = "block-grass", comment = "Prevents Grass turning into Dirt")
private boolean blockGrass = false;

@Setting(value = "block-ice", comment = "Prevents BlockIce turning into Water")
@Setting(value = "block-ice", comment = "Prevents Ice turning into Water")
private boolean blockIce = false;

@Setting(value = "ceremony-rain", comment = "Disables weather changing from Totemic")
@Setting(value = "ceremony-rain", comment = "Prevents Totemic from changing the weather")
private boolean ceremonyRain = false;

@Setting(value = "entity-villager", comment = "Prevents villagers crashing the server")
private boolean entityVillager = false;

@Setting(value = "traveling-merchant", comment = "Fixes Traveling Merchants from PrimitiveMobs")
@Setting(value = "traveling-merchant", comment = "Fixes https://github.com/Daveyx0/PrimitiveMobs/issues/59")
private boolean travelingMerchant = false;

public boolean isAdvancementProgress() {
Expand All @@ -63,10 +60,6 @@ public boolean isCeremonyRain() {
return ceremonyRain;
}

public boolean isEntityVillager() {
return entityVillager;
}

public boolean isTravelingMerchant() {
return travelingMerchant;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,35 +18,31 @@

import io.github.lxgaming.sledgehammer.Sledgehammer;
import net.minecraft.advancements.AdvancementProgress;
import org.spongepowered.api.advancement.criteria.AdvancementCriterion;
import org.spongepowered.api.entity.living.player.Player;
import org.spongepowered.asm.mixin.Dynamic;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import org.spongepowered.common.advancement.ICriterionProgress;
import org.spongepowered.common.interfaces.advancement.IMixinAdvancementProgress;
import org.spongepowered.common.interfaces.advancement.IMixinPlayerAdvancements;

import java.lang.reflect.Field;
import java.util.Map;

@Mixin(value = AdvancementProgress.class, priority = 1337)
public abstract class MixinAdvancementProgress implements org.spongepowered.api.advancement.AdvancementProgress, IMixinAdvancementProgress {

@Dynamic(mixin = org.spongepowered.common.mixin.core.advancement.MixinAdvancementProgress.class)
private Map<AdvancementCriterion, ICriterionProgress> progressMap;

@Inject(method = "isDone", at = @At(value = "HEAD"))
private void onIsDone(CallbackInfoReturnable<Boolean> callbackInfoReturnable) {
if (!get(getAdvancement().getCriterion()).isPresent()) {
this.progressMap = null;
Player player = ((IMixinPlayerAdvancements) getPlayerAdvancements()).getPlayer();
Sledgehammer.getInstance().debugMessage("Resetting {} for {} ({})", getAdvancement().getCriterion().getName(), player.getName(), player.getUniqueId());
resetProgressMap();
}
}

private void resetProgressMap() {
try {
Field field = this.getClass().getDeclaredField("progressMap");
field.setAccessible(true);
field.set(this, null);
} catch (Exception ex) {
Sledgehammer.getInstance().getLogger().error("Encountered an error processing {}::resetProgressMap", getClass().getSimpleName(), ex);
Sledgehammer.getInstance().debugMessage("Reset {} for {} ({})", getAdvancement().getCriterion().getName(), player.getName(), player.getUniqueId());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@
@Mixin(value = BlockGrass.class, priority = 1337)
public abstract class MixinBlockGrass {

@Inject(method = "updateTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;)Z", ordinal = 0), cancellable = true)
@Inject(method = "updateTick",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/world/World;setBlockState(Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/state/IBlockState;)Z",
ordinal = 0
),
cancellable = true
)
private void onUpdateTick(World world, BlockPos blockPos, IBlockState blockState, Random random, CallbackInfo callbackInfo) {
callbackInfo.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,13 @@
@Mixin(value = BlockIce.class, priority = 1337)
public abstract class MixinBlockIce {

@Inject(method = "updateTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockIce;turnIntoWater(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V", ordinal = 0), cancellable = true)
@Inject(method = "updateTick",
at = @At(value = "INVOKE",
target = "Lnet/minecraft/block/BlockIce;turnIntoWater(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;)V",
ordinal = 0
),
cancellable = true
)
private void onUpdateTick(World world, BlockPos blockPos, IBlockState blockState, Random random, CallbackInfo callbackInfo) {
callbackInfo.cancel();
}
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -65,9 +65,6 @@ private void onProcessInteract(EntityPlayer player, EnumHand hand, CallbackInfoR
populateTravelingMerchant();
}

/**
* Fixes https://github.com/Daveyx0/PrimitiveMobs/issues/59
*/
@SuppressWarnings("deprecation")
private void populateTravelingMerchant() {
if (!StringUtils.equals(((Entity) this).getType().getId(), "primitivemobs:travelingmerchant") || (this.buyingList != null && !this.buyingList.isEmpty())) {
Expand All @@ -77,6 +74,10 @@ private void populateTravelingMerchant() {
VillagerRegistry.VillagerProfession villagerProfession = VillagerRegistry.getById(((SpongeProfession) getProfession()).type);
VillagerRegistry.VillagerCareer villagerCareer = villagerProfession.getCareer(this.careerId - 1);
List<EntityVillager.ITradeList> trades = villagerCareer.getTrades(this.careerLevel - 1);
if (trades == null) {
Sledgehammer.getInstance().getLogger().warn("Failed to populate TravelingMerchant");
return;
}

for (EntityVillager.ITradeList trade : trades) {
trade.addMerchantRecipe(((IMerchant) this), this.buyingList, this.rand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class Reference {

public static final String PLUGIN_ID = "sledgehammer";
public static final String PLUGIN_NAME = "Sledgehammer";
public static final String PLUGIN_VERSION = "1.1.0-1.12.2";
public static final String PLUGIN_VERSION = "1.1.1-1.12.2";
public static final String DESCRIPTION = "Smashes the stupid out of the server.";
public static final String AUTHORS = "LX_Gaming";
public static final String SOURCE = "https://github.com/LXGaming/Sledgehammer/";
Expand Down
1 change: 0 additions & 1 deletion src/main/resources/mixins.sledgehammer.core.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
"advancements.MixinAdvancementProgress",
"block.MixinBlockGrass",
"block.MixinBlockIce",
"entity.passive.MixinEntityVillager",
"server.MixinDedicatedServer"
],
"injectors": {
Expand Down

0 comments on commit c1c0ffa

Please sign in to comment.