mirror of
https://github.com/ViaVersion/ViaFabricPlus.git
synced 2025-01-25 22:11:32 +01:00
Move 1.19.4 material data to json file
This commit is contained in:
parent
b41474f257
commit
57564c8488
File diff suppressed because it is too large
Load Diff
@ -20,8 +20,8 @@
|
||||
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import de.florianmichael.viafabricplus.fixes.data.Material1_19_4;
|
||||
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
|
||||
import de.florianmichael.viafabricplus.protocoltranslator.impl.ViaFabricPlusMappingDataLoader;
|
||||
import net.minecraft.block.*;
|
||||
import net.minecraft.fluid.FlowableFluid;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
@ -37,7 +37,8 @@ public abstract class MixinFlowableFluid {
|
||||
@Redirect(method = "isFlowBlocked", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/BlockState;isSideSolidFullSquare(Lnet/minecraft/world/BlockView;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/util/math/Direction;)Z"))
|
||||
private boolean modifyIsSolidBlock(BlockState instance, BlockView blockView, BlockPos blockPos, Direction direction) {
|
||||
if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_11_1)) {
|
||||
return Material1_19_4.getMaterial(instance).solid();
|
||||
final ViaFabricPlusMappingDataLoader.Material material = ViaFabricPlusMappingDataLoader.MATERIALS.get(ViaFabricPlusMappingDataLoader.getBlockMaterial(instance.getBlock()));
|
||||
return material.solid();
|
||||
} else if (ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_13_2)) {
|
||||
final Block block = instance.getBlock();
|
||||
if (block instanceof ShulkerBoxBlock || block instanceof LeavesBlock || block instanceof TrapdoorBlock ||
|
||||
|
@ -20,8 +20,8 @@
|
||||
package de.florianmichael.viafabricplus.injection.mixin.fixes.minecraft.item;
|
||||
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import de.florianmichael.viafabricplus.fixes.data.Material1_19_4;
|
||||
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
|
||||
import de.florianmichael.viafabricplus.protocoltranslator.impl.ViaFabricPlusMappingDataLoader;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.Blocks;
|
||||
import net.minecraft.entity.player.PlayerEntity;
|
||||
@ -73,7 +73,7 @@ public abstract class MixinItemPlacementContext extends ItemUsageContext {
|
||||
@Inject(method = "canPlace", at = @At("RETURN"), cancellable = true)
|
||||
private void canPlace1_12_2(CallbackInfoReturnable<Boolean> cir) {
|
||||
if (!cir.getReturnValueZ() && ProtocolTranslator.getTargetVersion().olderThanOrEqualTo(ProtocolVersion.v1_12_2)) {
|
||||
cir.setReturnValue(Material1_19_4.getMaterial(this.getWorld().getBlockState(this.getBlockPos())).equals(Material1_19_4.DECORATION) && Block.getBlockFromItem(this.getStack().getItem()).equals(Blocks.ANVIL));
|
||||
cir.setReturnValue(ViaFabricPlusMappingDataLoader.getBlockMaterial(this.getWorld().getBlockState(this.getBlockPos()).getBlock()).equals("decoration") && Block.getBlockFromItem(this.getStack().getItem()).equals(Blocks.ANVIL));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,6 +30,8 @@ import com.viaversion.viaversion.api.minecraft.item.data.ToolProperties;
|
||||
import com.viaversion.viaversion.api.minecraft.item.data.ToolRule;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.api.type.Type;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.IntOpenHashSet;
|
||||
import com.viaversion.viaversion.libs.fastutil.ints.IntSet;
|
||||
import com.viaversion.viaversion.libs.gson.JsonArray;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
@ -118,12 +120,12 @@ public abstract class MixinBlockItemPacketRewriter1_20_5 extends ItemRewriter<Cl
|
||||
final String item = toolComponentObject.get("item").getAsString();
|
||||
final float defaultMiningSpeed = toolComponentObject.get("default_mining_speed").getAsFloat();
|
||||
final int damagePerBlock = toolComponentObject.get("damage_per_block").getAsInt();
|
||||
final int[] suitableFor = this.blockJsonArrayToIds(toolComponentObject.getAsJsonArray("suitable_for"));
|
||||
final int[] suitableFor = this.blockJsonArrayToIds(version, toolComponentObject.getAsJsonArray("suitable_for"));
|
||||
final List<ToolRule> toolRules = new ArrayList<>();
|
||||
final JsonArray miningSpeeds = toolComponentObject.getAsJsonArray("mining_speeds");
|
||||
for (JsonElement miningSpeed : miningSpeeds) {
|
||||
final JsonObject miningSpeedObject = miningSpeed.getAsJsonObject();
|
||||
final int[] blocks = this.blockJsonArrayToIds(miningSpeedObject.getAsJsonArray("blocks"));
|
||||
final int[] blocks = this.blockJsonArrayToIds(version, miningSpeedObject.getAsJsonArray("blocks"));
|
||||
final float speed = miningSpeedObject.get("speed").getAsFloat();
|
||||
toolRules.add(new ToolRule(HolderSet.of(blocks), speed, null));
|
||||
}
|
||||
@ -174,13 +176,25 @@ public abstract class MixinBlockItemPacketRewriter1_20_5 extends ItemRewriter<Cl
|
||||
}
|
||||
|
||||
@Unique
|
||||
private int[] blockJsonArrayToIds(final JsonArray jsonArray) {
|
||||
final int[] ids = new int[jsonArray.size()];
|
||||
int i = 0;
|
||||
private int[] blockJsonArrayToIds(final ProtocolVersion protocolVersion, final JsonArray jsonArray) {
|
||||
final IntSet ids = new IntOpenHashSet();
|
||||
for (final JsonElement element : jsonArray) {
|
||||
ids[i++] = this.protocol.getMappingData().blockId(element.getAsString());
|
||||
final String name = element.getAsString();
|
||||
if (name.startsWith("#")) { // Material name
|
||||
final String material = name.substring(1);
|
||||
for (Map.Entry<String, Map<ProtocolVersion, String>> entry : ViaFabricPlusMappingDataLoader.BLOCK_MATERIALS.entrySet()) {
|
||||
for (Map.Entry<ProtocolVersion, String> materialEntry : entry.getValue().entrySet()) {
|
||||
if (protocolVersion.olderThanOrEqualTo(materialEntry.getKey()) && materialEntry.getValue().equals(material)) {
|
||||
ids.add(this.protocol.getMappingData().blockId(entry.getKey()));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else { // Block name
|
||||
ids.add(this.protocol.getMappingData().blockId(element.getAsString()));
|
||||
}
|
||||
}
|
||||
return ids;
|
||||
return ids.toIntArray();
|
||||
}
|
||||
|
||||
// TODO: Remove again
|
||||
|
@ -20,13 +20,69 @@
|
||||
package de.florianmichael.viafabricplus.protocoltranslator.impl;
|
||||
|
||||
import com.viaversion.viaversion.api.data.MappingDataLoader;
|
||||
import com.viaversion.viaversion.api.protocol.version.ProtocolVersion;
|
||||
import com.viaversion.viaversion.libs.gson.JsonElement;
|
||||
import com.viaversion.viaversion.libs.gson.JsonObject;
|
||||
import de.florianmichael.viafabricplus.protocoltranslator.ProtocolTranslator;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.registry.Registries;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class ViaFabricPlusMappingDataLoader extends MappingDataLoader {
|
||||
|
||||
public static final ViaFabricPlusMappingDataLoader INSTANCE = new ViaFabricPlusMappingDataLoader(ViaFabricPlusMappingDataLoader.class, "assets/viafabricplus/data/");
|
||||
public static final Map<String, Material> MATERIALS = new HashMap<>();
|
||||
public static final Map<String, Map<ProtocolVersion, String>> BLOCK_MATERIALS = new HashMap<>();
|
||||
|
||||
public ViaFabricPlusMappingDataLoader(final Class<?> dataLoaderClass, final String dataPath) {
|
||||
super(dataLoaderClass, dataPath);
|
||||
public static final ViaFabricPlusMappingDataLoader INSTANCE = new ViaFabricPlusMappingDataLoader();
|
||||
|
||||
private ViaFabricPlusMappingDataLoader() {
|
||||
super(ViaFabricPlusMappingDataLoader.class, "assets/viafabricplus/data/");
|
||||
|
||||
final JsonObject materialsData = this.loadData("materials-1.19.4.json");
|
||||
for (Map.Entry<String, JsonElement> entry : materialsData.getAsJsonObject("materials").entrySet()) {
|
||||
final JsonObject materialData = entry.getValue().getAsJsonObject();
|
||||
MATERIALS.put(entry.getKey(), new Material(
|
||||
materialData.get("blocksMovement").getAsBoolean(),
|
||||
materialData.get("burnable").getAsBoolean(),
|
||||
materialData.get("liquid").getAsBoolean(),
|
||||
materialData.get("blocksLight").getAsBoolean(),
|
||||
materialData.get("replaceable").getAsBoolean(),
|
||||
materialData.get("solid").getAsBoolean()
|
||||
));
|
||||
}
|
||||
for (Map.Entry<String, JsonElement> blockEntry : materialsData.getAsJsonObject("blocks").entrySet()) {
|
||||
final Map<ProtocolVersion, String> blockMaterials = new HashMap<>();
|
||||
for (Map.Entry<String, JsonElement> entry : blockEntry.getValue().getAsJsonObject().entrySet()) {
|
||||
blockMaterials.put(ProtocolVersion.getClosest(entry.getKey()), entry.getValue().getAsString());
|
||||
}
|
||||
BLOCK_MATERIALS.put(blockEntry.getKey(), blockMaterials);
|
||||
}
|
||||
}
|
||||
|
||||
public static String getBlockMaterial(final Block block) {
|
||||
return getBlockMaterial(block, ProtocolTranslator.getTargetVersion());
|
||||
}
|
||||
|
||||
public static String getBlockMaterial(final Block block, ProtocolVersion version) {
|
||||
if (version.newerThan(ProtocolVersion.v1_19_4)) {
|
||||
version = ProtocolVersion.v1_19_4;
|
||||
}
|
||||
|
||||
final Map<ProtocolVersion, String> materials = BLOCK_MATERIALS.get(Registries.BLOCK.getId(block).toString());
|
||||
if (materials == null) {
|
||||
return null;
|
||||
}
|
||||
for (Map.Entry<ProtocolVersion, String> materialEntry : materials.entrySet()) {
|
||||
if (version.olderThanOrEqualTo(materialEntry.getKey())) {
|
||||
return materialEntry.getValue();
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public record Material(boolean blocksMovement, boolean burnable, boolean liquid, boolean blocksLight, boolean replaceable, boolean solid) {
|
||||
}
|
||||
|
||||
}
|
||||
|
File diff suppressed because it is too large
Load Diff
3417
src/main/resources/assets/viafabricplus/data/materials-1.19.4.json
Normal file
3417
src/main/resources/assets/viafabricplus/data/materials-1.19.4.json
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user