Skip to content

Commit

Permalink
Fixed incompatibilities with DraconicEvolution, Mekanism, and a few o…
Browse files Browse the repository at this point in the history
…ther mods

 - Fixes #152
 - Fixes #151
  • Loading branch information
Runemoro committed Jan 4, 2019
1 parent eae024a commit 40d91ca
Show file tree
Hide file tree
Showing 6 changed files with 39 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ public static NumericalBlockState fromPropertyValueMap(BlockStateContainer conta
}

public static <T extends Comparable<T>> void makePropertyInfo(IProperty<T> property) {
if (propertyWidths.containsKey(property)) return;
if (propertyWidths.containsKey(property)) {
return;
}

Collection<T> allowedValues = property.getAllowedValues();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public abstract class MixinBlockStateContainer implements IPatchedBlockStateCont
// @formatter:on

@SuppressWarnings("EqualsBetweenInconvertibleTypes") // mixin
private boolean isNumerical = getClass().equals(BlockStateContainer.class) || getClass().equals(ExtendedBlockState.class);
protected
boolean isNumerical = getClass().equals(BlockStateContainer.class) || getClass().equals(ExtendedBlockState.class);
private final ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties;
private final Map<IProperty<?>, Integer> propertyOffsets = new HashMap<>();
protected ImmutableList<IBlockState> validStatesCache = null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
import net.minecraftforge.common.property.IUnlistedProperty;
import org.dimdev.vanillafix.blockstates.NumericalExtendedBlockState;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Overwrite;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import javax.annotation.Nullable;
import java.util.Optional;
Expand All @@ -20,11 +22,11 @@ public MixinExtendedBlockState(Block block, IProperty<?>[] properties, Immutable
super(block, properties, unlistedProperties);
}

@Override
@Overwrite(remap = false)
@SuppressWarnings("OverwriteModifiers" /* (no @NonNull) */)
protected BlockStateContainer.StateImplementation createState(Block block, ImmutableMap<IProperty<?>, Comparable<?>> properties, @Nullable ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties) {
return null;
@Inject(method = "createState", remap = false, at = @At("HEAD"), cancellable = true)
protected void overrideCreateState(Block block, ImmutableMap<IProperty<?>, Comparable<?>> properties, @Nullable ImmutableMap<IUnlistedProperty<?>, Optional<?>> unlistedProperties, CallbackInfoReturnable<BlockStateContainer.StateImplementation> cir) {
if (isNumerical) {
cir.setReturnValue(null);
}
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.dimdev.vanillafix.blockstates.mixins;

import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyHelper;
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;

@Mixin(PropertyHelper.class)
public abstract class MixinPropertyHelper<T extends Comparable<T>> implements IProperty<T> {
/**
* Fix mods using duplicate property names.
*/
@Inject(method = "equals", at = @At("RETURN"), cancellable = true)
public void overrideEquals(Object obj, CallbackInfoReturnable<Boolean> cir) {
if (cir.getReturnValue() && obj instanceof PropertyHelper) {
if (!getClass().getName().startsWith("net.minecraft") && !getAllowedValues().equals(((PropertyHelper<?>) obj).getAllowedValues())) {
cir.setReturnValue(false);
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public static void postEventAllowingErrors(Event event) {
try {
Field busIDField = EventBus.class.getDeclaredField("busID");
busIDField.setAccessible(true);
busID = (int) busIDField.get(MinecraftForge.EVENT_BUS);
busID = busIDField.getInt(MinecraftForge.EVENT_BUS);
} catch (ReflectiveOperationException e) {
throw new RuntimeException(e);
}
Expand Down
3 changes: 2 additions & 1 deletion src/main/resources/mixins.vanillafix.blockstates.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"compatibilityLevel": "JAVA_8",
"mixins": [
"MixinBlockStateContainer",
"MixinExtendedBlockState"
"MixinExtendedBlockState",
"MixinPropertyHelper"
],
"client": [
],
Expand Down

0 comments on commit 40d91ca

Please sign in to comment.