update mappings, fix block registration issue, push prototype HandlerList

This commit is contained in:
asie 2018-11-18 09:51:12 +01:00
parent a9853c2d45
commit 9273c32d4b
12 changed files with 98 additions and 13 deletions

View file

@ -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"
}

View file

@ -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();
}

View file

@ -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()) {

View file

@ -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) {}
}

View file

@ -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;
}

View file

@ -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);
}
}
}

View file

@ -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();
}
}

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}

View file

@ -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);
}
}
}

View 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;
}
}

View 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);
}