mirror of
https://github.com/FabricMC/fabric.git
synced 2025-03-21 20:50:28 -04:00
update mappings, fix block registration issue, push prototype HandlerList
This commit is contained in:
parent
a9853c2d45
commit
9273c32d4b
12 changed files with 98 additions and 13 deletions
build.gradle
src/main/java/net/fabricmc/fabric
|
@ -31,7 +31,7 @@ minecraft {
|
|||
|
||||
dependencies {
|
||||
minecraft "com.mojang:minecraft:18w46a"
|
||||
mappings "net.fabricmc:pomf:18w46a.4"
|
||||
mappings "net.fabricmc:pomf:18w46a.6"
|
||||
modCompile "net.fabricmc:fabric-loader:18w44a-0.1.0.46"
|
||||
}
|
||||
|
||||
|
|
|
@ -27,7 +27,7 @@ import java.util.List;
|
|||
@Mixin(IdList.class)
|
||||
public class MixinIdList implements ExtendedIdList {
|
||||
@Shadow
|
||||
private int field_11099;
|
||||
private int nextId;
|
||||
@Shadow
|
||||
private IdentityHashMap idMap;
|
||||
@Shadow
|
||||
|
@ -35,7 +35,7 @@ public class MixinIdList implements ExtendedIdList {
|
|||
|
||||
@Override
|
||||
public void clear() {
|
||||
field_11099 = 0;
|
||||
nextId = 0;
|
||||
idMap.clear();
|
||||
list.clear();
|
||||
}
|
||||
|
|
|
@ -61,8 +61,9 @@ public abstract class MixinIdRegistry<T> implements RemappableRegistry, Listenab
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "ConstantConditions" })
|
||||
@Inject(method = "set", at = @At("HEAD"))
|
||||
public void set(int id, Identifier identifier, Object object, CallbackInfoReturnable info) {
|
||||
public void setPre(int id, Identifier identifier, Object object, CallbackInfoReturnable info) {
|
||||
IdRegistry<Object> registry = (IdRegistry<Object>) (Object) this;
|
||||
if (listeners != null) {
|
||||
for (RegistryListener listener : listeners) {
|
||||
|
@ -71,6 +72,17 @@ public abstract class MixinIdRegistry<T> implements RemappableRegistry, Listenab
|
|||
}
|
||||
}
|
||||
|
||||
@SuppressWarnings({ "unchecked", "ConstantConditions" })
|
||||
@Inject(method = "set", at = @At("RETURN"))
|
||||
public void setPost(int id, Identifier identifier, Object object, CallbackInfoReturnable info) {
|
||||
IdRegistry<Object> registry = (IdRegistry<Object>) (Object) this;
|
||||
if (listeners != null) {
|
||||
for (RegistryListener listener : listeners) {
|
||||
listener.afterRegistryRegistration(registry, id, identifier, object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void remap(Object2IntMap<Identifier> idMap, boolean reallocateMissingEntries) throws RemapException {
|
||||
//noinspection unchecked, ConstantConditions
|
||||
|
@ -120,7 +132,7 @@ public abstract class MixinIdRegistry<T> implements RemappableRegistry, Listenab
|
|||
}
|
||||
|
||||
// We don't really need to clear anything but idStore yet.
|
||||
idStore.method_15229();
|
||||
idStore.clear();
|
||||
nextId = 0;
|
||||
|
||||
for (Identifier identifier : idMap.keySet()) {
|
||||
|
|
|
@ -22,4 +22,5 @@ import net.minecraft.util.registry.Registry;
|
|||
public interface RegistryListener<T> {
|
||||
default void beforeRegistryCleared(Registry<T> registry) {}
|
||||
default void beforeRegistryRegistration(Registry<T> registry, int id, Identifier identifier, T object, boolean isNew) {}
|
||||
default void afterRegistryRegistration(Registry<T> registry, int id, Identifier identifier, T object) {}
|
||||
}
|
||||
|
|
|
@ -95,7 +95,7 @@ public final class RegistrySyncManager {
|
|||
TagCompound mainTag = tag.getTagCompound("registries");
|
||||
|
||||
for (Identifier registryId : Registry.REGISTRIES.keys()) {
|
||||
if (!mainTag.hasKey(registryId.toString())) {
|
||||
if (!mainTag.containsKey(registryId.toString())) {
|
||||
continue;
|
||||
}
|
||||
|
||||
|
|
|
@ -34,7 +34,7 @@ public class BootstrapBiomeRegistryListener implements RegistryListener<Biome> {
|
|||
public void beforeRegistryRegistration(Registry<Biome> registry, int id, Identifier identifier, Biome object, boolean isNew) {
|
||||
// refer net.minecraft.biome.Biomes
|
||||
if (object.hasParent()) {
|
||||
Biome.PARENT_BIOME_ID_MAP.add(object, id);
|
||||
Biome.PARENT_BIOME_ID_MAP.set(object, id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -27,7 +27,7 @@ import net.minecraft.util.registry.Registry;
|
|||
public class BootstrapBlockRegistryListener implements RegistryListener<Block> {
|
||||
@Override
|
||||
public void beforeRegistryCleared(Registry<Block> registry) {
|
||||
((ExtendedIdList) Block.BLOCKSTATE_ID_LIST).clear();
|
||||
((ExtendedIdList) Block.STATE_IDS).clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -35,9 +35,14 @@ public class BootstrapBlockRegistryListener implements RegistryListener<Block> {
|
|||
// refer net.minecraft.block.Blocks
|
||||
for (BlockState state : object.getStateFactory().getStates()) {
|
||||
state.method_11590();
|
||||
Block.BLOCKSTATE_ID_LIST.method_10205(state);
|
||||
Block.STATE_IDS.add(state);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void afterRegistryRegistration(Registry<Block> registry, int id, Identifier identifier, Block object) {
|
||||
System.out.println(identifier);
|
||||
// refer net.minecraft.block.Blocks
|
||||
object.getDropTableId();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,14 +28,14 @@ import net.minecraft.util.registry.Registry;
|
|||
public class BootstrapFluidRegistryListener implements RegistryListener<Fluid> {
|
||||
@Override
|
||||
public void beforeRegistryCleared(Registry<Fluid> registry) {
|
||||
((ExtendedIdList) Block.BLOCKSTATE_ID_LIST).clear();
|
||||
((ExtendedIdList) Fluid.STATE_IDS).clear();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void beforeRegistryRegistration(Registry<Fluid> registry, int id, Identifier identifier, Fluid object, boolean isNew) {
|
||||
// refer net.minecraft.fluid.Fluids
|
||||
for (FluidState state : object.getStateFactory().getStates()) {
|
||||
Fluid.field_15904.method_10205(state);
|
||||
Fluid.STATE_IDS.add(state);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -33,7 +33,7 @@ public class BootstrapItemRegistryListener implements RegistryListener<Item> {
|
|||
public void beforeRegistryRegistration(Registry<Item> registry, int id, Identifier identifier, Item object, boolean isNew) {
|
||||
// refer net.minecraft.item.Items
|
||||
if (object instanceof ItemBlock) {
|
||||
((ItemBlock) object).method_7713(Item.BLOCK_ITEM_MAP, object);
|
||||
((ItemBlock) object).registerBlockItemMap(Item.BLOCK_ITEM_MAP, object);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -58,7 +58,7 @@ public class IdListUpdater<K, V> implements RegistryListener<K> {
|
|||
@Override
|
||||
public void beforeRegistryRegistration(Registry<K> registry, int id, Identifier identifier, K object, boolean isNew) {
|
||||
if (mapperCache.containsKey(identifier)) {
|
||||
mappers.add(mapperCache.get(identifier), id);
|
||||
mappers.set(mapperCache.get(identifier), id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
46
src/main/java/net/fabricmc/fabric/util/HandlerList.java
Normal file
46
src/main/java/net/fabricmc/fabric/util/HandlerList.java
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018 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.fabricmc.fabric.util;
|
||||
|
||||
public class HandlerList<T> implements HandlerRegistry<T> {
|
||||
private static final Object[] EMPTY = new Object[0];
|
||||
private T[] array;
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
public HandlerList() {
|
||||
this.array = (T[]) EMPTY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void register(T handler) {
|
||||
for (int i = 0; i < array.length; i++) {
|
||||
if (array[i] == handler) {
|
||||
throw new RuntimeException("Handler " + handler + " already registered!");
|
||||
}
|
||||
}
|
||||
|
||||
//noinspection unchecked
|
||||
T[] newArray = (T[]) new Object[array.length + 1];
|
||||
System.arraycopy(array, 0, newArray, 0, array.length);
|
||||
newArray[array.length] = handler;
|
||||
array = newArray;
|
||||
}
|
||||
|
||||
public T[] getBackingArray() {
|
||||
return array;
|
||||
}
|
||||
}
|
21
src/main/java/net/fabricmc/fabric/util/HandlerRegistry.java
Normal file
21
src/main/java/net/fabricmc/fabric/util/HandlerRegistry.java
Normal file
|
@ -0,0 +1,21 @@
|
|||
/*
|
||||
* Copyright (c) 2016, 2017, 2018 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.fabricmc.fabric.util;
|
||||
|
||||
public interface HandlerRegistry<T> {
|
||||
void register(T handler);
|
||||
}
|
Loading…
Reference in a new issue