-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Block module rebase fixes * Fix whether to use neighbour light for Modded blocks * Clean up and fix style * Update test mods * Fix compiling errors * Spotless * Fix compiling errors * PR Feedback
- Loading branch information
1 parent
7a0c24b
commit c89b8a8
Showing
38 changed files
with
893 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
loom { | ||
accessWidenerPath = file("src/main/resources/legacy-fabric-block-api-v1.accesswidener") | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minVersionIncluded=1.8 | ||
maxVersionIncluded=1.12.2 |
69 changes: 69 additions & 0 deletions
69
...1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/BlockStateRemapper.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 |
---|---|---|
@@ -0,0 +1,69 @@ | ||
/* | ||
* Copyright (c) 2020 - 2024 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.legacyfabric.fabric.impl.block.versioned; | ||
|
||
import java.util.Map; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.util.collection.IdList; | ||
|
||
import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; | ||
import net.legacyfabric.fabric.api.registry.v2.event.RegistryRemapCallback; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.holder.FabricRegistryEntry; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.registrable.IdsHolder; | ||
import net.legacyfabric.fabric.api.util.Identifier; | ||
import net.legacyfabric.fabric.api.util.VersionUtils; | ||
import net.legacyfabric.fabric.mixin.block.versioned.BlockAccessor; | ||
|
||
public class BlockStateRemapper implements RegistryRemapCallback<Block> { | ||
private static final boolean hasSpecialCase = VersionUtils.matches(">1.8.9"); | ||
private static final Identifier specialCaseId = new Identifier("tripwire"); | ||
|
||
@Override | ||
public void callback(Map<Integer, FabricRegistryEntry<Block>> changedIdsMap) { | ||
IdsHolder<BlockState> newList = Block.BLOCK_STATES.fabric$new(); | ||
|
||
for (Block block : Block.REGISTRY) { | ||
int blockRawId = RegistryHelper.getRawId(Block.REGISTRY, block); | ||
|
||
if (changedIdsMap.containsKey(blockRawId)) { | ||
blockRawId = changedIdsMap.get(blockRawId).getId(); | ||
} | ||
|
||
Identifier blockId = RegistryHelper.getId(Block.REGISTRY, block); | ||
|
||
if (blockId.equals(specialCaseId) && hasSpecialCase) { | ||
for (int i = 0; i < 15; ++i) { | ||
int blockStateId = blockRawId << 4 | i; | ||
BlockState state = block.stateFromData(i); | ||
|
||
newList.fabric$setValue(state, blockStateId); | ||
} | ||
} else { | ||
for (BlockState state : block.getStateManager().getBlockStates()) { | ||
int blockStateId = blockRawId << 4 | block.getData(state); | ||
|
||
newList.fabric$setValue(state, blockStateId); | ||
} | ||
} | ||
} | ||
|
||
BlockAccessor.setBlockStateList((IdList<BlockState>) newList); | ||
} | ||
} |
89 changes: 89 additions & 0 deletions
89
...1/1.12.2/src/main/java/net/legacyfabric/fabric/impl/block/versioned/EarlyInitializer.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 |
---|---|---|
@@ -0,0 +1,89 @@ | ||
/* | ||
* Copyright (c) 2020 - 2024 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.legacyfabric.fabric.impl.block.versioned; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.SlabBlock; | ||
import net.minecraft.block.StairsBlock; | ||
import net.minecraft.block.material.Material; | ||
import net.minecraft.item.BlockItem; | ||
import net.minecraft.item.Item; | ||
|
||
import net.fabricmc.loader.api.entrypoint.PreLaunchEntrypoint; | ||
|
||
import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; | ||
import net.legacyfabric.fabric.api.registry.v2.RegistryIds; | ||
import net.legacyfabric.fabric.api.registry.v2.event.RegistryInitializedEvent; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.holder.FabricRegistry; | ||
import net.legacyfabric.fabric.api.registry.v2.registry.holder.SyncedFabricRegistry; | ||
import net.legacyfabric.fabric.api.util.Identifier; | ||
import net.legacyfabric.fabric.api.util.VersionUtils; | ||
import net.legacyfabric.fabric.mixin.block.versioned.ItemAccessor; | ||
|
||
public class EarlyInitializer implements PreLaunchEntrypoint { | ||
private static final boolean checkGrass = VersionUtils.matches(">1.8.9"); | ||
@Override | ||
public void onPreLaunch() { | ||
RegistryInitializedEvent.event(RegistryIds.BLOCKS).register(EarlyInitializer::blockRegistryInit); | ||
RegistryInitializedEvent.event(RegistryIds.ITEMS).register(EarlyInitializer::itemRegistryInit); | ||
} | ||
|
||
private static void blockRegistryInit(FabricRegistry<?> holder) { | ||
SyncedFabricRegistry<Block> registry = (SyncedFabricRegistry<Block>) holder; | ||
|
||
registry.fabric$getEntryAddedCallback().register((rawId, id, block) -> { | ||
for (BlockState blockState : block.getStateManager().getBlockStates()) { | ||
int i = rawId << 4 | block.getData(blockState); | ||
Block.BLOCK_STATES.set(blockState, i); | ||
} | ||
}); | ||
|
||
registry.fabric$getRegistryRemapCallback().register(new BlockStateRemapper()); | ||
|
||
registry.fabric$getEntryAddedCallback().register((rawId, id, block) -> { | ||
if (block.material == Material.AIR) { | ||
block.useNeighbourLight = false; | ||
} else { | ||
boolean useNeighbourLight = false; | ||
boolean isStairs = block instanceof StairsBlock; | ||
boolean isSlab = block instanceof SlabBlock; | ||
boolean isMissingTop = block == RegistryHelper.getValue(Item.REGISTRY, new Identifier("farmland")) | ||
|| (checkGrass && block == RegistryHelper.getValue(Item.REGISTRY, new Identifier("grass_path"))); | ||
boolean isTranslucent = block.transluscent; | ||
boolean isNotOpaque = block.opacity == 0; | ||
|
||
if (isStairs || isSlab || isMissingTop || isTranslucent || isNotOpaque) { | ||
useNeighbourLight = true; | ||
} | ||
|
||
block.useNeighbourLight = useNeighbourLight; | ||
} | ||
}); | ||
} | ||
|
||
private static void itemRegistryInit(FabricRegistry<?> holder) { | ||
SyncedFabricRegistry<Item> registry = (SyncedFabricRegistry<Item>) holder; | ||
|
||
registry.fabric$getEntryAddedCallback().register((rawId, id, item) -> { | ||
if (item instanceof BlockItem) { | ||
ItemAccessor.getBlockItemsMap().put(((BlockItem) item).getBlock(), item); | ||
} | ||
}); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockAccessor.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 |
---|---|---|
@@ -0,0 +1,32 @@ | ||
/* | ||
* Copyright (c) 2020 - 2024 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.legacyfabric.fabric.mixin.block.versioned; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.util.collection.IdList; | ||
|
||
@Mixin(Block.class) | ||
public interface BlockAccessor { | ||
@Accessor("BLOCK_STATES") | ||
static void setBlockStateList(IdList<BlockState> blockStates) { | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
...api-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/BlockMixin.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 |
---|---|---|
@@ -0,0 +1,44 @@ | ||
/* | ||
* Copyright (c) 2020 - 2024 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.legacyfabric.fabric.mixin.block.versioned; | ||
|
||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.registry.BiDefaultedRegistry; | ||
|
||
import net.legacyfabric.fabric.api.registry.v2.RegistryHelper; | ||
import net.legacyfabric.fabric.api.registry.v2.RegistryIds; | ||
|
||
@Mixin(Block.class) | ||
public class BlockMixin { | ||
@Shadow | ||
@Final | ||
public static BiDefaultedRegistry<Identifier, Block> REGISTRY; | ||
|
||
@Inject(method = "setup", at = @At("RETURN")) | ||
private static void registerRegistry(CallbackInfo ci) { | ||
RegistryHelper.addRegistry(RegistryIds.BLOCKS, REGISTRY); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...i-v1/1.12.2/src/main/java/net/legacyfabric/fabric/mixin/block/versioned/ItemAccessor.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 |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
* Copyright (c) 2020 - 2024 Legacy Fabric | ||
* Copyright (c) 2016 - 2022 FabricMC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package net.legacyfabric.fabric.mixin.block.versioned; | ||
|
||
import java.util.Map; | ||
|
||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.item.Item; | ||
|
||
@Mixin(Item.class) | ||
public interface ItemAccessor { | ||
@Accessor("BLOCK_ITEMS") | ||
static Map<Block, Item> getBlockItemsMap() { | ||
return null; | ||
} | ||
} |
46 changes: 46 additions & 0 deletions
46
legacy-fabric-block-api-v1/1.12.2/src/main/resources/fabric.mod.json
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 |
---|---|---|
@@ -0,0 +1,46 @@ | ||
{ | ||
"schemaVersion": 1, | ||
"id": "legacy-fabric-block-api-v1", | ||
"name": "Legacy Fabric Block API (V1)", | ||
"version": "${version}", | ||
"environment": "*", | ||
"license": "Apache-2.0", | ||
"icon": "assets/legacy-fabric/icon.png", | ||
"contact": { | ||
"homepage": "https://legacyfabric.net/", | ||
"irc": "irc://irc.esper.net:6667/legacyfabric", | ||
"issues": "https://github.com/Legacy-Fabric/fabric/issues", | ||
"sources": "https://github.com/Legacy-Fabric/fabric" | ||
}, | ||
"authors": [ | ||
"Legacy-Fabric" | ||
], | ||
"depends": { | ||
"fabricloader": ">=0.4.0", | ||
"minecraft": "${minecraft_version}" | ||
}, | ||
"description": "Block utils", | ||
"entrypoints": { | ||
"preLaunch": [ | ||
"net.legacyfabric.fabric.impl.block.versioned.EarlyInitializer" | ||
] | ||
}, | ||
"mixins": [ | ||
"legacy-fabric-block-api-v1.mixins.json" | ||
], | ||
"accessWidener": "legacy-fabric-block-api-v1.accesswidener", | ||
"custom": { | ||
"loom:injected_interfaces": { | ||
}, | ||
"modmenu": { | ||
"badges": [ "library" ], | ||
"parent": { | ||
"id": "legacy-fabric-api", | ||
"name": "Legacy Fabric API", | ||
"badges": [ "library" ], | ||
"description": "Core API module providing key hooks and inter-compatibility features for Minecraft 1.7.10-1.12.2.", | ||
"icon": "assets/legacy-fabric/icon.png" | ||
} | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
...cy-fabric-block-api-v1/1.12.2/src/main/resources/legacy-fabric-block-api-v1.accesswidener
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
accessWidener v2 named | ||
|
||
accessible field net/minecraft/block/Block useNeighbourLight Z | ||
accessible field net/minecraft/block/Block transluscent Z | ||
accessible field net/minecraft/block/Block material Lnet/minecraft/block/material/Material; | ||
accessible field net/minecraft/block/Block opacity I |
15 changes: 15 additions & 0 deletions
15
legacy-fabric-block-api-v1/1.12.2/src/main/resources/legacy-fabric-block-api-v1.mixins.json
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 |
---|---|---|
@@ -0,0 +1,15 @@ | ||
{ | ||
"required": true, | ||
"package": "net.legacyfabric.fabric.mixin.block.versioned", | ||
"compatibilityLevel": "JAVA_8", | ||
"injectors": { | ||
"defaultRequire": 1 | ||
}, | ||
"mixins": [ | ||
"BlockAccessor", | ||
"BlockMixin", | ||
"ItemAccessor" | ||
], | ||
"client": [ | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,3 @@ | ||
loom { | ||
accessWidenerPath = file("src/main/resources/legacy-fabric-block-api-v1.accesswidener") | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
minVersionIncluded=1.7 | ||
maxVersionIncluded=1.7.10 |
Oops, something went wrong.