Skip to content

Commit

Permalink
Lazy Structure Templates prototype 2
Browse files Browse the repository at this point in the history
  • Loading branch information
ImplementsLegend committed Oct 13, 2024
1 parent 4f39ea6 commit a3803ce
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public abstract class LazyStructureTemplate implements LazyObject {
@Shadow private Set<ResourceLocation> tags;
private AtomicReference<CompletableFuture<Unit>> initializationTask = new AtomicReference<>(CompletableFuture.completedFuture(Unit.INSTANCE));

private HashSet<ResourceLocation> preInitTags = new HashSet<>();
//private HashSet<ResourceLocation> preInitTags = new HashSet<>();

private static ExecutorService LAZY_LOADING_EXECUTOR = Executors.newSingleThreadExecutor((runnable)->{
var thread = new Thread(runnable);
Expand Down Expand Up @@ -73,7 +73,7 @@ private void initializeIfNot(){
} catch (Exception e){
e.printStackTrace();
}
tags.addAll(preInitTags);
//tags.addAll(preInitTags);
return Unit.INSTANCE;
}, LAZY_LOADING_EXECUTOR);
}else intTask = initializationTask.get();
Expand All @@ -93,12 +93,13 @@ private void initializeIfNot(){
@Inject(method={"getEntities"},at = @At("HEAD"),remap = false)
private void invokeLazyInit2(EntityPredicate filter, PlacementSettings settings, CallbackInfoReturnable<Iterator<PartialEntity>> cir){initializeIfNot();}

@Inject(method={"addTag"},at = @At("HEAD"),remap = false)
private void invokeLazyInit3(ResourceLocation tag, CallbackInfo ci){preInitTags.add(tag);}
/*
@Inject(method={"addTag"},at = @At("HEAD"),remap = false,cancellable = true)
private void invokeLazyInit3(ResourceLocation tag, CallbackInfo ci){preInitTags.add(tag);if(initializationTask.get()==null)ci.cancel();}
@Inject(method={"hasTag"},at = @At("HEAD"),remap = false,cancellable = true)
private void invokeLazyInit4(ResourceLocation tag, CallbackInfoReturnable<Boolean> cir){if(preInitTags.contains(tag))cir.setReturnValue(true); else initializeIfNot();}
@Inject(method={"getTags"},at = @At("HEAD"),remap = false)
private void invokeLazyInit5(CallbackInfoReturnable<Iterator<ResourceLocation>> cir){initializeIfNot();}
private void invokeLazyInit5(CallbackInfoReturnable<Iterator<ResourceLocation>> cir){initializeIfNot();}*/
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,12 @@ public class MixinPartialBlock implements IndexedBlock {
public int getRegistryIndex(){
if(id==null)regIdx=-666;
if(regIdx==-69420){
regIdx= FixatedBlockIDsKt.getIdForBlock(((ForgeRegistry<Block>) ForgeRegistries.BLOCKS).getValue(this.id));
var block = ((ForgeRegistry<Block>) ForgeRegistries.BLOCKS).getValue(this.id);
if(block.getRegistryName()!=this.id) {
if (block.getRegistryName().equals(this.id)) this.id = block.getRegistryName();//resource location deduplication, not sure if it helps
else ;
}
regIdx= FixatedBlockIDsKt.getIdForBlock(block);
if(regIdx==0 ) {
var resName = ((PartialBlockIDAccessor)this).getId();
if(!resName.getNamespace().equals("minecraft") && !resName.getPath().equals("air")) regIdx=-666;
Expand Down

0 comments on commit a3803ce

Please sign in to comment.