Skip to content

Commit

Permalink
fix: easy place allowing placement of invalid block states by introdu…
Browse files Browse the repository at this point in the history
…cing a Black List.
  • Loading branch information
sakura-ryoko committed Dec 28, 2024
1 parent f3865ca commit 94ff930
Showing 1 changed file with 38 additions and 3 deletions.
41 changes: 38 additions & 3 deletions src/main/java/fi/dy/masa/tweakeroo/tweaks/PlacementHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@ public class PlacementHandler
Properties.INVERTED,
Properties.OPEN,
//Properties.PERSISTENT,
// TODO --> TEST (Boolean)
Properties.POWERED,
Properties.LOCKED,
//Properties.POWERED,
//Properties.LOCKED,
//Properties.WATERLOGGED
// EnumProperty:
// ATTACHMENT - Bells
Expand Down Expand Up @@ -82,6 +81,14 @@ public class PlacementHandler
Properties.ROTATION
);

/**
* BlackList for Block States. Entries here will be reset to their default value.
*/
public static final ImmutableSet<Property<?>> BLACKLISTED_PROPERTIES = ImmutableSet.of(
Properties.WATERLOGGED,
Properties.POWERED
);

public static EasyPlacementProtocol getEffectiveProtocolVersion()
{
EasyPlacementProtocol protocol = (EasyPlacementProtocol) Configs.Generic.ACCURATE_PLACEMENT_PROTOCOL_MODE.getOptionListValue();
Expand Down Expand Up @@ -232,9 +239,23 @@ public static <T extends Comparable<T>> BlockState applyPlacementProtocolV3(Bloc
{
for (Property<?> p : propList)
{
//System.out.printf("[PHv3] check property [%s], whitelisted [%s], blacklisted [%s]\n", p.getName(), WHITELISTED_PROPERTIES.contains(p), BLACKLISTED_PROPERTIES.contains(p));

if ((property.isPresent() && !property.get().equals(p)) ||
(property.isEmpty()) &&
WHITELISTED_PROPERTIES.contains(p))
//WHITELISTED_PROPERTIES.contains(p) &&
//!BLACKLISTED_PROPERTIES.contains(p))

/*
if (property.isPresent() && property.get().equals(p))
{
//System.out.printf("[PHv3] skipping prot val: 0x%08X [Property %s]\n", protocolValue, p.getName());
continue;
}
else if (WHITELISTED_PROPERTIES.contains(p) &&
!BLACKLISTED_PROPERTIES.contains(p))
*/
{
@SuppressWarnings("unchecked")
Property<T> prop = (Property<T>) p;
Expand Down Expand Up @@ -278,6 +299,20 @@ public static <T extends Comparable<T>> BlockState applyPlacementProtocolV3(Bloc
Tweakeroo.logger.warn("Exception trying to apply placement protocol value", e);
}

// Strip Blacklisted properties, and use the Block's default state.
// This needs to be done after the initial loop, or it breaks compatibility
for (Property<?> p : BLACKLISTED_PROPERTIES)
{
if (state.contains(p))
{
@SuppressWarnings("unchecked")
Property<T> prop = (Property<T>) p;
BlockState def = state.getBlock().getDefaultState();
state = state.with(prop, def.get(prop));
//System.out.printf("[PHv3] blacklisted state [%s] found, setting default value\n", prop.getName());
}
}

if (state.canPlaceAt(context.getWorld(), context.getPos()))
{
//System.out.printf("validator passed for \"%s\"\n", state);
Expand Down

0 comments on commit 94ff930

Please sign in to comment.