-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
51 additions
and
83 deletions.
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
2 changes: 1 addition & 1 deletion
2
src/main/java/de/dafuqs/revelationary/api/advancements/AdvancementHelper.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
33 changes: 33 additions & 0 deletions
33
src/main/java/de/dafuqs/revelationary/api/revelations/CloakedBlock.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,33 @@ | ||
package de.dafuqs.revelationary.api.revelations; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.util.Pair; | ||
|
||
import java.util.Hashtable; | ||
import java.util.Map; | ||
|
||
public abstract class CloakedBlock extends Block implements RevelationAware { | ||
|
||
final Block cloakedBlock; | ||
|
||
public CloakedBlock(Settings settings, Block cloakedBlock) { | ||
super(settings); | ||
this.cloakedBlock = cloakedBlock; | ||
RevelationAware.register(this); | ||
} | ||
|
||
@Override | ||
public Map<BlockState, BlockState> getBlockStateCloaks() { | ||
Hashtable<BlockState, BlockState> hashtable = new Hashtable<>(); | ||
hashtable.put(this.getDefaultState(), cloakedBlock.getDefaultState()); | ||
return hashtable; | ||
} | ||
|
||
@Override | ||
public Pair<Item, Item> getItemCloak() { | ||
return null; | ||
} | ||
|
||
} |
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
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
30 changes: 5 additions & 25 deletions
30
src/main/java/de/dafuqs/revelationary/mixin/AbstractBlockMixin.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 |
---|---|---|
@@ -1,52 +1,32 @@ | ||
package de.dafuqs.revelationary.mixin; | ||
|
||
import de.dafuqs.revelationary.api.revelations.RevelationAware; | ||
import de.dafuqs.revelationary.RevelationRegistry; | ||
import de.dafuqs.revelationary.api.revelations.RevelationAware; | ||
import net.minecraft.block.AbstractBlock; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.loot.LootTable; | ||
import net.minecraft.loot.LootTables; | ||
import net.minecraft.loot.context.LootContext; | ||
import net.minecraft.loot.context.LootContextParameters; | ||
import net.minecraft.loot.context.LootContextTypes; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.util.Identifier; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
|
||
@Mixin(AbstractBlock.class) | ||
public class AbstractBlockMixin { | ||
|
||
@Inject(method = "getDroppedStacks(Lnet/minecraft/block/BlockState;Lnet/minecraft/loot/context/LootContext$Builder;)Ljava/util/List;", at = @At("HEAD"), cancellable = true) | ||
public void revelationary$getDroppedStacks(BlockState state, LootContext.Builder builder, CallbackInfoReturnable<List<ItemStack>> cir) { | ||
BlockState cloak = RevelationRegistry.getCloak(state); | ||
if(cloak != null) { | ||
BlockState cloakState = RevelationRegistry.getCloak(state); | ||
if(cloakState != null) { | ||
PlayerEntity lootPlayerEntity = RevelationAware.getLootPlayerEntity(builder); | ||
if (!RevelationRegistry.isVisibleTo(state, lootPlayerEntity)) { | ||
cir.setReturnValue(getLootForSwappedState(builder, cloak)); | ||
List<ItemStack> drops = cloakState.getBlock().getDroppedStacks(cloakState, builder); | ||
cir.setReturnValue(drops); | ||
} | ||
} | ||
} | ||
|
||
private List<ItemStack> getLootForSwappedState(LootContext.Builder builder, BlockState cloakedState) { | ||
Identifier lootTableId = cloakedState.getBlock().getLootTableId(); | ||
|
||
if (lootTableId == LootTables.EMPTY) { | ||
return Collections.emptyList(); | ||
} else { | ||
LootContext lootContext; | ||
lootContext = builder.parameter(LootContextParameters.BLOCK_STATE, cloakedState).build(LootContextTypes.BLOCK); | ||
ServerWorld serverWorld = lootContext.getWorld(); | ||
LootTable lootTable = serverWorld.getServer().getLootManager().getTable(lootTableId); | ||
return lootTable.generateLoot(lootContext); | ||
} | ||
} | ||
|
||
} |
2 changes: 1 addition & 1 deletion
2
src/main/java/de/dafuqs/revelationary/mixin/PlayerAdvancementTrackerMixin.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